Skip to content

Commit e93b312

Browse files
authored
test(EndToEnd): Labels tests (#146)
1 parent 43f5cee commit e93b312

File tree

30 files changed

+418
-35
lines changed

30 files changed

+418
-35
lines changed

e2e/fixtures/pages/ExploreProfilesPage.ts

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ export class ExploreProfilesPage extends PyroscopePage {
4949

5050
/* Time picker/refresh */
5151

52-
getTimePicker() {
52+
getTimePickerButton() {
5353
return this.getByTestId('data-testid TimePicker Open Button');
5454
}
5555

5656
async assertSelectedTimeRange(expectedTimeRange: string) {
57-
await expect(this.getTimePicker()).toContainText(expectedTimeRange);
57+
await expect(this.getTimePickerButton()).toContainText(expectedTimeRange);
58+
}
59+
60+
async selectTimeRange(quickRangeLabel: string) {
61+
await this.getTimePickerButton().click();
62+
await this.getByTestId('data-testid TimePicker Overlay Content').getByText(quickRangeLabel).click();
5863
}
5964

6065
getRefreshPicker() {
@@ -151,25 +156,40 @@ export class ExploreProfilesPage extends PyroscopePage {
151156
return this.getLayoutSwitcher().getByLabel(layoutName).click();
152157
}
153158

154-
/* No data switch */
159+
/* Hide panels without data switcher */
155160

156-
async getNoDataSwitcher() {
157-
const inputId = await this.getByLabel('Hide panels without data').getAttribute('for');
158-
return this.locator(`input[type="checkbox"]#${inputId}`);
161+
getHideNoDataSwitcher() {
162+
return this.getByTestId('noDataSwitcher');
159163
}
160164

161-
async assertNoDataSwitcher(isChecked: boolean) {
162-
const checkBoxInput = await this.getNoDataSwitcher();
163-
165+
async assertHideNoDataSwitcher(isChecked: boolean) {
164166
if (isChecked) {
165-
await expect(checkBoxInput).toBeChecked();
167+
await expect(this.getHideNoDataSwitcher()).toBeChecked();
166168
} else {
167-
await expect(checkBoxInput).not.toBeChecked();
169+
await expect(this.getHideNoDataSwitcher()).not.toBeChecked();
168170
}
169171
}
170172

171-
async selectNoData() {
172-
return (await this.getNoDataSwitcher()).click();
173+
async selectHidePanelsWithoutNoData() {
174+
// weirdly the mouse is on the "Flame graph" panel action at this point
175+
// so we have to move it for the label to become actionable
176+
await this.page.mouse.move(0, 0);
177+
await this.getByLabel('Hide panels without data').click();
178+
}
179+
180+
/* Panel type switcher */
181+
182+
getPanelTypeSwitcher() {
183+
return this.getByLabel('Panel type switcher');
184+
}
185+
186+
async assertSelectedPanelType(expectedPanelType: string) {
187+
const panelType = await this.getPanelTypeSwitcher().locator('input[checked]~label').textContent();
188+
await expect(panelType?.trim()).toBe(expectedPanelType);
189+
}
190+
191+
selectPanelType(panelType: string) {
192+
return this.getPanelTypeSwitcher().getByLabel(panelType).click();
173193
}
174194

175195
/* Scene body & grid panels */
@@ -191,6 +211,10 @@ export class ExploreProfilesPage extends PyroscopePage {
191211
await panel.getByLabel(actionLabel).click();
192212
}
193213

214+
async assertPanelHasNoData(panelTitle: string) {
215+
await expect(this.getPanelByTitle(panelTitle).getByText('No data')).toBeVisible();
216+
}
217+
194218
async assertNoSpinner() {
195219
await expect(this.getByTestId('Spinner')).toHaveCount(0);
196220
}
@@ -255,6 +279,41 @@ export class ExploreProfilesPage extends PyroscopePage {
255279
}
256280

257281
closeFlameGraphContextualMenu() {
258-
return this.getByTestId('panel').getByRole('heading').click();
282+
return this.getByTestId('header-container').first().click();
283+
}
284+
285+
/* Group by */
286+
287+
getGroupByContainer() {
288+
return this.getByTestId('groupByLabelsContainer');
289+
}
290+
291+
getGroupByPanels() {
292+
return this.getGroupByContainer().locator(`[data-viz-panel-key]`);
293+
}
294+
295+
getGroupByLabelsSelector() {
296+
return this.getGroupByContainer().getByLabel('Labels selector', { exact: true });
297+
}
298+
299+
async selectGroupByLabel(label: string) {
300+
await this.getGroupByLabelsSelector().getByLabel(label, { exact: true }).click();
301+
}
302+
303+
getCompareButton() {
304+
return this.getGroupByContainer().getByRole('button', { name: 'Compare' });
305+
}
306+
307+
getClearComparisonButton() {
308+
// getByRole('button', { name:... }) does not work :man_shrug:
309+
return this.getGroupByContainer().getByTestId('clearComparison');
310+
}
311+
312+
getStatsPanel(labelValue: string) {
313+
return this.getGroupByContainer().getByTestId(`stats-panel-${labelValue}`);
314+
}
315+
316+
async selectForComparison(panelTitle: string, target: string) {
317+
await this.getStatsPanel(panelTitle).getByText(target).click();
259318
}
260319
}

e2e/fixtures/pages/PyroscopePage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class PyroscopePage {
2626
return this.page.getByTestId(testId);
2727
}
2828

29-
getByLabel(label: string) {
30-
return this.page.getByLabel(label);
29+
getByLabel(label: string, options?: Record<string, unknown>) {
30+
return this.page.getByLabel(label, options);
3131
}
3232

3333
getByText(text, options?: Record<string, unknown>) {

e2e/tests/all-services-view/all-services.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ test.describe('All services view', () => {
2121
await expect(exploreProfilesPage.getSceneBody()).toHaveScreenshot();
2222
});
2323

24+
test.describe('Main refresh button', () => {
25+
test('To presrve the user context, the panels in grid remains in placeuntil "Refresh" is clicked', async ({
26+
exploreProfilesPage,
27+
}) => {
28+
await expect(exploreProfilesPage.getPanels()).toHaveCount(3);
29+
await expect(exploreProfilesPage.getPanelByTitle('load-generator')).toBeVisible();
30+
await expect(exploreProfilesPage.getPanelByTitle('pyroscope')).toBeVisible();
31+
await expect(exploreProfilesPage.getPanelByTitle('ride-sharing-app')).toBeVisible();
32+
33+
await exploreProfilesPage.selectTimeRange('Last 5 minutes');
34+
35+
await expect(exploreProfilesPage.getPanels()).toHaveCount(3);
36+
await expect(exploreProfilesPage.getPanelByTitle('load-generator')).toBeVisible();
37+
await expect(exploreProfilesPage.getPanelByTitle('pyroscope')).toBeVisible();
38+
await expect(exploreProfilesPage.getPanelByTitle('ride-sharing-app')).toBeVisible();
39+
40+
await exploreProfilesPage.clickOnRefresh();
41+
42+
await expect(exploreProfilesPage.getPanels()).toHaveCount(1);
43+
await expect(exploreProfilesPage.getPanelByTitle('pyroscope')).toBeVisible();
44+
});
45+
});
46+
2447
test('Profile type selector', async ({ exploreProfilesPage }) => {
2548
await exploreProfilesPage.selectProfileType('memory/inuse_objects');
2649

@@ -35,7 +58,6 @@ test.describe('All services view', () => {
3558
await expect(exploreProfilesPage.getPanels()).toHaveCount(2);
3659
await expect(exploreProfilesPage.getPanelByTitle('load-generator')).toBeVisible();
3760
await expect(exploreProfilesPage.getPanelByTitle('ride-sharing-app')).toBeVisible();
38-
await expect(exploreProfilesPage.getPanelByTitle('pyroscope')).not.toBeVisible();
3961
});
4062

4163
test('Layout switcher', async ({ exploreProfilesPage }) => {

e2e/tests/favorites-view/favorites-view.spec.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test.describe('Favorites view', () => {
3131
// body scene controls
3232
await exploreProfilesPage.assertQuickFilter('Search favorites (comma-separated regexes are supported)', '');
3333
await exploreProfilesPage.assertSelectedLayout('Grid');
34-
await exploreProfilesPage.assertNoDataSwitcher(false);
34+
await exploreProfilesPage.assertHideNoDataSwitcher(false);
3535

3636
// body
3737
await expect(exploreProfilesPage.getSceneBody()).toHaveScreenshot();
@@ -56,10 +56,25 @@ test.describe('Favorites view', () => {
5656
});
5757
});
5858

59+
test('Hide no data switcher', async ({ exploreProfilesPage }) => {
60+
await exploreProfilesPage.selectTimeRange('Last 5 minutes');
61+
62+
await expect(exploreProfilesPage.getPanels()).toHaveCount(4);
63+
await expect(exploreProfilesPage.getPanelByTitle('pyroscope · goroutine (goroutine)')).toBeVisible();
64+
65+
await exploreProfilesPage.assertPanelHasNoData('load-generator · cpu (process_cpu)');
66+
await exploreProfilesPage.assertPanelHasNoData('ride-sharing-app · inuse_space (memory)');
67+
await exploreProfilesPage.assertPanelHasNoData('ride-sharing-app · samples (process_cpu) · vehicle (4)');
68+
69+
await exploreProfilesPage.selectHidePanelsWithoutNoData();
70+
71+
await expect(exploreProfilesPage.getPanels()).toHaveCount(1);
72+
await expect(exploreProfilesPage.getPanelByTitle('pyroscope · goroutine (goroutine)')).toBeVisible();
73+
});
74+
5975
test.describe('Panel actions', () => {
6076
test('Labels action without "group by"', async ({ exploreProfilesPage }) => {
61-
const panel = await exploreProfilesPage.getPanelByTitle('ride-sharing-app · inuse_space (memory)');
62-
await panel.getByLabel('Labels').click();
77+
await exploreProfilesPage.clickOnPanelAction('ride-sharing-app · inuse_space (memory)', 'Labels');
6378

6479
await exploreProfilesPage.asserSelectedExplorationType('Labels');
6580
await exploreProfilesPage.assertSelectedService('ride-sharing-app');
@@ -73,8 +88,7 @@ test.describe('Favorites view', () => {
7388
});
7489

7590
test('Labels action with "group by"', async ({ exploreProfilesPage }) => {
76-
const panel = await exploreProfilesPage.getPanelByTitle('ride-sharing-app · samples (process_cpu) · vehicle (4)');
77-
await panel.getByLabel('Labels').click();
91+
await exploreProfilesPage.clickOnPanelAction('ride-sharing-app · samples (process_cpu) · vehicle (4)', 'Labels');
7892

7993
await exploreProfilesPage.asserSelectedExplorationType('Labels');
8094
await exploreProfilesPage.assertSelectedService('ride-sharing-app');
@@ -88,8 +102,7 @@ test.describe('Favorites view', () => {
88102
});
89103

90104
test('Flame graph action', async ({ exploreProfilesPage }) => {
91-
const panel = await exploreProfilesPage.getPanelByTitle('ride-sharing-app · inuse_space (memory)');
92-
await panel.getByLabel('Flame graph').click();
105+
await exploreProfilesPage.clickOnPanelAction('ride-sharing-app · inuse_space (memory)', 'Flame graph');
93106

94107
await exploreProfilesPage.asserSelectedExplorationType('Flame graph');
95108
await exploreProfilesPage.assertSelectedService('ride-sharing-app');
@@ -112,8 +125,7 @@ test.describe('Favorites view', () => {
112125
});
113126

114127
test('Favorite action, after clicking on the main refresh button', async ({ exploreProfilesPage }) => {
115-
const panel = await exploreProfilesPage.getPanelByTitle('ride-sharing-app · inuse_space (memory)');
116-
await panel.getByLabel('Favorite').click();
128+
await exploreProfilesPage.clickOnPanelAction('ride-sharing-app · inuse_space (memory)', 'Favorite');
117129

118130
await exploreProfilesPage.clickOnRefresh();
119131

0 commit comments

Comments
 (0)