|
1 | 1 | import { CONSENT_COOKIE_NAME, ConsentMethod, FidesCookie } from "fides-js"; |
2 | 2 |
|
| 3 | +import { mockCookie } from "../../support/mocks"; |
3 | 4 | import { stubConfig, stubTCFExperience } from "../../support/stubs"; |
4 | 5 |
|
5 | 6 | describe("Banner and modal dismissal", () => { |
@@ -245,4 +246,61 @@ describe("Banner and modal dismissal", () => { |
245 | 246 | }); |
246 | 247 | }, |
247 | 248 | ); |
| 249 | + |
| 250 | + // When the saved cookie has prior decisions for some notices but lists a |
| 251 | + // currently-served notice in `non_applicable_notice_keys` (i.e. that notice |
| 252 | + // was non-applicable in a prior region), dismissing the banner must record |
| 253 | + // a default preference for the now-applicable notice. Otherwise the banner |
| 254 | + // would resurface on every reload until the user explicitly saved. |
| 255 | + describe("when a served notice has no recorded preference but is in non_applicable_notice_keys", () => { |
| 256 | + beforeEach(() => { |
| 257 | + cy.fixture("consent/fidesjs_options_banner_modal.json").then((config) => { |
| 258 | + const experienceItem = config.experience; |
| 259 | + experienceItem.experience_config.dismissable = true; |
| 260 | + |
| 261 | + // Seed a cookie with consent for an unrelated notice and "advertising" |
| 262 | + // recorded as previously non-applicable. The current experience serves |
| 263 | + // "advertising" as applicable, so the banner should resurface once. |
| 264 | + const cookie = mockCookie({ |
| 265 | + consent: { essential: true }, |
| 266 | + fides_meta: { |
| 267 | + version: "0.9.0", |
| 268 | + createdAt: "2024-01-01T12:00:00.000Z", |
| 269 | + updatedAt: "2024-01-01T12:00:00.000Z", |
| 270 | + consentMethod: ConsentMethod.ACCEPT, |
| 271 | + }, |
| 272 | + non_applicable_notice_keys: ["advertising"], |
| 273 | + }); |
| 274 | + cy.setCookie(CONSENT_COOKIE_NAME, JSON.stringify(cookie)); |
| 275 | + |
| 276 | + stubConfig({ |
| 277 | + options: { tcfEnabled: false }, |
| 278 | + experience: experienceItem, |
| 279 | + }); |
| 280 | + }); |
| 281 | + }); |
| 282 | + |
| 283 | + it("records a default preference for the served notice on dismiss and stops resurfacing", () => { |
| 284 | + cy.get("#fides-banner").should("be.visible"); |
| 285 | + cy.get("#fides-banner .fides-close-button").click(); |
| 286 | + cy.get("#fides-banner").should("not.be.visible"); |
| 287 | + |
| 288 | + cy.waitUntilCookieExists(CONSENT_COOKIE_NAME).then(() => { |
| 289 | + cy.getCookie(CONSENT_COOKIE_NAME).then((cookie) => { |
| 290 | + const fidesCookie: FidesCookie = JSON.parse( |
| 291 | + decodeURIComponent(cookie!.value), |
| 292 | + ); |
| 293 | + // The dismiss flow should have recorded a default value for the |
| 294 | + // newly-applicable notice while preserving the existing decision. |
| 295 | + expect(fidesCookie.consent).to.have.property("advertising"); |
| 296 | + expect(fidesCookie.fides_meta.consentMethod).to.eql( |
| 297 | + ConsentMethod.DISMISS, |
| 298 | + ); |
| 299 | + }); |
| 300 | + }); |
| 301 | + |
| 302 | + cy.reload(); |
| 303 | + cy.get("#fides-banner").should("not.be.visible"); |
| 304 | + }); |
| 305 | + }); |
248 | 306 | }); |
0 commit comments