Skip to content

Commit

Permalink
feat(tests): move e2e tests for consultation-portal to their app
Browse files Browse the repository at this point in the history
  • Loading branch information
svanaeinars committed Nov 25, 2024
1 parent 6cf5d56 commit e7d5e93
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 7 deletions.
18 changes: 18 additions & 0 deletions apps/consultation-portal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ Login here https://island-is.awsapps.com/start#/ (Contact devops if you need acc
Copy env variables as instructed [here](https://docs.devland.is/technical-overview/devops/dockerizing#troubleshooting) (image arrows 1,2,3)
Paste env variables into terminal

## E2E Testing

### Quick Start

To run the E2E tests for the `consultation-portal` app:

```bash
# Install dependencies
yarn install && yarn codegen

# Start the server
yarn nx e2e consultation-portal
```

### More Resources

For further details, refer to the [E2E Testing Library README](../../libs/testing/e2e/README.md).

## Project owner

- [Stjórnarráðið](https://www.stjornarradid.is)
Expand Down
139 changes: 139 additions & 0 deletions apps/consultation-portal/e2e/consultation-portal-authenticated.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import {
BrowserContext,
expect,
test,
icelandicAndNoPopupUrl,
urls,
session,
} from '@island.is/testing/e2e'

test.describe('Consultation portal authenticated', { tag: '@fast' }, () => {
let context: BrowserContext
test.use({ baseURL: urls.islandisBaseUrl })

test.beforeAll(async ({ browser }) => {
context = await session({
browser: browser,
storageState: 'consultation-auth.json',
idsLoginOn: {
nextAuth: { nextAuthRoot: `${urls.islandisBaseUrl}/samradsgatt` },
},
phoneNumber: '0102989',
homeUrl: `${urls.islandisBaseUrl}/samradsgatt`,
authTrigger: async (page) => {
await page.goto('/samradsgatt')
await page.getByTestId('menu-login-btn').click()
return `${urls.islandisBaseUrl}/samradsgatt`
},
})
})

test.afterAll(async () => {
if (context) {
await context.close()
}
})

test('logged in user should be shown instead of login', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await expect(
page.getByRole('button', { name: 'Gervimaður Ameríku' }),
).toBeVisible()
await expect(page.getByTestId('menu-login-btn')).not.toBeVisible()

await page.close()
})

test('subscriptions page should show logged in state', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByTestId('subscriptions-btn').click()
await expect(page.getByTestId('subscriptions-title')).toBeVisible()
await expect(page.getByTestId('action-card')).toBeVisible()
await expect(
page.getByRole('button', {
name: 'Skrá mig inn',
}),
).not.toBeVisible()

await page.close()
})

test('my subscriptions page should show logged in state', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt/minaraskriftir'))
await expect(page.getByTestId('subscriptions-title')).toBeVisible()
await expect(page.getByTestId('action-card')).not.toBeVisible()

await page.close()
})

test('advices page should show logged in state', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.goto('/umsagnir')
await expect(page.getByTestId('actionCard')).not.toBeVisible()

await page.close()
})

test('logout button should be visible', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByRole('button', { name: 'Gervimaður Ameríku' }).click()
await expect(page.getByRole('button', { name: 'Útskrá' })).toBeVisible()

await page.close()
})

// Additional tests
test('user should be able to navigate to profile page', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByRole('button', { name: 'Gervimaður Ameríku' }).click()
await page.getByRole('link', { name: 'Mínar síður' }).click()
await expect(page.getByTestId('profile-page')).toBeVisible()

await page.close()
})

test('user should be able to update profile information', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt/minar-sidur'))

await page.getByTestId('edit-profile-btn').click()
await page.fill('input[name="name"]', 'Updated Name')
await page.getByTestId('save-profile-btn').click()
await expect(page.getByTestId('profile-name')).toHaveText('Updated Name')

await page.close()
})

test('user should be able to view notifications', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByRole('button', { name: 'Gervimaður Ameríku' }).click()
await page.getByRole('link', { name: 'Tilkynningar' }).click()
await expect(page.getByTestId('notifications-page')).toBeVisible()

await page.close()
})

