Skip to content

Commit

Permalink
Small test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
svanaeinars committed Nov 15, 2024
1 parent af54dcc commit 1226759
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 46 deletions.
13 changes: 0 additions & 13 deletions apps/web/e2e/smoke/homepage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ test.describe('Front page', () => {
})

test(`should navigate to featured link @lang:is`, async () => {
if (!context) {
throw new Error('Context is not initialized')
}
test.slow()
const page = await createPageAndNavigate(context, '/')
const featuredLinks = page.locator('[data-testid="featured-link"]')
Expand All @@ -104,9 +101,6 @@ test.describe('Front page', () => {
})

test(`should navigate to featured link @lang:en`, async () => {
if (!context) {
throw new Error('Context is not initialized')
}
test.slow()
const page = await createPageAndNavigate(context, '/en')
const featuredLinks = page.locator('[data-testid="featured-link"]')
Expand All @@ -131,9 +125,6 @@ test.describe('Front page', () => {
})

test(`should have link on life events pages to navigate back to the main page @lang:is`, async () => {
if (!context) {
throw new Error('Context is not initialized')
}
test.slow()
const page = await createPageAndNavigate(context, '/')
const lifeEventsCards = page.locator('[data-testid="lifeevent-card"]')
Expand All @@ -147,7 +138,6 @@ test.describe('Front page', () => {
await lifeEventPage.goto(url)
await lifeEventPage.locator('[data-testid="link-back-home"]').click()
}
await lifeEventPage.locator('[data-testid="link-back-home"]').click()
await expect(
lifeEventPage.locator('data-testid=home-heading'),
).toBeVisible()
Expand All @@ -157,9 +147,6 @@ test.describe('Front page', () => {
})

test(`should have link on life events pages to navigate back to the main page @lang:en`, async () => {
if (!context) {
throw new Error('Context is not initialized')
}
test.slow()
const page = await createPageAndNavigate(context, '/en')
const lifeEventsCards = page.locator('[data-testid="lifeevent-card"]')
Expand Down
4 changes: 2 additions & 2 deletions apps/web/e2e/smoke/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test.describe('Search feature', () => {
test('has expected sections', async () => {
const testPhrase = 'umsókn'
const page = await context.newPage()
await page.goto('/')
await page.goto('/', { waitUntil: 'networkidle' })
await page
.getByRole('textbox', { name: 'Leitaðu á Ísland.is' })
.fill(testPhrase)
Expand All @@ -41,7 +41,7 @@ test.describe('Search feature', () => {

test('should have no search results for long bogus search words', async () => {
const page = await context.newPage()
await page.goto('/')
await page.goto('/', { waitUntil: 'networkidle' })
await page
.getByRole('textbox', { name: 'Leitaðu á Ísland.is' })
.fill('abcdefhijklmnopqrstuvwxyz1234567890')
Expand Down
62 changes: 31 additions & 31 deletions apps/web/e2e/smoke/sites-of-institutions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type GetByRoleParameters = Parameters<GetByRole>
type Orgs = {
organisationName: string
organisationHome?: string
enabled?: boolean
skip?: boolean
target?: { role: GetByRoleParameters[0]; options?: GetByRoleParameters[1] }
}
const orgs: Orgs[] = [
Expand All @@ -27,7 +27,7 @@ const orgs: Orgs[] = [
{ organisationName: 'Sjúkratryggingar', target: { role: 'link' } },
{ organisationName: 'Ríkislögmaður' },
{ organisationName: 'Landskjörstjórn', target: { role: 'link' } },
{ organisationName: 'Opinber nýsköpun', enabled: true },
{ organisationName: 'Opinber nýsköpun', skip: true },
{ organisationName: 'Sýslumenn' },
{ organisationName: 'Fjársýslan' },
{
Expand All @@ -43,45 +43,45 @@ const orgs: Orgs[] = [

test.describe('Sites of institutions', () => {
let context: BrowserContext

test.beforeAll(async ({ browser }) => {
context = await session({
browser,
idsLoginOn: false,
homeUrl: '/s',
})
})

test.afterAll(async () => {
await context.close()
})
orgs.forEach(
({
organisationName,
organisationHome = `/${slugify(organisationName, { lower: true })}`,
target,
skip,
}) => {
test(organisationName, async () => {
if (skip) return
const page = await context.newPage()
const url = `/s${organisationHome}`

const response = await page.goto(url, { timeout: 30000 })
expect(response?.ok()).toBe(true)

for (const {
organisationName,
organisationHome = `/${slugify(organisationName, { lower: true })}`,
target,
enabled,
} of orgs) {
test(organisationName, async ({ browser }) => {
if (enabled) return
const pageContext = await session({
browser,
idsLoginOn: false,
homeUrl: '/s',
// Verify we landed on the correct URL
expect(page.url()).toContain(url)

await expect(
page
.getByRole(target?.role ?? 'heading', {
...{ name: organisationName },
...target?.options,
})
.first(),
).toBeVisible()

await page.close()
})
const page = await pageContext.newPage()
const url = `/s${organisationHome}`
await page.goto(url)
await expect(
page
.getByRole(target?.role ?? 'heading', {
name: organisationName,
...target?.options,
})
.first(),
).toBeVisible()
await page.close()
await pageContext.close()
})
}
},
)
})

0 comments on commit 1226759

Please sign in to comment.