Skip to content

Commit c8ad930

Browse files
committed
Update test cases
1 parent ac43b37 commit c8ad930

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

special-pages/pages/new-tab/app/activity/integration-tests/activity.page.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,22 @@ export class ActivityPage {
441441
- paragraph: Past 7 days
442442
`);
443443
}
444+
445+
/**
446+
* Test that cookie popup blocked indicator is shown for items with cookiePopUpBlocked: true
447+
*/
448+
async showsCookiePopupBlockedIndicator() {
449+
// First item in 'few' mock has cookiePopUpBlocked: true
450+
const firstItem = this.context().getByTestId('ActivityItem').nth(0);
451+
await expect(firstItem.getByText(/cookie pop-up/i)).toBeVisible();
452+
}
453+
454+
/**
455+
* Test that cookie popup blocked indicator is NOT shown for items with cookiePopUpBlocked: false
456+
*/
457+
async hidesCookiePopupIndicatorWhenNotBlocked() {
458+
// Second item in 'few' mock (youtube) has cookiePopUpBlocked: false
459+
const secondItem = this.context().getByTestId('ActivityItem').nth(1);
460+
await expect(secondItem.getByText(/cookie pop-up/i)).not.toBeVisible();
461+
}
444462
}

special-pages/pages/new-tab/app/activity/integration-tests/activity.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ test.describe('activity widget', () => {
100100
await ap.didRender();
101101
await ap.showsAdsAndTrackersTrackerStates();
102102
});
103+
test('shows cookie popup blocked indicator', async ({ page }, workerInfo) => {
104+
const ntp = NewtabPage.create(page, workerInfo);
105+
const ap = new ActivityPage(page, ntp);
106+
await ntp.reducedMotion();
107+
await ntp.openPage({ additional: { ...defaultPageParams } });
108+
await ap.didRender();
109+
await ap.showsCookiePopupBlockedIndicator();
110+
});
111+
test('hides cookie popup indicator when not blocked', async ({ page }, workerInfo) => {
112+
const ntp = NewtabPage.create(page, workerInfo);
113+
const ap = new ActivityPage(page, ntp);
114+
await ntp.reducedMotion();
115+
await ntp.openPage({ additional: { ...defaultPageParams } });
116+
await ap.didRender();
117+
await ap.hidesCookiePopupIndicatorWhenNotBlocked();
118+
});
103119
test('after rendering and navigating to a new tab, data is re-requested on return', async ({ page }, workerInfo) => {
104120
const ntp = NewtabPage.create(page, workerInfo);
105121
const ap = new ActivityPage(page, ntp);

special-pages/pages/new-tab/app/protections/integrations-tests/protections.page.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class ProtectionsPage {
4040
/** @type {ProtectionsData} */
4141
const data = {
4242
totalCount: count,
43+
totalCookiePopUpsBlocked: null, // null means CPM is not enabled
4344
};
4445
await this.ntp.mocks.simulateSubscriptionMessage(named.subscription('protections_onDataUpdate'), data);
4546
await expect(this.context().getByRole('heading', { level: 3 })).toContainText(`${count} tracking attempts blocked`);
@@ -56,4 +57,56 @@ export class ProtectionsPage {
5657
- paragraph: Ostatnie 7 dni
5758
`);
5859
}
60+
61+
/**
62+
* Test that cookie popup blocking stats are displayed when both trackers and cookie popups are > 0
63+
*/
64+
async displaysCookiePopupStats() {
65+
/** @type {ProtectionsData} */
66+
const data = {
67+
totalCount: 100,
68+
totalCookiePopUpsBlocked: 25,
69+
};
70+
await this.ntp.mocks.simulateSubscriptionMessage(named.subscription('protections_onDataUpdate'), data);
71+
await expect(this.context().getByRole('heading', { level: 3 }).first()).toContainText('100 tracking attempts blocked');
72+
// Cookie popup stats should be visible
73+
await expect(this.context().getByText(/cookie pop-ups?/i)).toBeVisible();
74+
}
75+
76+
/**
77+
* Test that cookie popup stats are NOT displayed when totalCookiePopUpsBlocked is null (CPM disabled)
78+
*/
79+
async hidesCookiePopupStatsWhenDisabled() {
80+
/** @type {ProtectionsData} */
81+
const data = {
82+
totalCount: 100,
83+
totalCookiePopUpsBlocked: null,
84+
};
85+
await this.ntp.mocks.simulateSubscriptionMessage(named.subscription('protections_onDataUpdate'), data);
86+
// Cookie popup stats should not be visible
87+
await expect(this.context().getByText(/cookie pop-ups?/i)).not.toBeVisible();
88+
}
89+
90+
/**
91+
* Test that cookie popup stats are NOT displayed when totalCookiePopUpsBlocked is 0
92+
*/
93+
async hidesCookiePopupStatsWhenZero() {
94+
/** @type {ProtectionsData} */
95+
const data = {
96+
totalCount: 100,
97+
totalCookiePopUpsBlocked: 0,
98+
};
99+
await this.ntp.mocks.simulateSubscriptionMessage(named.subscription('protections_onDataUpdate'), data);
100+
// Cookie popup stats should not be visible when count is 0
101+
await expect(this.context().getByText(/cookie pop-ups?/i)).not.toBeVisible();
102+
}
103+
104+
/**
105+
* Test that the info tooltip is displayed
106+
*/
107+
async hasInfoTooltip() {
108+
const heading = this.context().getByTestId('ProtectionsHeading');
109+
// The InfoIcon should be present
110+
await expect(heading.locator('[class*="infoIcon"]')).toBeVisible();
111+
}
59112
}

special-pages/pages/new-tab/app/protections/integrations-tests/protections.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,44 @@ test.describe('protections report', () => {
5656
await protections.ready();
5757
await protections.hasPolishText();
5858
});
59+
60+
test('displays cookie popup blocking stats when enabled and counts > 0', async ({ page }, workerInfo) => {
61+
const ntp = NewtabPage.create(page, workerInfo);
62+
await ntp.reducedMotion();
63+
await ntp.openPage({ additional: { 'protections.feed': 'activity' } });
64+
65+
const protections = new ProtectionsPage(ntp);
66+
await protections.ready();
67+
await protections.displaysCookiePopupStats();
68+
});
69+
70+
test('hides cookie popup stats when CPM is disabled (null)', async ({ page }, workerInfo) => {
71+
const ntp = NewtabPage.create(page, workerInfo);
72+
await ntp.reducedMotion();
73+
await ntp.openPage({ additional: { 'protections.feed': 'activity' } });
74+
75+
const protections = new ProtectionsPage(ntp);
76+
await protections.ready();
77+
await protections.hidesCookiePopupStatsWhenDisabled();
78+
});
79+
80+
test('hides cookie popup stats when count is 0', async ({ page }, workerInfo) => {
81+
const ntp = NewtabPage.create(page, workerInfo);
82+
await ntp.reducedMotion();
83+
await ntp.openPage({ additional: { 'protections.feed': 'activity' } });
84+
85+
const protections = new ProtectionsPage(ntp);
86+
await protections.ready();
87+
await protections.hidesCookiePopupStatsWhenZero();
88+
});
89+
90+
test('displays info tooltip', async ({ page }, workerInfo) => {
91+
const ntp = NewtabPage.create(page, workerInfo);
92+
await ntp.reducedMotion();
93+
await ntp.openPage({ additional: { 'protections.feed': 'activity' } });
94+
95+
const protections = new ProtectionsPage(ntp);
96+
await protections.ready();
97+
await protections.hasInfoTooltip();
98+
});
5999
});

0 commit comments

Comments
 (0)