test('user should be able to log out', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByRole('button', { name: 'Gervimaður Ameríku' }).click()
await page.getByRole('button', { name: 'Útskrá' }).click()
await expect(page.getByTestId('menu-login-btn')).toBeVisible()

await page.close()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {
BrowserContext,
expect,
test,
icelandicAndNoPopupUrl,
urls,
session,
} from '@island.is/testing/e2e'

test.describe('Consultation portal unathenticated', { tag: '@fast' }, () => {
let context: BrowserContext
const authLink = new RegExp(`^${urls.authUrl}`)

test.use({ baseURL: `${urls.islandisBaseUrl}/samradsgatt` })

test.beforeAll(async ({ browser, baseURL }) => {
context = await session({
browser: browser,
storageState: 'consultation-no-auth.json',
idsLoginOn: false,
homeUrl: baseURL,
})
})
test.afterAll(async () => {
await context.close()
})

test('nav links on front page should be visible', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await expect(page.getByTestId('all-cases-btn')).toBeVisible()
await expect(page.getByTestId('subscriptions-btn')).toBeVisible()
await expect(page.getByTestId('advices-btn')).toBeVisible()
await expect(page.getByTestId('menu-login-btn')).toBeVisible()

await page.close()
})

test('subscriptions page should show logged out state', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByTestId('subscriptions-btn').click()
await expect(page.getByTestId('subscriptions-title')).toBeVisible()
await expect(page.getByTestId('tab-content')).not.toBeVisible()
await expect(page.getByTestId('action-card')).toBeVisible()
page
.getByRole('button', {
name: 'Skrá mig inn',
})
.click()
await page.waitForURL(authLink)

await page.close()
})

test('my subscriptions page should be empty and redirect user to login', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByTestId('subscriptions-btn').click()
await expect(page.getByTestId('tab-content')).not.toBeVisible()

page
.getByRole('link', {
name: 'Hægt er að afskrá sig hér',
})
.click()
await page.waitForURL(`**/minaraskriftir`)
await expect(page.getByTestId('tab-content')).not.toBeVisible()
await page.waitForURL(authLink)

await page.close()
})

test('advices page should show logged out state', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByTestId('advices-btn').click()
await expect(page.getByTestId('action-card')).toBeVisible()
page
.getByRole('button', {
name: 'Skrá mig inn',
})
.click()
await page.waitForURL(authLink)

await page.close()
})

test('login button should redirect to login', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

page.getByTestId('menu-login-btn').click()
await page.waitForURL(authLink)

await page.close()
})

test('card should show up on frontpage and show case when clicked', async () => {
const page = await context.newPage()
await page.goto(icelandicAndNoPopupUrl('/samradsgatt'))

await page.getByTestId('front-page-card').first().click()
await expect(page.getByTestId('short-description')).toBeVisible()

await page.close()
})
})
1 change: 1 addition & 0 deletions apps/consultation-portal/infra/samradsgatt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const serviceSetup = (services: {
prod: 'innskra.island.is',
},
NEXTAUTH_URL: {
local: 'http://localhost:4200/samradsgatt/api/auth',
dev: 'https://beta.dev01.devland.is/samradsgatt/api/auth',
staging: 'https://beta.staging01.devland.is/samradsgatt/api/auth',
prod: 'https://island.is/samradsgatt/api/auth',
Expand Down
9 changes: 9 additions & 0 deletions apps/consultation-portal/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createPlaywrightConfig } from '@island.is/testing/e2e'

const consultationPortalConfig = createPlaywrightConfig({
webServerUrl: 'http://localhost:4200/',
app: 'consultation-portal',
dependencies: ['api'],
})

export default consultationPortalConfig
6 changes: 6 additions & 0 deletions apps/consultation-portal/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
"jestConfig": "apps/consultation-portal/jest.config.ts"
}
},
"e2e": {
"executor": "@nx/playwright:playwright",
"options": {
"config": "{projectRoot}/playwright.config.ts"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
Expand Down
6 changes: 0 additions & 6 deletions apps/consultation-portal/proxy.config.json

This file was deleted.

8 changes: 8 additions & 0 deletions apps/consultation-portal/proxy.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const proxyConfig = {
'/api/graphql': {
target: process.env.API_URL ?? 'http://localhost:4444',
secure: false,
},
}

export default proxyConfig
3 changes: 2 additions & 1 deletion apps/consultation-portal/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bootstrap } from '@island.is/infra-next-server'
import proxyConfig from './proxy.config.json'
import proxyConfig from './proxy.config'

bootstrap({
name: 'consultation-portal',
appDir: 'apps/consultation-portal',
Expand Down

0 comments on commit e7d5e93

Please sign in to comment.