Skip to content

Commit 231437d

Browse files
committed
another global fix
1 parent 2323712 commit 231437d

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

special-pages/pages/new-tab/app/customizer/components/CustomizerMenu.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,8 @@ export function useCustomizer({ title, id, icon, toggle, visibility, index }) {
110110

111111
useEffect(() => {
112112
window.dispatchEvent(new Event(UPDATE_EVENT));
113+
return () => {
114+
window.dispatchEvent(new Event(UPDATE_EVENT));
115+
};
113116
}, [visibility]);
114117
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class CustomizerPage {
2020
this.ntp = ntp;
2121
}
2222

23+
context = () => this.ntp.page.locator('aside');
24+
2325
async showsColorSelectionPanel() {
2426
const { page } = this.ntp;
2527
await page.locator('aside').getByLabel('Solid Colors').click();
@@ -459,4 +461,34 @@ export class CustomizerPage {
459461
button: 'right',
460462
});
461463
}
464+
465+
/**
466+
* @param {string} name
467+
* @returns {Promise<void>}
468+
*/
469+
async isChecked(name) {
470+
await expect(this.context().getByRole('switch', { name })).toBeChecked();
471+
}
472+
473+
/**
474+
* @param {string} name
475+
* @returns {Promise<void>}
476+
*/
477+
async isUnchecked(name) {
478+
await expect(this.context().getByRole('switch', { name })).not.toBeChecked({ timeout: 1000 });
479+
}
480+
481+
/**
482+
* @param {string} name
483+
*/
484+
async hasSwitch(name) {
485+
await expect(this.context().getByRole('switch', { name })).toBeVisible();
486+
}
487+
488+
/**
489+
* @param {string} name
490+
*/
491+
async doesntHaveSwitch(name) {
492+
await expect(this.context().getByRole('switch', { name })).not.toBeVisible();
493+
}
462494
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
22

33
/**
44
* @typedef {import("../../../types/new-tab.js").OmnibarMode} Mode
5+
* @typedef {import("../../../types/new-tab.js").OmnibarConfig} Config
56
*/
67

78
export class OmnibarPage {
@@ -193,10 +194,11 @@ export class OmnibarPage {
193194
}
194195

195196
/**
197+
* @param {Config} config
196198
* @returns {Promise<void>}
197199
*/
198-
async didDisableGlobally() {
199-
const event = sub('omnibar_onConfigUpdate').payload({ mode: 'search', enableAi: false, showAiSetting: false });
200+
async didReceiveConfig(config) {
201+
const event = sub('omnibar_onConfigUpdate').payload(config);
200202
await test.step(`simulates global disabled (eg: settings): ${JSON.stringify(event.name)} ${JSON.stringify(event.payload)} `, async () => {
201203
await this.ntp.mocks.simulateSubscriptionEvent(event);
202204
});
@@ -229,7 +231,6 @@ export class OmnibarPage {
229231
return await expect(this.chatInput()).toHaveValue(value);
230232
}
231233
case 'search': {
232-
await this.searchInput().waitFor({ timeout: 1000 });
233234
return await expect(this.searchInput()).toHaveValue(value);
234235
}
235236
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ test.describe('omnibar widget persistence', () => {
7676
test('adjusts mode of other tabs when duck.ai is globally disabled', async ({ page }, workerInfo) => {
7777
const ntp = NewtabPage.create(page, workerInfo);
7878
const omnibar = new OmnibarPage(ntp);
79+
const customizer = new CustomizerPage(ntp);
7980
await ntp.reducedMotion();
8081
await ntp.openPage({ additional: { omnibar: true, tabs: true, 'tabs.debug': true } });
8182
await omnibar.ready();
@@ -87,12 +88,25 @@ test.describe('omnibar widget persistence', () => {
8788
await omnibar.didSwitchToTab('02', ['01', '02']);
8889
await omnibar.expectValue({ value: '', mode: 'ai' });
8990

90-
// disable globally
91-
await omnibar.didDisableGlobally();
92-
await omnibar.expectValue({ value: '', mode: 'search' });
91+
// open sidebar
92+
await customizer.opensCustomizer();
9393

94-
// back to first tab, should now also be search
95-
await omnibar.didSwitchToTab('01', ['01', '02']);
94+
// control: make sure the Duck.ai toggle is there
95+
await customizer.hasSwitch('Toggle Duck.ai');
96+
97+
// now receive global config settings...
98+
await omnibar.didReceiveConfig({ mode: 'search', enableAi: false, showAiSetting: false });
99+
100+
// ...and expect search box to be empty, but still on search mode.
96101
await omnibar.expectValue({ value: '', mode: 'search' });
102+
103+
// also, expect menu in sidebar to be updated (eg: switch is removed)
104+
await customizer.doesntHaveSwitch('Toggle Duck.ai');
105+
106+
// Second config, disable globally, but keep 'showAiSetting: true'
107+
await omnibar.didReceiveConfig({ mode: 'search', enableAi: false, showAiSetting: true });
108+
109+
// Ensure the toggle is back and is unchecked
110+
await customizer.isUnchecked('Toggle Duck.ai');
97111
});
98112
});

0 commit comments

Comments
 (0)