Skip to content

Commit 21ae759

Browse files
frontend: Add e2e-tests for react-hotkeys dependency
Signed-off-by: adwait-godbole <[email protected]>
1 parent fe12924 commit 21ae759

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

e2e-tests/tests/headlamp.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@ test('main page should have Network tab', async () => {
3535
await headlampPage.hasNetworkTab();
3636
});
3737

38+
test('main page should have global search along with react-hotkey hint text', async () => {
39+
const globalSearch = await headlampPage.hasGlobalSearch();
40+
41+
const searchHintContainer = globalSearch.locator('xpath=following-sibling::div');
42+
const pressTextExists = await searchHintContainer.getByText(/^Press/).isVisible();
43+
const slashHotKeyExists = await searchHintContainer
44+
.locator('div')
45+
.filter({ hasText: /^\/$/ })
46+
.isVisible();
47+
const toSearchTextExists = await searchHintContainer.getByText(/to search$/).isVisible();
48+
49+
expect(pressTextExists && slashHotKeyExists && toSearchTextExists).toBeTruthy();
50+
});
51+
52+
test('react-hotkey for global search', async ({ page }) => {
53+
await page.keyboard.press('/');
54+
55+
const focusedSearch = page.getByPlaceholder(/^Search resources, pages, clusters by name$/);
56+
await expect(focusedSearch).toBeVisible();
57+
await expect(focusedSearch).toBeFocused();
58+
});
59+
3860
test('service page should have headlamp service', async () => {
3961
await servicesPage.navigateToServices();
4062
await servicesPage.clickOnServicesSection();

e2e-tests/tests/headlampPage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export class HeadlampPage {
5353
expect(await securityTab.textContent()).toBe('Security');
5454
}
5555

56+
async hasGlobalSearch() {
57+
const globalSearch = this.page.getByPlaceholder(/^Search$/);
58+
59+
await expect(globalSearch).toBeVisible();
60+
await expect(globalSearch).toHaveValue(/^$/);
61+
await expect(globalSearch).not.toBeFocused();
62+
63+
return globalSearch;
64+
}
65+
5666
async checkPageContent(text: string) {
5767
await this.page.waitForSelector(`:has-text("${text}")`);
5868
const pageContent = await this.page.content();

e2e-tests/tests/multiCluster.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,30 @@ test.describe('multi-cluster setup', () => {
9595
await page.waitForLoadState('load');
9696
await headlampPage.hasTitleContaining(/Choose a cluster/);
9797
});
98+
99+
test('react-hotkey to open cluster chooser', async ({ page }) => {
100+
const testClusterAnchor = page.locator('table tbody tr td a', {
101+
hasText: /^test$/,
102+
});
103+
await expect(testClusterAnchor).toBeVisible();
104+
await expect(testClusterAnchor).toHaveAttribute('href', '/c/test/');
105+
106+
await Promise.all([page.waitForNavigation(), testClusterAnchor.click()]);
107+
108+
await headlampPage.authenticate(testToken);
109+
await headlampPage.pageLocatorContent(
110+
'button:has-text("Our Cluster Chooser button. Cluster: test")',
111+
'Our Cluster Chooser button. Cluster: test'
112+
);
113+
114+
await page.keyboard.press('Control+Shift+L');
115+
116+
const chooseClusterLabel = page.getByLabel(/^Choose cluster$/);
117+
await expect(chooseClusterLabel).toBeVisible();
118+
119+
const clusterNameInput = page.getByPlaceholder(/^Name$/);
120+
await expect(clusterNameInput).toBeVisible();
121+
await expect(clusterNameInput).toHaveValue(/^$/);
122+
await expect(clusterNameInput).toBeFocused();
123+
});
98124
});

e2e-tests/tests/podsPage.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from '@playwright/test';
1+
import { expect, test } from '@playwright/test';
22
import { HeadlampPage } from './headlampPage';
33
import { podsPage } from './podsPage';
44

@@ -39,3 +39,39 @@ test('multi tab create delete pod', async ({ browser }) => {
3939
await realtimeUpdate1.deletePod(name);
4040
await realtimeUpdate2.confirmPodDeletion(name);
4141
});
42+
43+
test('react-hotkey for logs search', async ({ page }) => {
44+
const headlampPage = new HeadlampPage(page);
45+
await headlampPage.navigateToCluster('test', process.env.HEADLAMP_TEST_TOKEN);
46+
47+
await new podsPage(page).navigateToPods();
48+
49+
const podsTable = page.getByRole('table');
50+
await expect(podsTable).toBeVisible();
51+
52+
const podLink = podsTable
53+
.locator('tbody')
54+
.nth(0)
55+
.locator('tr')
56+
.nth(0)
57+
.locator('td')
58+
.nth(1)
59+
.locator('a');
60+
const podName = await podLink.textContent();
61+
62+
await Promise.all([page.waitForNavigation(), podLink.click()]);
63+
64+
await expect(page.getByRole('heading', { level: 1 })).toHaveText(new RegExp(`^Pod: ${podName}$`));
65+
66+
const showLogsButton = page.getByRole('button', { name: /^Show Logs$/ });
67+
await showLogsButton.click();
68+
69+
const terminal = page.locator('#xterm-container');
70+
await expect(terminal).toBeVisible();
71+
72+
await page.keyboard.press('Control+Shift+F');
73+
74+
const searchInput = page.getByPlaceholder(/^Find$/);
75+
await expect(searchInput).toBeVisible();
76+
await expect(searchInput).toBeFocused();
77+
});

0 commit comments

Comments
 (0)