|
| 1 | +// Copyright The Linux Foundation and each contributor to LFX. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import { expect, Page, test } from '@playwright/test'; |
| 5 | + |
| 6 | +const ORG_PROJECTS_URL = '/org/projects'; |
| 7 | +const DATA_LOAD_TIMEOUT = 30_000; |
| 8 | +const MOCK_ACCOUNT_ID = '0014100000Te2QjAAJ'; |
| 9 | +const MOCK_UID = '4c46585f-878c-8285-b2e9-2dbfc38ddd9b'; |
| 10 | + |
| 11 | +test.setTimeout(120_000); |
| 12 | + |
| 13 | +function skipWhenAuthMissing(page: Page): void { |
| 14 | + try { |
| 15 | + const { hostname } = new URL(page.url()); |
| 16 | + if (hostname === 'auth0.com' || hostname.endsWith('.auth0.com')) { |
| 17 | + test.skip(true, 'TEST_USERNAME / TEST_PASSWORD not configured — see global-setup.ts'); |
| 18 | + } |
| 19 | + } catch { |
| 20 | + // Let malformed URLs fail naturally. |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +// The Projects page renders from a client-side demo-data service (no projects API yet), so the only |
| 25 | +// stub needed is the personas endpoint to give the org context an account to select. |
| 26 | +async function stubOrgContext(page: Page): Promise<void> { |
| 27 | + await page.route('**/api/user/personas*', (route) => |
| 28 | + route.fulfill({ |
| 29 | + status: 200, |
| 30 | + contentType: 'application/json', |
| 31 | + body: JSON.stringify({ |
| 32 | + personas: ['contributor'], |
| 33 | + personaProjects: {}, |
| 34 | + projects: [], |
| 35 | + organizations: [ |
| 36 | + { |
| 37 | + accountId: MOCK_ACCOUNT_ID, |
| 38 | + accountName: 'Red Hat LLC', |
| 39 | + accountSlug: 'red-hat-llc', |
| 40 | + membershipTier: '', |
| 41 | + uid: MOCK_UID, |
| 42 | + }, |
| 43 | + ], |
| 44 | + isRootWriter: false, |
| 45 | + }), |
| 46 | + }) |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +async function gotoOrgProjectsPage(page: Page): Promise<void> { |
| 51 | + await stubOrgContext(page); |
| 52 | + await page.goto('/', { waitUntil: 'domcontentloaded' }); |
| 53 | + skipWhenAuthMissing(page); |
| 54 | + await page.reload({ waitUntil: 'domcontentloaded' }); |
| 55 | + await page.goto(ORG_PROJECTS_URL, { waitUntil: 'domcontentloaded' }); |
| 56 | + skipWhenAuthMissing(page); |
| 57 | + await expect(page).not.toHaveURL(/auth0\.com/); |
| 58 | + |
| 59 | + if (!page.url().includes('/org/projects')) { |
| 60 | + test.skip(true, 'org-lens-enabled flag appears off — /org/projects redirected away'); |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +test.describe('Org Projects', () => { |
| 65 | + test('renders the projects table with demo data', async ({ page }) => { |
| 66 | + await gotoOrgProjectsPage(page); |
| 67 | + |
| 68 | + await expect(page.getByTestId('org-projects-page')).toBeVisible({ timeout: DATA_LOAD_TIMEOUT }); |
| 69 | + await expect(page.getByTestId('org-projects-table')).toBeVisible(); |
| 70 | + // Demo dataset always includes Kubernetes (Leading / Leading). |
| 71 | + const kubernetesRow = page.getByTestId('org-projects-row-kubernetes'); |
| 72 | + await expect(kubernetesRow).toBeVisible(); |
| 73 | + await expect(kubernetesRow.getByText('Leading').first()).toBeVisible(); |
| 74 | + await expect(page.getByTestId('org-projects-export-csv')).toBeVisible(); |
| 75 | + }); |
| 76 | + |
| 77 | + test('sorts by project name from the column header (persists to the URL)', async ({ page }) => { |
| 78 | + await gotoOrgProjectsPage(page); |
| 79 | + await expect(page.getByTestId('org-projects-table')).toBeVisible({ timeout: DATA_LOAD_TIMEOUT }); |
| 80 | + |
| 81 | + await page.getByTestId('org-projects-sort-name').click(); |
| 82 | + await expect(page).toHaveURL(/[?&]sort=name/); |
| 83 | + }); |
| 84 | + |
| 85 | + test('opens the workspace dropdown and the add-workspace dialog', async ({ page }) => { |
| 86 | + await gotoOrgProjectsPage(page); |
| 87 | + await expect(page.getByTestId('org-projects-page')).toBeVisible({ timeout: DATA_LOAD_TIMEOUT }); |
| 88 | + |
| 89 | + await page.getByTestId('org-projects-workspace-trigger').click(); |
| 90 | + // Each company is seeded with only the default workspace. |
| 91 | + await expect(page.getByTestId('org-projects-workspace-option-all-activities')).toBeVisible(); |
| 92 | + |
| 93 | + await page.getByTestId('org-projects-add-workspace').click(); |
| 94 | + await expect(page.getByTestId('org-projects-workspace-dialog')).toBeVisible(); |
| 95 | + await expect(page.getByTestId('org-projects-workspace-save')).toBeVisible(); |
| 96 | + }); |
| 97 | + |
| 98 | + test('reveals the LFX Insights health detail on hover', async ({ page }) => { |
| 99 | + await gotoOrgProjectsPage(page); |
| 100 | + await expect(page.getByTestId('org-projects-row-kubernetes')).toBeVisible({ timeout: DATA_LOAD_TIMEOUT }); |
| 101 | + |
| 102 | + await page.getByTestId('org-projects-health-kubernetes').hover(); |
| 103 | + const popover = page.getByTestId('org-projects-health-popover'); |
| 104 | + await expect(popover).toBeVisible(); |
| 105 | + await expect(popover.getByRole('link', { name: /LFX Insights/ })).toBeVisible(); |
| 106 | + }); |
| 107 | +}); |
0 commit comments