|
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 = {}) { |
|
|
|
|
|
|
18
|
|
|
return new CmsGdprVideoElement(document.querySelector('.cms-element'), options); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
beforeEach(() => { |
|
22
|
|
|
document.body.innerHTML = template; |
|
23
|
|
|
document.$emitter.subscribe = jest.fn(); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
cmsGdprVideoElement = initPlugin(); |
|
26
|
|
|
}); |
|
27
|
|
|
|
|
28
|
|
|
afterEach(() => { |
|
29
|
|
|
jest.clearAllMocks(); |
|
|
|
|
|
|
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'); |
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
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
|
|
|
|