-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tests): move e2e tests for consultation-portal to their app #17008
base: main
Are you sure you want to change the base?
Changes from 5 commits
e7d5e93
b76ada4
ad64565
743692e
7b8102c
62a7add
cec0ca0
348e044
ff2adf2
89c648e
00b6211
c72861e
2c9e5c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
**/*.log | ||
**/tmp/ | ||
**/temp/ | ||
**/.next/ | ||
|
||
# Outputs | ||
**/dist/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
ARG NODE_IMAGE_TAG=20.15.0-alpine3.20 | ||
|
||
# Stage 1: Install dependencies | ||
FROM node:${NODE_IMAGE_TAG} AS dependencies | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Install Python3 and build tools | ||
RUN apk add --no-cache python3 py3-pip make g++ && ln -sf /usr/bin/python3 /usr/bin/python | ||
|
||
# Copy only package management files | ||
COPY package.json yarn.lock ./ | ||
COPY .yarn/ .yarn | ||
COPY .yarnrc.yml .yarnrc.yml | ||
COPY ./apps/native/app/package.json ./apps/native/app/package.json | ||
|
||
# Install dependencies | ||
RUN --mount=type=cache,target=/app/.yarn/cache \ | ||
yarn install --immutable && yarn cache clean | ||
|
||
# Stage 2: Final runtime image | ||
FROM node:${NODE_IMAGE_TAG} | ||
|
||
# Install Python (runtime requirement if needed) | ||
RUN apk add --no-cache python3 py3-pip && ln -sf /usr/bin/python3 /usr/bin/python | ||
|
||
# Enable Corepack and Yarn 3.2.3 | ||
RUN corepack enable && corepack prepare yarn@3.2.3 --activate | ||
|
||
# Set working directory | ||
WORKDIR /app | ||
|
||
# Copy from dependencies stage | ||
COPY --from=dependencies /app/node_modules ./node_modules | ||
COPY --from=dependencies /app/yarn.lock ./yarn.lock | ||
COPY --from=dependencies /app/.yarn/ ./.yarn | ||
COPY --from=dependencies /app/.yarnrc.yml ./.yarnrc.yml | ||
|
||
# Copy source code and necessary configuration files | ||
COPY ./apps ./apps | ||
COPY ./libs ./libs | ||
COPY ./infra ./infra | ||
COPY ./tools ./tools | ||
COPY ./tsconfig.base.json ./ | ||
COPY ./tsconfig.shared.json ./ | ||
COPY ./package.json ./ | ||
|
||
# Verify Yarn version in runtime container | ||
RUN yarn --version | ||
|
||
# Default command to run the app | ||
CMD ["yarn", "nx", "serve"] | ||
|
||
# ARG NODE_IMAGE_TAG=20.15.0-alpine3.20 | ||
# FROM node:${NODE_IMAGE_TAG} AS build | ||
|
||
# WORKDIR /app | ||
|
||
# # Install build dependencies | ||
# RUN apk add --no-cache \ | ||
# python3 \ | ||
# py3-pip \ | ||
# make \ | ||
# g++ | ||
|
||
# # Set Python symlink | ||
# RUN ln -sf /usr/bin/python3 /usr/bin/python | ||
|
||
# # Install dependencies | ||
# COPY package.json yarn.lock ./ | ||
# COPY .yarn/ .yarn | ||
# COPY .yarnrc.yml .yarnrc.yml | ||
# COPY ./apps/native/app/package.json ./apps/native/app/package.json | ||
|
||
# # Run yarn install | ||
# RUN --mount=type=cache,target=/app/.yarn/cache \ | ||
# yarn install --immutable | ||
|
||
# # Copy source code | ||
# COPY . . | ||
|
||
# # Verify installation | ||
# RUN yarn nx --version | ||
|
||
# # Set default entrypoint | ||
# CMD ["yarn", "nx"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
``` | ||
Comment on lines
+74
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance the Quick Start guide with additional setup details. The current instructions might be insufficient for first-time users. Consider adding:
Here's a suggested enhancement: ### Quick Start
+Prerequisites:
+- Ensure you have the required environment variables (see Development section above)
+- The API should be running locally (follow steps 1-5 in the Development section)
+
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 +These tests verify both authenticated and unauthenticated user flows in the 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) | ||
|
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() | ||
} | ||
}) | ||
Comment on lines
+14
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and avoid hard-coded test data The setup hooks are functional but could be improved in several areas:
authTrigger: async (page) => {
try {
await page.goto('/samradsgatt')
await page.getByTestId('menu-login-btn').click()
return `${urls.islandisBaseUrl}/samradsgatt`
} catch (error) {
console.error('Auth trigger failed:', error)
throw error
}
}
// test-config.ts
export const TEST_DATA = {
phoneNumber: '0102989',
storageState: 'consultation-auth.json',
// ... other test constants
}
|
||
|
||
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() | ||
}) | ||
}) | ||
Comment on lines
+1
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the shell script results, I can now provide a final response since I have sufficient information about the test coverage across components. Test coverage improvements needed for critical user flows The current E2E test suite covers basic authenticated flows but lacks coverage for several critical components and scenarios:
Suggested test additions:
🔗 Analysis chainVerify test coverage for critical user flows The test suite covers essential authenticated user flows, but consider adding tests for:
🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check for missing test coverage in related components
rg "export|interface|type" apps/consultation-portal/components/ -A 2 | \
while IFS= read -r line; do
if [[ $line =~ "export" ]]; then
component=$(echo "$line" | awk '{print $3}')
echo "Checking test coverage for: $component"
rg "$component" apps/consultation-portal/e2e/ -c || echo "No tests found"
fi
done
Length of output: 63773 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add security best practices
Consider enhancing the security of the final image: