|
1 | | -import {expect, BrowserContext, Page, Locator} from '@playwright/test'; |
| 1 | +import {BrowserContext, expect, Page} from '@playwright/test'; |
2 | 2 | import Cookie from 'js-cookie'; |
| 3 | +import {OrejimeInstance} from '../src/setup'; |
3 | 4 | import {Config} from '../src/ui/types'; |
4 | 5 |
|
| 6 | +declare global { |
| 7 | + interface Window { |
| 8 | + orejimeConfig: Partial<Config>; |
| 9 | + orejime: OrejimeInstance; |
| 10 | + } |
| 11 | +} |
| 12 | + |
5 | 13 | export class OrejimePage { |
6 | 14 | constructor( |
7 | 15 | public readonly page: Page, |
@@ -80,6 +88,12 @@ export class OrejimePage { |
80 | 88 | await this.page.getByTestId('orejime-banner-decline').click(); |
81 | 89 | } |
82 | 90 |
|
| 91 | + async acceptAllFromManager() { |
| 92 | + return await this.page.evaluate(() => { |
| 93 | + window.orejime.manager.acceptAll(); |
| 94 | + }); |
| 95 | + } |
| 96 | + |
83 | 97 | async openModalFromBanner() { |
84 | 98 | await this.learnMoreBannerButton.click(); |
85 | 99 | } |
@@ -119,15 +133,34 @@ export class OrejimePage { |
119 | 133 | await this.page.getByTestId('orejime-contextual-notice-accept').click(); |
120 | 134 | } |
121 | 135 |
|
| 136 | + async expectUndefinedConsents() { |
| 137 | + await expect(await this.getConsentsFromCookies()).toBeUndefined(); |
| 138 | + } |
| 139 | + |
| 140 | + async expectAnyConsents() { |
| 141 | + await expect(await this.getConsentsFromCookies()).not.toBeUndefined(); |
| 142 | + } |
| 143 | + |
122 | 144 | async expectConsents(consents: Record<string, unknown>) { |
123 | 145 | await expect(await this.getConsentsFromCookies()).toEqual(consents); |
124 | 146 | } |
125 | 147 |
|
126 | 148 | async getConsentsFromCookies() { |
127 | 149 | const name = 'eu-consent'; |
128 | 150 | const cookies = await this.context.cookies(); |
129 | | - const {value} = cookies.find((cookie) => cookie.name === name)!; |
130 | | - return JSON.parse(Cookie.converter.read(value, name)); |
| 151 | + const cookie = cookies.find((cookie) => cookie.name === name)!; |
| 152 | + |
| 153 | + if (!cookie) { |
| 154 | + return undefined; |
| 155 | + } |
| 156 | + |
| 157 | + return JSON.parse(Cookie.converter.read(cookie.value, cookie.name)); |
| 158 | + } |
| 159 | + |
| 160 | + async clearConsents() { |
| 161 | + return await this.page.evaluate(() => { |
| 162 | + window.orejime.manager.clearConsents(); |
| 163 | + }); |
131 | 164 | } |
132 | 165 |
|
133 | 166 | // In specific conditions, browser events can get queued |
|
0 commit comments