-
Notifications
You must be signed in to change notification settings - Fork 210
Added tests to check the websocket in logs section (Object Explorer page) #2220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,280 @@ | ||||||||||||||||||||||||||||||||||||
| import { test, expect } from '@playwright/test'; | ||||||||||||||||||||||||||||||||||||
| import type { Page, WebSocket } from '@playwright/test'; | ||||||||||||||||||||||||||||||||||||
| import { LoginPage, ObjectExplorerPage, MSWHelper } from './pages'; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| test.describe('Object Explorer - WebSocket and API Integration', () => { | ||||||||||||||||||||||||||||||||||||
| let loginPage: LoginPage; | ||||||||||||||||||||||||||||||||||||
| let objectExplorerPage: ObjectExplorerPage; | ||||||||||||||||||||||||||||||||||||
| let mswHelper: MSWHelper; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| async function checkResourceDetailsAvailable(page: Page): Promise<boolean> { | ||||||||||||||||||||||||||||||||||||
| const detailsPanel = objectExplorerPage.detailsPanel; | ||||||||||||||||||||||||||||||||||||
| const isPanelVisible = await detailsPanel.isVisible().catch(() => false); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (isPanelVisible) return true; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const hasDetailsContent = await page | ||||||||||||||||||||||||||||||||||||
| .locator('text=/summary|edit|logs|yaml|overview/i') | ||||||||||||||||||||||||||||||||||||
| .first() | ||||||||||||||||||||||||||||||||||||
| .isVisible() | ||||||||||||||||||||||||||||||||||||
| .catch(() => false); | ||||||||||||||||||||||||||||||||||||
| const hasTabs = await page | ||||||||||||||||||||||||||||||||||||
| .locator('[role="tab"], .MuiTab-root') | ||||||||||||||||||||||||||||||||||||
| .first() | ||||||||||||||||||||||||||||||||||||
| .isVisible() | ||||||||||||||||||||||||||||||||||||
| .catch(() => false); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return hasDetailsContent || hasTabs; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| test.beforeEach(async ({ page }) => { | ||||||||||||||||||||||||||||||||||||
| loginPage = new LoginPage(page); | ||||||||||||||||||||||||||||||||||||
| objectExplorerPage = new ObjectExplorerPage(page); | ||||||||||||||||||||||||||||||||||||
| mswHelper = new MSWHelper(page); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| await loginPage.goto(); | ||||||||||||||||||||||||||||||||||||
| await loginPage.login(); | ||||||||||||||||||||||||||||||||||||
| await loginPage.waitForRedirect(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| await mswHelper.applyScenario('webSocketAPISuccess'); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.goto(); | ||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.waitForPageLoad(); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.selectKind('Pod'); | ||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.selectNamespace('default'); | ||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.waitForResources(); | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| test('should receive real-time log messages via WebSocket', async ({ page }) => { | ||||||||||||||||||||||||||||||||||||
| await objectExplorerPage.openResourceDetails(0); | ||||||||||||||||||||||||||||||||||||
| const isAvailable = await checkResourceDetailsAvailable(page); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if (!isAvailable) { | ||||||||||||||||||||||||||||||||||||
| console.warn('Resource details feature not implemented - WebSocket test skipped'); | ||||||||||||||||||||||||||||||||||||
| expect(true).toBe(true); | ||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const logMessages: string[] = []; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| page.on('websocket', (ws: WebSocket) => { | ||||||||||||||||||||||||||||||||||||
| console.info('WebSocket opened:', ws.url()); | ||||||||||||||||||||||||||||||||||||
| ws.on('framereceived', event => { | ||||||||||||||||||||||||||||||||||||
| if (event.payload) { | ||||||||||||||||||||||||||||||||||||
| logMessages.push(event.payload.toString()); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+68
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| await mswHelper.applyScenario('logStreamingMessages'); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| const logsTab = objectExplorerPage.logsTab; | ||||||||||||||||||||||||||||||||||||
| if (await logsTab.isVisible().catch(() => false)) { | ||||||||||||||||||||||||||||||||||||
| await logsTab.click(); | ||||||||||||||||||||||||||||||||||||
| await page.waitForTimeout(5000); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| await page.waitForTimeout(5000); | |
| await expect.poll(() => logMessages.length, { | |
| message: 'Waiting for at least one log message via WebSocket', | |
| timeout: parseInt(process.env.LOG_MESSAGE_TIMEOUT ?? '10000', 10), | |
| }).toBeGreaterThan(0); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nested conditional logic (lines 80-94) adds complexity and makes the test harder to maintain. Consider extracting this validation into a separate helper function like validateLogMessageFormat(messages: string[]): boolean.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will always pass due to the fallback logic. When logMessages.length > 0 is false, the test falls through to line 97 where it sets expect(true).toBe(true). This means the test passes even when WebSocket functionality doesn't work. Consider failing the test or using test.skip() if the feature is genuinely not implemented.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar race condition as in the previous test. The WebSocket listener is registered after opening resource details. Move this listener registration before openResourceDetails(0) at line 106 to capture all WebSocket connections.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple hard-coded timeouts (2000ms, 1000ms, 3000ms) make the test brittle and slow. Consider using Playwright's waitForEvent() with WebSocket events or making these timeouts configurable. This pattern is repeated throughout the file.
| await page.waitForTimeout(2000); | |
| await mswHelper.applyScenario('networkInterruption'); | |
| await page.waitForTimeout(1000); | |
| await mswHelper.applyScenario('logStreamingWebSocket'); | |
| await page.waitForTimeout(3000); | |
| // Wait for WebSocket connection after clicking logs tab | |
| await page.waitForEvent('websocket'); | |
| await mswHelper.applyScenario('networkInterruption'); | |
| // Wait for WebSocket reconnection after network interruption | |
| await page.waitForEvent('websocket'); | |
| await mswHelper.applyScenario('logStreamingWebSocket'); | |
| // Wait for WebSocket connection after log streaming resumes | |
| await page.waitForEvent('websocket'); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion expect(connectionCount).toBeGreaterThan(0) when connectionCount > 0 is redundant since the condition already checks this. Either assert something more specific about the reconnection behavior (e.g., expect(connectionCount).toBeGreaterThanOrEqual(2) to verify reconnection) or simplify the logic.
| expect(connectionCount).toBeGreaterThan(0); | |
| expect(connectionCount).toBeGreaterThanOrEqual(2); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test follows the same pattern as the previous WebSocket test with similar conditional logic and fallbacks. Consider extracting common test setup (resource details opening, feature availability check, WebSocket listener registration) into a reusable helper function to reduce code duplication.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request listener should be registered before opening resource details to avoid missing early API requests. Move this listener registration before line 152 (await objectExplorerPage.openResourceDetails(0);).
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This complex multi-condition check for YAML requests is repeated in similar form for logs requests (lines 220-225). Consider extracting into a helper function like hasMatchingRequest(requests: string[], patterns: string[]): boolean to improve maintainability.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to line 162, this request listener should be registered before opening resource details at line 198 to capture all API requests that may occur during the details panel opening.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test and the following tests (lines 151-241) follow a repetitive pattern with nearly identical structure: open details, check availability, register listener, apply scenario, click tab, wait, check results with fallbacks. Consider creating a reusable test helper function to reduce duplication and improve maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertion
expect(true).toBe(true)is redundant and doesn't validate anything. If the test should be skipped when the feature is not implemented, consider usingtest.skip()instead, or simply return without an assertion.