Passed
Push — trunk ( a9c55d...86d206 )
by Christian
19:30 queued 06:45
created

cms-gdpr-video-element.plugin.test.js ➔ initPlugin   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
1
import CookieStorageHelper from 'src/helper/storage/cookie-storage.helper';
2
import CmsGdprVideoElement, { CMS_GDPR_VIDEO_ELEMENT_REPLACE_ELEMENT_WITH_VIDEO } from 'src/plugin/cms-gdpr-video-element/cms-gdpr-video-element.plugin';
3
import { COOKIE_CONFIGURATION_CLOSE_OFF_CANVAS } from 'src/plugin/cookie/cookie-configuration.plugin';
4
5
/**
6
 * @package system-settings
7
 */
8
describe('src/plugin/cms-gdpr-video-element/cms-gdpr-video-element.plugin', () => {
9
    let cmsGdprVideoElement;
10
11
    const template = `
12
        <div class="cms-element">
13
            <button class="cms-element__accept-cookie">Accept</button>
14
        <div>
15
    `;
16
17
    function initPlugin(options = {}) {
0 ignored issues
show
Bug introduced by
The function initPlugin is declared conditionally. This is not supported by all runtimes. Consider moving it to root scope or using var initPlugin = function() { /* ... */ }; instead.
Loading history...
18
        return new CmsGdprVideoElement(document.querySelector('.cms-element'), options);
19
    }
20
21
    beforeEach(() => {
22
        document.body.innerHTML = template;
23
        document.$emitter.subscribe = 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...
24
25
        cmsGdprVideoElement = initPlugin();
26
    });
27
28
    afterEach(() => {
29
        jest.clearAllMocks();
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...
30
        CookieStorageHelper.removeItem(cmsGdprVideoElement.options.cookieName);
31
32
        cmsGdprVideoElement = undefined;
33
    });
34
35
    test('is registered correctly', () => {
36
        expect(typeof cmsGdprVideoElement).toBe('object');
37
        expect(cmsGdprVideoElement).toBeInstanceOf(CmsGdprVideoElement);
38
    });
39
40
    test('should replace elements with the video when the plugin created', () => {
41
        const _replaceElementWithVideo = jest.spyOn(cmsGdprVideoElement, '_replaceElementWithVideo');
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...
42
        CookieStorageHelper.setItem(cmsGdprVideoElement.options.cookieName, '1', '30');
43
44
        cmsGdprVideoElement.init();
45
46
        expect(document.$emitter.subscribe).toHaveBeenCalledWith(COOKIE_CONFIGURATION_CLOSE_OFF_CANVAS, expect.any(Function));
0 ignored issues
show
Bug introduced by
The variable expect seems to be never declared. If this is a global, consider adding a /** global: expect */ 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...
47
        expect(CookieStorageHelper.getItem(cmsGdprVideoElement.options.cookieName)).toBe('1');
48
        expect(_replaceElementWithVideo).toHaveBeenCalled();
49
    });
50
51
    test('should replace elements with the video when the accept button clicked', () => {
52
        document.$emitter.publish = 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...
53
54
        cmsGdprVideoElement.onReplaceElementWithVideo({ preventDefault: jest.fn() });
55
56
        expect(CookieStorageHelper.getItem(cmsGdprVideoElement.options.cookieName)).toBe('1');
57
        expect(document.$emitter.publish).toHaveBeenCalledWith(CMS_GDPR_VIDEO_ELEMENT_REPLACE_ELEMENT_WITH_VIDEO);
58
    });
59
});
60