|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | +import { client } from '$lib/services/manager/client.gen' |
| 3 | +import { deletePipeline, putPipeline } from '$lib/services/pipelineManager' |
| 4 | + |
| 5 | +const API_ORIGIN = (process.env.PLAYWRIGHT_API_ORIGIN ?? 'http://localhost:8080').replace(/\/$/, '') |
| 6 | +client.setConfig({ baseUrl: API_ORIGIN }) |
| 7 | + |
| 8 | +const PREFIX = `test-search-${Date.now()}` |
| 9 | +const PIPELINES = [`${PREFIX}-alpha`, `${PREFIX}-beta`, `${PREFIX}-gamma`] as const |
| 10 | + |
| 11 | +async function cleanupPipelines() { |
| 12 | + for (const name of PIPELINES) { |
| 13 | + try { |
| 14 | + await deletePipeline(name) |
| 15 | + } catch { |
| 16 | + // Pipeline may not exist |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +/** Navigate to the home page and wait until all test pipelines have compiled and are ready to start. */ |
| 22 | +async function gotoAndWaitForPipelines(page: import('@playwright/test').Page) { |
| 23 | + await page.goto('/') |
| 24 | + // Wait for every test pipeline to reach "Ready To Start" (Stopped) status. |
| 25 | + // Cannot use networkidle because the pipeline list polls every 2 s. |
| 26 | + for (const name of PIPELINES) { |
| 27 | + const row = page.getByRole('row').filter({ has: page.getByRole('link', { name }) }) |
| 28 | + await expect(row.getByText('Ready To Start')).toBeVisible({ timeout: 120_000 }) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +test.describe('Pipeline search', () => { |
| 33 | + test.setTimeout(180_000) |
| 34 | + |
| 35 | + test.beforeAll(async ({}, testInfo) => { |
| 36 | + testInfo.setTimeout(120_000) |
| 37 | + await cleanupPipelines() |
| 38 | + for (const name of PIPELINES) { |
| 39 | + await putPipeline(name, { |
| 40 | + name, |
| 41 | + description: `E2E search test pipeline: ${name}`, |
| 42 | + program_code: 'create view test as (select 1)' |
| 43 | + }) |
| 44 | + } |
| 45 | + }) |
| 46 | + |
| 47 | + test.afterAll(async ({}, testInfo) => { |
| 48 | + testInfo.setTimeout(60_000) |
| 49 | + await cleanupPipelines() |
| 50 | + }) |
| 51 | + |
| 52 | + test('filters pipelines by name substring', async ({ page }) => { |
| 53 | + await gotoAndWaitForPipelines(page) |
| 54 | + |
| 55 | + const searchInput = page.getByTestId('input-pipeline-search') |
| 56 | + await searchInput.fill('alpha') |
| 57 | + |
| 58 | + await expect(page.getByRole('link', { name: `${PREFIX}-alpha` })).toBeVisible() |
| 59 | + await expect(page.getByRole('link', { name: `${PREFIX}-beta` })).not.toBeVisible() |
| 60 | + await expect(page.getByRole('link', { name: `${PREFIX}-gamma` })).not.toBeVisible() |
| 61 | + }) |
| 62 | + |
| 63 | + test('search is case-insensitive', async ({ page }) => { |
| 64 | + await gotoAndWaitForPipelines(page) |
| 65 | + |
| 66 | + const searchInput = page.getByTestId('input-pipeline-search') |
| 67 | + await searchInput.fill(PREFIX.toUpperCase()) |
| 68 | + |
| 69 | + // All three pipelines share the prefix, so all should be visible |
| 70 | + for (const name of PIPELINES) { |
| 71 | + await expect(page.getByRole('link', { name })).toBeVisible() |
| 72 | + } |
| 73 | + }) |
| 74 | + |
| 75 | + test('shows empty state when no pipelines match', async ({ page }) => { |
| 76 | + await gotoAndWaitForPipelines(page) |
| 77 | + |
| 78 | + const searchInput = page.getByTestId('input-pipeline-search') |
| 79 | + await searchInput.fill('nonexistent-pipeline-xyz-999') |
| 80 | + |
| 81 | + await expect(page.getByText('No pipelines found')).toBeVisible() |
| 82 | + }) |
| 83 | + |
| 84 | + test('clearing search shows all pipelines again', async ({ page }) => { |
| 85 | + await gotoAndWaitForPipelines(page) |
| 86 | + |
| 87 | + const searchInput = page.getByTestId('input-pipeline-search') |
| 88 | + await searchInput.fill('alpha') |
| 89 | + await expect(page.getByRole('link', { name: `${PREFIX}-beta` })).not.toBeVisible() |
| 90 | + |
| 91 | + await searchInput.clear() |
| 92 | + |
| 93 | + for (const name of PIPELINES) { |
| 94 | + await expect(page.getByRole('link', { name })).toBeVisible() |
| 95 | + } |
| 96 | + }) |
| 97 | + |
| 98 | + test('search works together with status filter', async ({ page }) => { |
| 99 | + await gotoAndWaitForPipelines(page) |
| 100 | + |
| 101 | + // All test pipelines should be in "Stopped" (Ready To Start) status |
| 102 | + const statusSelect = page.getByTestId('select-pipeline-status') |
| 103 | + await statusSelect.selectOption('Ready To Start') |
| 104 | + |
| 105 | + const searchInput = page.getByTestId('input-pipeline-search') |
| 106 | + await searchInput.fill('beta') |
| 107 | + |
| 108 | + await expect(page.getByRole('link', { name: `${PREFIX}-beta` })).toBeVisible() |
| 109 | + await expect(page.getByRole('link', { name: `${PREFIX}-alpha` })).not.toBeVisible() |
| 110 | + |
| 111 | + // Switching to a non-matching status should hide everything |
| 112 | + await statusSelect.selectOption('Running') |
| 113 | + await expect(page.getByRole('link', { name: `${PREFIX}-beta` })).not.toBeVisible() |
| 114 | + }) |
| 115 | +}) |
0 commit comments