Skip to content

Commit 7afa571

Browse files
committed
finish migration
1 parent bce7c7c commit 7afa571

File tree

4 files changed

+44
-32
lines changed

4 files changed

+44
-32
lines changed

packages/consent/consent-tools-integration-tests/playwright.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const config: PlaywrightTestConfig = {
3737
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3838
baseURL: `http://127.0.0.1:5432`,
3939
trace: 'on',
40-
launchOptions: {
41-
args: ['--enable-precise-memory-info', '--js-flags=--expose-gc'],
42-
},
4340
},
4441

4542
/* Configure projects for major browsers */

packages/consent/consent-tools-integration-tests/src/page-bundles/onetrust/index.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import { AnalyticsBrowser } from '@segment/analytics-next'
2-
import { initMockConsentManager } from '../helpers/mock-cmp'
3-
import { withMockCMP } from '../helpers/mock-cmp-wrapper'
2+
import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'
43

5-
initMockConsentManager({
6-
consentModel: 'opt-in',
7-
})
8-
//import { withOneTrust } from '@segment/analytics-consent-wrapper-onetrust'
9-
10-
// declare global {
11-
// interface Window {
12-
// withOneTrust: typeof import('@segment/analytics-consent-wrapper-onetrust').withOneTrust
13-
// }
14-
// }
15-
// window.withOneTrust = withOneTrust
4+
declare global {
5+
interface Window {
6+
withOneTrust: typeof import('@segment/analytics-consent-wrapper-onetrust').withOneTrust
7+
}
8+
}
9+
window.withOneTrust = withOneTrust
1610

1711
const analytics = new AnalyticsBrowser()
1812

19-
withMockCMP(analytics).load(
13+
withOneTrust(analytics).load(
2014
{
2115
writeKey: 'foo',
2216
},
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
import { BasePage } from './base-page'
2-
import { Page } from '@playwright/test'
2+
import { Locator, Page } from '@playwright/test'
33

44
export default class OneTrustPage extends BasePage {
55
constructor(page: Page) {
66
super(page, 'consent-tools-onetrust.html')
77
}
88

9-
async clickAcceptButtonAndClosePopup() {
10-
const acceptButton = await this.page.locator('#onetrust-accept-btn-handler')
11-
await acceptButton.click()
9+
async openAlertBoxIfNeeded() {
10+
const floatingButton = this.page.locator('#ot-sdk-btn-floating')
11+
try {
12+
// Wait for the button to exist for up to 2 seconds
13+
await floatingButton.waitFor({ timeout: 2000 })
14+
await floatingButton.click()
15+
} catch (error) {
16+
// If the button does not exist or is not visible, do nothing.
17+
}
18+
}
19+
20+
async clickConfirmButtonAndClosePopup() {
21+
const confirmButton = await this.findFirstVisibleElement([
22+
'button:has-text("Confirm")',
23+
'#onetrust-accept-btn-handler',
24+
])
25+
26+
if (confirmButton) {
27+
await confirmButton.click()
28+
}
1229
}
13-
}
1430

15-
//export default (page: Page) => new OneTrustPage(page)
31+
private async findFirstVisibleElement(
32+
selectors: string[]
33+
): Promise<Locator | undefined> {
34+
for (const selector of selectors) {
35+
const locator = this.page.locator(selector)
36+
if (await locator.isVisible()) {
37+
return locator
38+
}
39+
}
40+
}
41+
}

packages/consent/consent-tools-integration-tests/src/tests/onetrust.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@ test.describe('OneTrust Consent Tests', () => {
1212
await pageObject.cleanup()
1313
})
1414

15-
test.skip('should send a consent changed event when user clicks accept on popup', async () => {
15+
test('should send a consent changed event when user clicks accept on popup', async () => {
1616
expect(pageObject.getConsentChangedEvents().length).toBe(0)
17-
18-
await pageObject.clickAcceptButtonAndClosePopup()
19-
20-
await expect
21-
.poll(() => pageObject.getConsentChangedEvents().length, {
22-
timeout: 5000,
23-
})
24-
.toBe(1)
17+
await pageObject.openAlertBoxIfNeeded()
18+
await pageObject.clickConfirmButtonAndClosePopup()
19+
await expect.poll(() => pageObject.getConsentChangedEvents().length).toBe(1)
2520
})
2621
})

0 commit comments

Comments
 (0)