-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1111 from adobe/consentFlicker
Show personalization containers when consent is out
- Loading branch information
Showing
10 changed files
with
189 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/components/Personalization/createHandleConsentFlicker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2024 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import { OUT } from "../../constants/consentStatus"; | ||
|
||
export default ({ showContainers, consent }) => () => { | ||
const { state, wasSet } = consent.current(); | ||
if (state === OUT && wasSet) { | ||
showContainers(); | ||
} else { | ||
consent.awaitConsent().catch(showContainers); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2023 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
import { t, Selector } from "testcafe"; | ||
import createFixture from "../../helpers/createFixture"; | ||
import { | ||
compose, | ||
orgMainConfigMain, | ||
debugEnabled, | ||
consentPending | ||
} from "../../helpers/constants/configParts"; | ||
import { TEST_PAGE as TEST_PAGE_URL } from "../../helpers/constants/url"; | ||
import createAlloyProxy from "../../helpers/createAlloyProxy"; | ||
import addHtmlToHeader from "../../helpers/dom/addHtmlToHeader"; | ||
import reloadPage from "../../helpers/reloadPage"; | ||
import { CONSENT_OUT } from "../../helpers/constants/consent"; | ||
|
||
const config = compose(orgMainConfigMain, debugEnabled, consentPending); | ||
|
||
createFixture({ | ||
title: "C17294899: Prehiding style is removed when consent is set to out", | ||
url: `${TEST_PAGE_URL}?test=CC17294899` | ||
}); | ||
|
||
test.meta({ | ||
ID: "C17294899", | ||
SEVERITY: "P0", | ||
TEST_RUN: "Regression" | ||
}); | ||
|
||
test("Test C17294899: Prehiding style is removed when consent is set to out", async () => { | ||
const alloy = createAlloyProxy(); | ||
await addHtmlToHeader( | ||
`<style id="alloy-prehiding">body { visibility: hidden; }</style` | ||
); | ||
await alloy.configure(config); | ||
await t.expect(Selector("#alloy-prehiding").exists).ok(); | ||
|
||
await alloy.sendEventAsync({ renderDecisions: true }); | ||
await t.expect(Selector("#alloy-prehiding").exists).ok(); | ||
|
||
await alloy.setConsent(CONSENT_OUT); | ||
await t.expect(Selector("#alloy-prehiding").exists).notOk(); | ||
|
||
await reloadPage(); | ||
await addHtmlToHeader( | ||
`<style id="alloy-prehiding">body { visibility: hidden; }</style` | ||
); | ||
await t.expect(Selector("#alloy-prehiding").exists).ok(); | ||
|
||
await alloy.configure(config); | ||
await t.expect(Selector("#alloy-prehiding").exists).notOk(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/unit/specs/components/Personalization/createHandleConsentFlicker.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import createHandleConsentFlicker from "../../../../../src/components/Personalization/createHandleConsentFlicker"; | ||
import flushPromiseChains from "../../../helpers/flushPromiseChains"; | ||
|
||
describe("Personalization::createHandleConsentFlicker", () => { | ||
let showContainers; | ||
let consent; | ||
let handleConsentFlicker; | ||
|
||
beforeEach(() => { | ||
showContainers = jasmine.createSpy("showContainers"); | ||
consent = jasmine.createSpyObj("consent", ["current", "awaitConsent"]); | ||
handleConsentFlicker = createHandleConsentFlicker({ | ||
showContainers, | ||
consent | ||
}); | ||
}); | ||
|
||
it("shows containers when consent is out and was set", () => { | ||
consent.current.and.returnValue({ state: "out", wasSet: true }); | ||
handleConsentFlicker(); | ||
expect(showContainers).toHaveBeenCalled(); | ||
flushPromiseChains().then(() => { | ||
expect(consent.awaitConsent).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it("shows containers after consent is rejected", () => { | ||
consent.current.and.returnValue({ state: "out", wasSet: false }); | ||
consent.awaitConsent.and.returnValue(Promise.reject()); | ||
handleConsentFlicker(); | ||
expect(consent.awaitConsent).toHaveBeenCalled(); | ||
flushPromiseChains().then(() => { | ||
expect(showContainers).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it("does not show containers after consent is given", () => { | ||
consent.current.and.returnValue({ state: "out", wasSet: false }); | ||
consent.awaitConsent.and.returnValue(Promise.resolve()); | ||
handleConsentFlicker(); | ||
expect(consent.awaitConsent).toHaveBeenCalled(); | ||
flushPromiseChains().then(() => { | ||
expect(showContainers).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters