|
| 1 | +import {expect, test, ElectronApplication, Page} from '@playwright/test'; |
| 2 | + |
| 3 | +import {NavPage} from './pages/nav-page'; |
| 4 | +import {ContainerLogsPage} from './pages/container-logs-page'; |
| 5 | +import {startSlowerDesktop, teardown, tool} from './utils/TestUtils'; |
| 6 | + |
| 7 | +let page: Page; |
| 8 | + |
| 9 | +test.describe.serial('Container Logs Tests', () => { |
| 10 | + let electronApp: ElectronApplication; |
| 11 | + let testContainerId: string; |
| 12 | + let testContainerName: string; |
| 13 | + |
| 14 | + test.beforeAll(async ({}, testInfo) => { |
| 15 | + [electronApp, page] = await startSlowerDesktop(testInfo, { |
| 16 | + kubernetes: {enabled: false}, |
| 17 | + containerEngine: {allowedImages: {enabled: false}} |
| 18 | + }); |
| 19 | + |
| 20 | + const navPage = new NavPage(page); |
| 21 | + await navPage.progressBecomesReady(); |
| 22 | + }); |
| 23 | + |
| 24 | + test.afterAll(async ({}, testInfo) => { |
| 25 | + if (testContainerId) { |
| 26 | + try { |
| 27 | + await tool('docker', 'rm', '-f', testContainerId); |
| 28 | + } catch (error) { |
| 29 | + } |
| 30 | + } |
| 31 | + await teardown(electronApp, testInfo); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should navigate to containers page', async () => { |
| 35 | + const navPage = new NavPage(page); |
| 36 | + const containersPage = await navPage.navigateTo('Containers'); |
| 37 | + |
| 38 | + await expect(navPage.mainTitle).toHaveText('Containers'); |
| 39 | + await containersPage.waitForTableToLoad(); |
| 40 | + }); |
| 41 | + |
| 42 | + test('should create and display test container', async () => { |
| 43 | + testContainerName = `test-logs-container-${Date.now()}`; |
| 44 | + |
| 45 | + const output = await tool('docker', 'run', '--detach', '--name', testContainerName, |
| 46 | + 'alpine', 'sh', '-c', 'echo "Starting"; for i in $(seq 1 10); do echo "L$i: msg$i"; done; echo "Finished"'); testContainerId = output.trim(); |
| 47 | + |
| 48 | + expect(testContainerId).toMatch(/^[a-f0-9]{64}$/); |
| 49 | + |
| 50 | + await page.reload(); |
| 51 | + |
| 52 | + const navPage = new NavPage(page); |
| 53 | + const containersPage = await navPage.navigateTo('Containers'); |
| 54 | + await containersPage.waitForTableToLoad(); |
| 55 | + |
| 56 | + await containersPage.waitForContainerToAppear(testContainerId); |
| 57 | + await containersPage.viewContainerLogs(testContainerId); |
| 58 | + |
| 59 | + await page.waitForURL(`**/containers/logs/${testContainerId}`, {timeout: 10_000}); |
| 60 | + }); |
| 61 | + |
| 62 | + test('should display container logs page', async () => { |
| 63 | + const containerLogsPage = new ContainerLogsPage(page); |
| 64 | + |
| 65 | + await expect(containerLogsPage.containerInfo).toBeVisible(); |
| 66 | + |
| 67 | + await expect(containerLogsPage.terminal).toBeVisible(); |
| 68 | + await expect(containerLogsPage.loadingIndicator).not.toBeVisible(); |
| 69 | + }); |
| 70 | + |
| 71 | + test('should show container information', async () => { |
| 72 | + const containerLogsPage = new ContainerLogsPage(page); |
| 73 | + |
| 74 | + await expect(containerLogsPage.containerInfo).toBeVisible(); |
| 75 | + |
| 76 | + await expect(containerLogsPage.containerName).toContainText(testContainerName); |
| 77 | + await expect(containerLogsPage.containerState).not.toBeEmpty(); |
| 78 | + }); |
| 79 | + |
| 80 | + test('should display logs content', async () => { |
| 81 | + const containerLogsPage = new ContainerLogsPage(page); |
| 82 | + |
| 83 | + await containerLogsPage.waitForLogsToLoad(); |
| 84 | + |
| 85 | + await expect(containerLogsPage.terminal).toContainText('L1: msg1'); |
| 86 | +}); |
| 87 | + |
| 88 | + test('should support log search', async () => { |
| 89 | + const containerLogsPage = new ContainerLogsPage(page); |
| 90 | + |
| 91 | + await expect(containerLogsPage.searchInput).toBeVisible(); |
| 92 | + |
| 93 | + const searchTerm = 'msg'; |
| 94 | + await containerLogsPage.searchLogs(searchTerm); |
| 95 | + |
| 96 | + const searchHighlight = page.locator('span.xterm-decoration-top'); |
| 97 | + await expect(searchHighlight).toBeVisible(); |
| 98 | + |
| 99 | + const highlightedRow = containerLogsPage.terminal.locator('.xterm-rows div', { |
| 100 | + has: page.locator('.xterm-decoration-top') |
| 101 | + }); |
| 102 | + |
| 103 | + await expect(highlightedRow).toContainText('L1: msg1'); |
| 104 | + |
| 105 | + await containerLogsPage.searchNextButton.click(); |
| 106 | + |
| 107 | + await expect(searchHighlight).toBeVisible(); |
| 108 | + await expect(highlightedRow).toContainText('L2: msg2'); |
| 109 | + |
| 110 | + await containerLogsPage.searchPrevButton.click(); |
| 111 | + |
| 112 | + await expect(searchHighlight).toBeVisible(); |
| 113 | + await expect(highlightedRow).toContainText('L1: msg1'); |
| 114 | + |
| 115 | + await containerLogsPage.searchClearButton.click(); |
| 116 | + await expect(containerLogsPage.searchInput).toBeEmpty(); |
| 117 | + |
| 118 | + await containerLogsPage.terminal.click(); |
| 119 | + |
| 120 | + await expect(searchHighlight).not.toBeVisible(); |
| 121 | + }); |
| 122 | + |
| 123 | + test('should handle terminal scrolling', async () => { |
| 124 | + const scrollTestContainerName = `test-scroll-container-${Date.now()}`; |
| 125 | + let scrollTestContainerId: string; |
| 126 | + |
| 127 | + try { |
| 128 | + const output = await tool('docker', 'run', '--detach', '--name', scrollTestContainerName, |
| 129 | + 'alpine', 'sh', '-c', 'for i in $(seq 1 100); do echo "Line $i:"; done; sleep 1'); |
| 130 | + scrollTestContainerId = output.trim(); |
| 131 | + |
| 132 | + const navPage = new NavPage(page); |
| 133 | + const containersPage = await navPage.navigateTo('Containers'); |
| 134 | + |
| 135 | + await page.reload(); |
| 136 | + await containersPage.waitForTableToLoad(); |
| 137 | + |
| 138 | + await containersPage.waitForContainerToAppear(scrollTestContainerId); |
| 139 | + await containersPage.viewContainerLogs(scrollTestContainerId); |
| 140 | + |
| 141 | + await page.waitForURL(`**/containers/logs/${scrollTestContainerId}`, {timeout: 10_000}); |
| 142 | + |
| 143 | + const containerLogsPage = new ContainerLogsPage(page); |
| 144 | + await containerLogsPage.waitForLogsToLoad(); |
| 145 | + |
| 146 | + const terminalRows = containerLogsPage.terminal.locator('.xterm-rows'); |
| 147 | + const lastLine = terminalRows.getByText('Line 100:', { exact: false }); |
| 148 | + const firstLine = terminalRows.getByText('Line 1:', { exact: false }); |
| 149 | + |
| 150 | + await expect(lastLine).toBeVisible(); |
| 151 | + await expect(firstLine).not.toBeVisible(); |
| 152 | + |
| 153 | + await containerLogsPage.scrollToTop(); |
| 154 | + |
| 155 | + await expect(firstLine).toBeVisible(); |
| 156 | + await expect(lastLine).not.toBeVisible(); |
| 157 | + |
| 158 | + await containerLogsPage.scrollToBottom(); |
| 159 | + |
| 160 | + await expect(lastLine).toBeVisible(); |
| 161 | + await expect(firstLine).not.toBeVisible(); |
| 162 | + } finally { |
| 163 | + if (scrollTestContainerId) { |
| 164 | + try { |
| 165 | + await tool('docker', 'rm', '-f', scrollTestContainerId); |
| 166 | + } catch (cleanupError) { |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + }); |
| 171 | + |
| 172 | + test('should output logs if container not exited', async () => { |
| 173 | + const longRunningContainerName = `test-not-exited-logs-${Date.now()}`; |
| 174 | + let longRunningContainerId: string; |
| 175 | + |
| 176 | + try { |
| 177 | + const output = await tool('docker', 'run', '--detach', '--name', longRunningContainerName, |
| 178 | + 'alpine', 'sh', '-c', 'while true; do echo "Log $(date +%s)"; sleep 2; done'); |
| 179 | + longRunningContainerId = output.trim(); |
| 180 | + |
| 181 | + const navPage = new NavPage(page); |
| 182 | + const containersPage = await navPage.navigateTo('Containers'); |
| 183 | + |
| 184 | + await page.reload(); |
| 185 | + await containersPage.waitForTableToLoad(); |
| 186 | + |
| 187 | + await containersPage.waitForContainerToAppear(longRunningContainerId); |
| 188 | + await containersPage.viewContainerLogs(longRunningContainerId); |
| 189 | + |
| 190 | + await page.waitForURL(`**/containers/logs/${longRunningContainerId}`, {timeout: 10000}); |
| 191 | + |
| 192 | + const containerLogsPage = new ContainerLogsPage(page); |
| 193 | + await containerLogsPage.waitForLogsToLoad(); |
| 194 | + |
| 195 | + const locator = containerLogsPage.terminal.locator('.xterm-screen'); |
| 196 | + await expect(locator.getByText(/Log \d+/).nth(1)).toBeVisible(); |
| 197 | + |
| 198 | + await expect(containerLogsPage.terminal).toContainText('Log '); |
| 199 | + |
| 200 | + await tool('docker', 'rm', '-f', longRunningContainerId); |
| 201 | + } finally { |
| 202 | + if (longRunningContainerId) { |
| 203 | + try { |
| 204 | + await tool('docker', 'rm', '-f', longRunningContainerId); |
| 205 | + } catch (cleanupError) { |
| 206 | + } |
| 207 | + } |
| 208 | + } |
| 209 | + }); |
| 210 | +}); |
0 commit comments