mirror of
https://github.com/EKKOLearnAI/hermes-web-ui.git
synced 2026-05-25 13:30:14 +00:00
97b15d6514
* test: add Playwright browser smoke suite * Update playwright.yml --------- Co-authored-by: ekko <152005280+EKKOLearnAI@users.noreply.github.com>
45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
import { mockHermesApi, TEST_ACCESS_KEY } from './fixtures'
|
|
|
|
test('redirects protected routes to the login screen without a token', async ({ page }) => {
|
|
const api = await mockHermesApi(page)
|
|
|
|
await page.goto('/#/hermes/jobs')
|
|
|
|
await expect(page).toHaveURL(/#\/$/)
|
|
await expect(page.getByRole('heading', { name: 'Hermes Web UI' })).toBeVisible()
|
|
await expect(page.getByPlaceholder('Access token')).toBeVisible()
|
|
expect(api.unexpectedRequests).toEqual([])
|
|
})
|
|
|
|
test('rejects an invalid access token without persisting it', async ({ page }) => {
|
|
const api = await mockHermesApi(page, { tokenValidationStatus: 401 })
|
|
|
|
await page.goto('/')
|
|
await page.getByPlaceholder('Access token').fill('bad-token')
|
|
await page.getByRole('button', { name: 'Login' }).click()
|
|
|
|
await expect(page.getByText('Invalid token')).toBeVisible()
|
|
await expect(page).toHaveURL(/#\/$/)
|
|
await expect(page.evaluate(() => window.localStorage.getItem('hermes_api_key'))).resolves.toBeNull()
|
|
expect(api.unexpectedRequests).toEqual([])
|
|
})
|
|
|
|
test('validates token login through the BFF before entering the app', async ({ page }) => {
|
|
const api = await mockHermesApi(page)
|
|
|
|
await page.goto('/')
|
|
await page.getByPlaceholder('Access token').fill(TEST_ACCESS_KEY)
|
|
await page.getByRole('button', { name: 'Login' }).click()
|
|
|
|
await expect(page).toHaveURL(/#\/hermes\/chat$/)
|
|
await expect(page.evaluate(() => window.localStorage.getItem('hermes_api_key'))).resolves.toBe(TEST_ACCESS_KEY)
|
|
|
|
const validationRequest = api.requests.find((request) => (
|
|
request.pathname === '/api/hermes/sessions' &&
|
|
request.headers.authorization === `Bearer ${TEST_ACCESS_KEY}`
|
|
))
|
|
expect(validationRequest).toBeTruthy()
|
|
expect(api.unexpectedRequests).toEqual([])
|
|
})
|