Skip to content

Commit 277ae90

Browse files
adwait-godboleillume
authored andcommitted
frontend: Add e2e-tests for react-hotkeys dependency
Signed-off-by: adwait-godbole <[email protected]>
1 parent 71b11a9 commit 277ae90

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

e2e-tests/tests/headlamp.spec.ts

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

54+
test('main page should have global search along with react-hotkey hint text', async () => {
55+
const globalSearch = await headlampPage.hasGlobalSearch();
56+
57+
const searchHintContainer = globalSearch.locator('xpath=following-sibling::div');
58+
const pressTextExists = await searchHintContainer.getByText(/^Press/).isVisible();
59+
const slashHotKeyExists = await searchHintContainer
60+
.locator('div')
61+
.filter({ hasText: /^\/$/ })
62+
.isVisible();
63+
const toSearchTextExists = await searchHintContainer.getByText(/to search$/).isVisible();
64+
65+
expect(pressTextExists && slashHotKeyExists && toSearchTextExists).toBeTruthy();
66+
});
67+
68+
test('react-hotkey for global search', async ({ page }) => {
69+
await page.keyboard.press('/');
70+
71+
const focusedSearch = page.getByPlaceholder(/^Search resources, pages, clusters by name$/);
72+
await expect(focusedSearch).toBeVisible();
73+
await expect(focusedSearch).toBeFocused();
74+
});
75+
5476
test('service page should have headlamp service', async () => {
5577
await servicesPage.navigateToServices();
5678
await servicesPage.clickOnServicesSection();

e2e-tests/tests/headlampPage.ts

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

79+
async hasGlobalSearch() {
80+
const globalSearch = this.page.getByPlaceholder(/^Search$/);
81+
82+
await expect(globalSearch).toBeVisible();
83+
await expect(globalSearch).toHaveValue(/^$/);
84+
await expect(globalSearch).not.toBeFocused();
85+
86+
return globalSearch;
87+
}
88+
7989
async checkPageContent(text: string) {
8090
await this.page.waitForSelector(`:has-text("${text}")`);
8191
const pageContent = await this.page.content();

e2e-tests/tests/multiCluster.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,34 @@ test.describe('multi-cluster setup', () => {
111111
await page.waitForLoadState('load');
112112
await headlampPage.hasTitleContaining(/Choose a cluster/);
113113
});
114+
115+
// This is commented out because the CI e2e test job loads the plugins
116+
// Which interferes with the test. It replaces the cluster chooser,
117+
// so this test does not work.
118+
119+
// test('react-hotkey to open cluster chooser', async ({ page }) => {
120+
// const testClusterAnchor = page.locator('table tbody tr td a', {
121+
// hasText: /^test$/,
122+
// });
123+
// await expect(testClusterAnchor).toBeVisible();
124+
// await expect(testClusterAnchor).toHaveAttribute('href', '/c/test/');
125+
126+
// await Promise.all([page.waitForNavigation(), testClusterAnchor.click()]);
127+
128+
// await headlampPage.authenticate(testToken);
129+
// await headlampPage.pageLocatorContent(
130+
// 'button:has-text("Our Cluster Chooser button. Cluster: test")',
131+
// 'Our Cluster Chooser button. Cluster: test'
132+
// );
133+
134+
// await page.keyboard.press('Control+Shift+L');
135+
136+
// const chooseClusterLabel = page.getByLabel(/^Choose cluster$/);
137+
// await expect(chooseClusterLabel).toBeVisible();
138+
139+
// const clusterNameInput = page.getByPlaceholder(/^Name$/);
140+
// await expect(clusterNameInput).toBeVisible();
141+
// await expect(clusterNameInput).toHaveValue(/^$/);
142+
// await expect(clusterNameInput).toBeFocused();
143+
// });
114144
});

e2e-tests/tests/podsPage.spec.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { test } from '@playwright/test';
17+
import { expect, test } from '@playwright/test';
1818
import { HeadlampPage } from './headlampPage';
1919
import { podsPage } from './podsPage';
2020

@@ -51,3 +51,40 @@ test('multi tab create delete pod', async ({ browser }) => {
5151
await realtimeUpdate1.createPod(name);
5252
await realtimeUpdate2.confirmPodCreation(name);
5353
});
54+
55+
test('react-hotkey for logs search', async ({ page }) => {
56+
const headlampPage = new HeadlampPage(page);
57+
await headlampPage.navigateToCluster('test', process.env.HEADLAMP_TEST_TOKEN);
58+
59+
await headlampPage.navigateTopage('/c/test/pods', /Pods/);
60+
61+
const podsTable = page.getByRole('table');
62+
await expect(podsTable).toBeVisible();
63+
64+
const podLink = podsTable
65+
.locator('tbody')
66+
.nth(0)
67+
.locator('tr')
68+
.nth(0)
69+
.locator('td')
70+
.nth(1)
71+
.locator('a');
72+
const podName = await podLink.textContent();
73+
74+
await podLink.click();
75+
76+
const podHeading = page.getByRole('heading', { level: 1, name: new RegExp(`^Pod: ${podName}$`) });
77+
await expect(podHeading).toBeVisible();
78+
79+
const showLogsButton = page.getByRole('button', { name: /^Show Logs$/ });
80+
await showLogsButton.click();
81+
82+
const terminal = page.locator('#xterm-container');
83+
await expect(terminal).toBeVisible();
84+
85+
await page.keyboard.press('Control+Shift+F');
86+
87+
const searchInput = page.getByPlaceholder(/^Find$/);
88+
await expect(searchInput).toBeVisible();
89+
await expect(searchInput).toBeFocused();
90+
});

0 commit comments

Comments
 (0)