|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -import { test, expect } from '@playwright/test'; |
| 16 | +import { test, expect, type Page } from '@playwright/test'; |
| 17 | + |
| 18 | +// Extra time for Backstage to poll popup.closed and update React state. |
| 19 | +const AUTH_ERROR_TIMEOUT_MS = 15_000; |
| 20 | +// Tolerance for the ~214-pixel layout shift caused by the error text |
| 21 | +// inserting into the card and nudging the Sign In button by ~1 px. |
| 22 | +const AUTH_ERROR_MAX_DIFF_PIXELS = 300; |
| 23 | + |
| 24 | +/** Sign in as a Guest (accepts the backend-unavailable fallback dialog). */ |
| 25 | +async function signInAsGuest(page: Page) { |
| 26 | + page.on('dialog', dialog => dialog.accept()); |
| 27 | + await page.goto('/'); |
| 28 | + await page.getByRole('button', { name: 'Enter' }).click(); |
| 29 | +} |
17 | 30 |
|
18 | 31 | test('App should render the sign-in screen', async ({ page }) => { |
19 | 32 | await page.goto('/'); |
20 | 33 |
|
21 | 34 | await expect(page).toHaveTitle(/RaBe Backstage/); |
22 | 35 |
|
23 | | - const enterButton = page.getByRole('button', { name: 'Enter' }); |
24 | | - await expect(enterButton).toBeVisible(); |
| 36 | + // OIDC sign-in button is always visible. |
| 37 | + await expect(page.getByRole('button', { name: 'Sign In' })).toBeVisible(); |
| 38 | + // Guest sign-in button is visible in dev / CI (auth.environment = development). |
| 39 | + await expect(page.getByRole('button', { name: 'Enter' })).toBeVisible(); |
25 | 40 |
|
26 | 41 | await expect(page).toHaveScreenshot('login-page.png'); |
27 | 42 | }); |
28 | 43 |
|
29 | | -test('Guest sign-in should navigate to the main application', async ({ page }) => { |
30 | | - // Accept any browser confirm dialogs (e.g. fallback to legacy guest token when the auth backend is unavailable) |
31 | | - page.on('dialog', dialog => dialog.accept()); |
| 44 | +test('Sign-in should show an auth error when no IdP is available', async ({ |
| 45 | + page, |
| 46 | + context, |
| 47 | +}) => { |
| 48 | + // Register handler before navigating so auto sign-in popups are also closed. |
| 49 | + context.on('page', async popup => { |
| 50 | + await popup.close(); |
| 51 | + }); |
32 | 52 |
|
33 | 53 | await page.goto('/'); |
34 | 54 |
|
35 | | - const enterButton = page.getByRole('button', { name: 'Enter' }); |
36 | | - await expect(enterButton).toBeVisible(); |
| 55 | + const signInButton = page.getByRole('button', { name: 'Sign In' }); |
| 56 | + await expect(signInButton).toBeVisible(); |
| 57 | + |
| 58 | + // Wait for the initial auto sign-in attempt to settle before clicking. |
| 59 | + await page.waitForLoadState('networkidle'); |
| 60 | + |
| 61 | + await signInButton.click(); |
| 62 | + |
| 63 | + // Backstage polls popup.closed on an interval, so allow extra time. |
| 64 | + await expect(page.getByText('Login failed, popup was closed')).toBeVisible({ |
| 65 | + timeout: AUTH_ERROR_TIMEOUT_MS, |
| 66 | + }); |
| 67 | + |
| 68 | + // Wait for the layout to settle after the error text causes a reflow. |
| 69 | + await expect(signInButton).toBeVisible(); |
| 70 | + |
| 71 | + await expect(page).toHaveScreenshot('login-auth-error.png', { |
| 72 | + maxDiffPixels: AUTH_ERROR_MAX_DIFF_PIXELS, |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +test('Guest sign-in should load the catalog page', async ({ page }) => { |
| 77 | + await signInAsGuest(page); |
| 78 | + |
| 79 | + await expect( |
| 80 | + page.getByRole('heading', { name: 'Radio Bern RaBe Catalog' }), |
| 81 | + ).toBeVisible(); |
| 82 | + |
| 83 | + await expect(page).toHaveScreenshot('catalog-page.png'); |
| 84 | +}); |
| 85 | + |
| 86 | +test('Settings page should be accessible after sign-in', async ({ page }) => { |
| 87 | + await signInAsGuest(page); |
| 88 | + |
| 89 | + await page.getByRole('link', { name: 'Settings' }).click(); |
37 | 90 |
|
38 | | - await enterButton.click(); |
| 91 | + await expect( |
| 92 | + page.getByRole('heading', { name: 'Settings' }), |
| 93 | + ).toBeVisible(); |
39 | 94 |
|
40 | | - // After sign-in, the catalog heading should be visible |
41 | | - await expect(page.getByRole('heading', { name: 'Radio Bern RaBe Catalog' })).toBeVisible(); |
| 95 | + await expect(page).toHaveScreenshot('settings-page.png'); |
42 | 96 | }); |
0 commit comments