Skip to content

Commit aeddd30

Browse files
Anton StandrikAnton Standrik
authored andcommitted
fix: turn experiments on
1 parent 69338f2 commit aeddd30

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

tests/suites/sidebar/Sidebar.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ export class Sidebar {
88
private documentationButton: Locator;
99
private accountButton: Locator;
1010
private collapseButton: Locator;
11+
private drawer: Locator;
12+
private drawerMenu: Locator;
13+
private experimentsSection: Locator;
1114

1215
constructor(page: Page) {
1316
this.sidebarContainer = page.locator('.gn-aside-header__aside-content');
1417
this.logoButton = this.sidebarContainer.locator('.gn-logo__btn-logo');
1518
this.footer = this.sidebarContainer.locator('.gn-aside-header__footer');
19+
this.drawer = page.locator('.gn-drawer');
20+
this.drawerMenu = page.locator('.gn-settings-menu');
21+
this.experimentsSection = this.drawerMenu
22+
.locator('.gn-settings-menu__item')
23+
.filter({hasText: 'Experiments'});
1624

1725
// Footer buttons with specific icons
1826
const footerItems = this.sidebarContainer.locator('.gn-footer-item');
@@ -94,4 +102,41 @@ export class Sidebar {
94102
const item = items.nth(index);
95103
return item.locator('.gn-composite-bar-item__title-text').innerText();
96104
}
105+
106+
async isDrawerVisible() {
107+
return this.drawer.isVisible();
108+
}
109+
110+
async getDrawerMenuItems(): Promise<string[]> {
111+
const items = this.drawerMenu.locator('.gn-settings-menu__item >> span');
112+
const count = await items.count();
113+
const texts: string[] = [];
114+
for (let i = 0; i < count; i++) {
115+
texts.push(await items.nth(i).innerText());
116+
}
117+
return texts;
118+
}
119+
120+
async clickExperimentsSection() {
121+
await this.experimentsSection.click();
122+
}
123+
124+
async toggleExperimentByTitle(title: string) {
125+
const experimentItem = this.drawer
126+
.locator('.gn-settings__item-title')
127+
.filter({hasText: title});
128+
// Click the label element which wraps the switch, avoiding the slider that intercepts events
129+
const switchLabel = experimentItem.locator(
130+
'xpath=../../..//label[contains(@class, "g-control-label")]',
131+
);
132+
await switchLabel.click();
133+
}
134+
135+
async isExperimentEnabled(title: string): Promise<boolean> {
136+
const experimentItem = this.drawer
137+
.locator('.gn-settings__item-title')
138+
.filter({hasText: title});
139+
const switchControl = experimentItem.locator('xpath=../../..//input[@type="checkbox"]');
140+
return switchControl.isChecked();
141+
}
97142
}

tests/suites/sidebar/sidebar.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ test.describe('Test Sidebar', async () => {
3131
await sidebar.clickSettings();
3232
});
3333

34+
test('Settings button click opens drawer with correct sections', async ({page}) => {
35+
const sidebar = new Sidebar(page);
36+
await sidebar.waitForSidebarToLoad();
37+
38+
// Initially drawer should not be visible
39+
await expect(sidebar.isDrawerVisible()).resolves.toBe(false);
40+
41+
// Click settings button
42+
await sidebar.clickSettings();
43+
await page.waitForTimeout(500); // Wait for animation
44+
45+
// Drawer should become visible
46+
await expect(sidebar.isDrawerVisible()).resolves.toBe(true);
47+
48+
// Verify drawer menu items
49+
const menuItems = await sidebar.getDrawerMenuItems();
50+
expect(menuItems).toEqual(['General', 'Editor', 'Experiments', 'About']);
51+
});
52+
3453
test('Documentation button is visible and clickable', async ({page}) => {
3554
const sidebar = new Sidebar(page);
3655
await sidebar.waitForSidebarToLoad();
@@ -70,4 +89,35 @@ test.describe('Test Sidebar', async () => {
7089
const itemsCount = await sidebar.getFooterItemsCount();
7190
expect(itemsCount).toBeGreaterThan(0);
7291
});
92+
93+
test('Can toggle experiments in settings', async ({page}) => {
94+
const sidebar = new Sidebar(page);
95+
await sidebar.waitForSidebarToLoad();
96+
97+
// Open settings
98+
await sidebar.clickSettings();
99+
await page.waitForTimeout(500); // Wait for animation
100+
101+
// Click experiments section
102+
await sidebar.clickExperimentsSection();
103+
await page.waitForTimeout(500); // Wait for animation
104+
105+
// Toggle "Use paginated tables" experiment
106+
const experimentTitle = 'Use paginated tables';
107+
const initialState = await sidebar.isExperimentEnabled(experimentTitle);
108+
await sidebar.toggleExperimentByTitle(experimentTitle);
109+
await page.waitForTimeout(500); // Wait for animation
110+
111+
// Verify the state has changed
112+
const newState = await sidebar.isExperimentEnabled(experimentTitle);
113+
expect(newState).not.toBe(initialState);
114+
115+
// Toggle back
116+
await sidebar.toggleExperimentByTitle(experimentTitle);
117+
await page.waitForTimeout(500); // Wait for animation
118+
119+
// Verify it's back to initial state
120+
const finalState = await sidebar.isExperimentEnabled(experimentTitle);
121+
expect(finalState).toBe(initialState);
122+
});
73123
});

0 commit comments

Comments
 (0)