|
| 1 | +beforeEach(async () => { |
| 2 | + const client = await page.createCDPSession() |
| 3 | + await client.send('Storage.clearDataForOrigin', { |
| 4 | + origin: __SERVERURL__, |
| 5 | + storageTypes: |
| 6 | + 'cookies, local_storage, session_storage, indexeddb, websql, cache_storage, service_workers' |
| 7 | + }) |
| 8 | + await page.goto(`${__SERVERURL__}/index-esm.html`, { waitUntil: 'domcontentloaded' }) |
| 9 | +}) |
| 10 | + |
| 11 | +describe('a fresh instance of biscuitman', () => { |
| 12 | + test('should load without without consents', async () => { |
| 13 | + expect(await utils.getConsent()).toBeEmpty() |
| 14 | + expect(await utils.loadConsents()).toBeNull() |
| 15 | + }) |
| 16 | + |
| 17 | + test('should display a UI', async () => { |
| 18 | + const ui = await page.$('.biscuitman') |
| 19 | + expect(ui).not.toBeNull() |
| 20 | + |
| 21 | + const banner = await page.$('.biscuitman article') |
| 22 | + expect(await banner.isVisible()).toBe(true) |
| 23 | + }) |
| 24 | + |
| 25 | + test('should open settings modal after clicking settings', async () => { |
| 26 | + await page.click('button[data-id=settings]') |
| 27 | + const dialog = await page.$('dialog') |
| 28 | + expect(await dialog.isVisible()).toBe(true) |
| 29 | + }) |
| 30 | + |
| 31 | + test('should close settings modal after clicking close', async () => { |
| 32 | + await page.click('button[data-id=settings]') |
| 33 | + const dialog = await page.$('dialog') |
| 34 | + await page.click('button[data-id=close]') |
| 35 | + expect(await dialog.isVisible()).toBe(false) |
| 36 | + }) |
| 37 | + |
| 38 | + test('should hide UI and save consents correctly after clicking accept', async () => { |
| 39 | + await page.click('button[data-id=accept]') |
| 40 | + |
| 41 | + const banner = await page.$('.biscuitman article') |
| 42 | + expect(await banner.isVisible()).toBe(false) |
| 43 | + |
| 44 | + let entries = [ |
| 45 | + ['analytics', true], |
| 46 | + ['functional', true], |
| 47 | + ['advertisement', true], |
| 48 | + ['performance', true], |
| 49 | + ['uncategorized', true] |
| 50 | + ] |
| 51 | + |
| 52 | + expect(await utils.getConsent()).toContainEntries(entries) |
| 53 | + expect(await utils.loadConsents()).toContainEntries(entries) |
| 54 | + }) |
| 55 | + |
| 56 | + test('should hide UI and save consents correctly after clicking reject', async () => { |
| 57 | + await page.click('button[data-id=reject]') |
| 58 | + |
| 59 | + const banner = await page.$('.biscuitman article') |
| 60 | + expect(await banner.isVisible()).toBe(false) |
| 61 | + |
| 62 | + let entries = [ |
| 63 | + ['analytics', false], |
| 64 | + ['functional', false], |
| 65 | + ['advertisement', false], |
| 66 | + ['performance', false], |
| 67 | + ['uncategorized', false] |
| 68 | + ] |
| 69 | + expect(await utils.getConsent()).toContainEntries(entries) |
| 70 | + expect(await utils.loadConsents()).toContainEntries(entries) |
| 71 | + }) |
| 72 | + |
| 73 | + test('should hide UI and save consents correctly after selecting some sections', async () => { |
| 74 | + await page.click('button[data-id=settings]') |
| 75 | + await page.click('[for=biscuitman_analytics]') |
| 76 | + await page.click('[for=biscuitman_functional]') |
| 77 | + await page.click('[for=biscuitman_performance]') |
| 78 | + |
| 79 | + await page.click('button[data-id=save]') |
| 80 | + |
| 81 | + const banner = await page.$('.biscuitman article') |
| 82 | + expect(await banner.isVisible()).toBe(false) |
| 83 | + |
| 84 | + let entries = [ |
| 85 | + ['analytics', true], |
| 86 | + ['functional', true], |
| 87 | + ['advertisement', false], |
| 88 | + ['performance', true], |
| 89 | + ['uncategorized', false] |
| 90 | + ] |
| 91 | + |
| 92 | + expect(await utils.getConsent()).toContainEntries(entries) |
| 93 | + expect(await utils.loadConsents()).toContainEntries(entries) |
| 94 | + }) |
| 95 | + |
| 96 | + test('should remove consent preferences when "bmInvalidate" is called', async () => { |
| 97 | + await page.evaluate(() => window.bmInvalidate()) |
| 98 | + expect(await utils.getConsent()).toEqual({}) |
| 99 | + expect(await utils.loadConsents()).toBeNull() |
| 100 | + }) |
| 101 | + |
| 102 | + test('should update consent preferences when "bmUpdate" is called', async () => { |
| 103 | + await page.evaluate(() => window.bmUpdate()) |
| 104 | + const dialog = await page.$('dialog') |
| 105 | + const dialogVisible = await page.evaluate( |
| 106 | + (dialog) => dialog.open, |
| 107 | + dialog |
| 108 | + ) |
| 109 | + expect(dialogVisible).toBe(true) |
| 110 | + }) |
| 111 | +}) |
0 commit comments