|
1
|
|
|
/** |
|
2
|
|
|
* @jest-environment jsdom |
|
3
|
|
|
*/ |
|
4
|
|
|
|
|
5
|
|
|
import jQuery from 'jquery' |
|
6
|
|
|
import PseudoModalUtil from 'src/utility/modal-extension/pseudo-modal.util'; |
|
7
|
|
|
|
|
8
|
|
|
import PseudoModalTemplate from './pseudo-modal.template.html' |
|
9
|
|
|
import ModalContentTemplate from './modal-content.template.html' |
|
10
|
|
|
|
|
11
|
|
|
const selector = { |
|
12
|
|
|
templateTitle: '.js-pseudo-modal-template-title-element' |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
describe('pseudo-modal.util tests', () => { |
|
16
|
|
|
let pseudoModal = null; |
|
17
|
|
|
const spyInsertAdjacentElement = jest.fn(); |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
function initialModal() { |
|
|
|
|
|
|
20
|
|
|
return new PseudoModalUtil(ModalContentTemplate); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
beforeAll(() => { |
|
24
|
|
|
window.$ = jQuery; |
|
25
|
|
|
document.body.innerHTML = PseudoModalTemplate; |
|
26
|
|
|
document.body.insertAdjacentElement = spyInsertAdjacentElement; |
|
27
|
|
|
}) |
|
28
|
|
|
|
|
29
|
|
|
beforeEach(() => { |
|
30
|
|
|
pseudoModal = initialModal(); |
|
31
|
|
|
}) |
|
32
|
|
|
|
|
33
|
|
|
test('it has title template placeholder in modal header', () => { |
|
34
|
|
|
const templateTitle = document.querySelector(selector.templateTitle); |
|
35
|
|
|
|
|
36
|
|
|
expect(templateTitle).not.toBeNull(); |
|
37
|
|
|
expect(templateTitle.textContent).toBe(''); |
|
38
|
|
|
}) |
|
39
|
|
|
|
|
40
|
|
|
test('it can move modal title from modal body to header', () => { |
|
41
|
|
|
const modal = pseudoModal.getModal(); |
|
42
|
|
|
const modalTitle = modal.querySelector(`h5${selector.templateTitle}`); |
|
43
|
|
|
|
|
44
|
|
|
expect(modalTitle).not.toBeNull(); |
|
45
|
|
|
expect(modalTitle.textContent).toBe('Modal title'); |
|
46
|
|
|
}) |
|
47
|
|
|
|
|
48
|
|
|
test('it can remove modal title from body after moving to header', () => { |
|
49
|
|
|
const modal = pseudoModal.getModal(); |
|
50
|
|
|
const titleElement = modal.querySelectorAll(selector.templateTitle); |
|
51
|
|
|
|
|
52
|
|
|
expect(titleElement).toHaveLength(1); |
|
53
|
|
|
}) |
|
54
|
|
|
}); |
|
55
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.