Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 6, 2023
1 parent 59e50cc commit edac4d9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1,116 deletions.
2 changes: 0 additions & 2 deletions packages/consent/consent-tools-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
"@wdio/cli": "^8.10.6",
"@wdio/local-runner": "^8.10.6",
"@wdio/mocha-framework": "^8.10.6",
"@wdio/sauce-service": "^8.10.6",
"@wdio/spec-reporter": "^8.10.6",
"@wdio/static-server-service": "^8.10.6",
"@wdio/types": "8",
"expect": "^29.4.1",
"globby": "^11.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ class OneTrustPage extends BasePage {
clickAcceptButtonAndClosePopup() {
return $('#onetrust-accept-btn-handler').click()
}

/**
* Whenever a consent event is sent, increment a counter
*/
detectConsentChanged() {
const getConsentChangedCallCount = (): Promise<number> =>
browser.execute(() => window._segmentConsentCalls)

void browser.execute(() => {
window._segmentConsentCalls ??= 0
window.analytics.on('track', (name) => {
if (name.includes('Segment Consent')) {
window._segmentConsentCalls += 1
}
})
})
return { getConsentChangedCallCount }
}
}

export default new OneTrustPage()
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ afterEach(async () => {

it('should stamp each event', async () => {
await page.load()

const commands = [
`analytics.track("hello world")`,
`analytics.alias("foo", "bar")`,
Expand All @@ -39,33 +38,18 @@ it('should stamp each event', async () => {
it('should send an onConsentChanged event when user clicks accept on popup', async () => {
await page.load()

// you can also use interceptors, but not clear that will work in saucelabs?
const listenToConsent = () => {
browser.execute(() => {
if (window._segmentConsentCalls === undefined) {
window._segmentConsentCalls = 0
}
window.analytics.on('track', (name) => {
if (name.includes('Segment Consent')) {
window._segmentConsentCalls += 1
}
})
})
}

listenToConsent()

const { getConsentChangedCallCount } = await page.detectConsentChanged()
// make sure an onConsentChange event is not sent
await browser.pause(1000)
await expect(
browser.execute(() => window._segmentConsentCalls)
).resolves.toBe(0)
await expect(getConsentChangedCallCount()).resolves.toBe(0)

// make a consent selection in the OneTrust popup
await page.clickAcceptButtonAndClosePopup()

// onConsentChange event should now be sent
await browser.waitUntil(
async () => (await browser.execute(() => window._segmentConsentCalls)) === 1
async () => (await getConsentChangedCallCount()) === 1
)
await browser.pause(100000000000)
await expect(true).toBe(true)
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"node",
"expect-webdriverio",
"@wdio/mocha-framework",
"@wdio/sauce-service",
"wdio-intercept-service"
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import type { Options } from '@wdio/types'

export const config: Options.Testrunner = {
afterTest(test, _, { error, passed }) {
console.log(
[
`${passed ? '✅ Passed' : '❌ Failed'}! ${test.title}`,
test.file,
error ? error : '',
].join('\n')
)
},
services: ['intercept'],
// services: [ /* Using webpack-dev-server instead */
// [
Expand Down Expand Up @@ -61,7 +70,7 @@ export const config: Options.Testrunner = {
// },
//
// If you only want to run your tests until a specific amount of tests have failed use
bail: 1, // Fail fast
bail: 0, // Fail fast
//
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
Expand Down
Loading

0 comments on commit edac4d9

Please sign in to comment.