Passed
Push — master ( 3a1f9c...b4794f )
by Christian
11:51 queued 10s
created

src/Storefront/Resources/app/storefront/test/utility/modal-extension/pseudo-modal.util.test.js   A

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 50
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 30
mnd 0
bc 0
fnc 7
dl 0
loc 50
rs 10
bpm 0
cpm 1
noi 2
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A pseudo-modal.util.test.js ➔ initialModal 0 3 2
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();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

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.

Loading history...
18
19
    function initialModal() {
0 ignored issues
show
Bug introduced by
The function initialModal is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var initialModal = function() { /* ... */ }; instead.
Loading history...
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