-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathdnt.spec.js
More file actions
92 lines (74 loc) · 3.23 KB
/
dnt.spec.js
File metadata and controls
92 lines (74 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const {test, expect} = require('@playwright/test')
const config = require('../../config.js')
const {generateUserCredentials} = require('../../scripts/utils.js')
const {registerShopper, answerConsentTrackingForm} = require('../../scripts/pageHelpers.js')
const REGISTERED_USER_CREDENTIALS = generateUserCredentials()
const checkDntCookie = async (page, expectedValue) => {
var cookies = await page.context().cookies()
var cookieName = 'dw_dnt'
var cookie = cookies.find((cookie) => cookie.name === cookieName)
expect(cookie).toBeTruthy()
expect(cookie.value).toBe(expectedValue)
}
test('Shopper can use the consent tracking form', async ({page}) => {
await page.context().clearCookies()
await page.goto(config.RETAIL_APP_HOME)
const modalSelector = '[aria-label="Close consent tracking form"]'
page.locator(modalSelector).waitFor()
await expect(page.getByText(/Tracking Consent/i)).toBeVisible({timeout: 10000})
// Decline Tracking
const declineButton = page.locator('button:visible', {hasText: 'Decline'})
await expect(declineButton).toBeVisible()
await declineButton.click()
// Intercept einstein request
let apiCallsMade = false
await page.route(
'https://api.cquotient.com/v3/activities/aaij-MobileFirst/viewCategory',
(route) => {
apiCallsMade = true
route.continue()
}
)
await page.waitForTimeout(5000)
await checkDntCookie(page, '1')
// Trigger einstein events
await page.getByLabel('Menu', {exact: true}).click()
// SSR nav loads top level categories as direct links so we wait till all sub-categories load in the accordion
const categoryAccordion = page.locator(
"#category-nav .chakra-accordion__button svg+:text('Womens')"
)
await categoryAccordion.waitFor()
await page.getByRole('button', {name: 'Womens'}).click()
const clothingNav = page.getByRole('button', {name: 'Clothing'})
await clothingNav.waitFor()
await clothingNav.click()
// Reloading the page after setting DNT makes the form not appear again
await page.reload()
await expect(page.getByText(/Tracking Consent/i)).toBeHidden()
// Registering after setting DNT persists the preference
await registerShopper({page, userCredentials: REGISTERED_USER_CREDENTIALS})
await answerConsentTrackingForm(page, true)
await checkDntCookie(page, '1')
// Logging out clears the preference
await page.getByRole('button', {name: /My Account chevron-down/i}).click()
const buttons = await page.getByText(/Log Out/i).elementHandles()
for (const button of buttons) {
if (await button.isVisible()) {
await button.click()
break
}
}
var cookies = await page.context().cookies()
if (cookies.some((item) => item.name === 'dw_dnt')) {
throw new Error('dw_dnt still exists in the cookies')
}
await page.reload()
await expect(page.getByText(/Tracking Consent/i)).toBeVisible({timeout: 10000})
expect(apiCallsMade).toBe(false)
})