From 818f8cc4214199acc88d231217734747bfd6b4d0 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 26 Apr 2024 18:46:10 +0100 Subject: [PATCH] Update E2E workflow to use environment variables from config.env in test.e2e.yaml --- E2E/Config.ts | 6 +++ E2E/Tests/Accounts/Login.spec.ts | 48 +++++++++++++++++++ E2E/Tests/StatusPage/Basic.spec.ts | 18 +++++++ .../oneuptime/templates/cleanup-cron-job.yaml | 2 +- .../Public/oneuptime/templates/e2e-cron.yml | 4 +- HelmChart/Public/oneuptime/values.yaml | 2 + StatusPage/src/Pages/Overview/Overview.tsx | 2 +- config.example.env | 3 +- docker-compose.base.yml | 4 ++ 9 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 E2E/Tests/StatusPage/Basic.spec.ts diff --git a/E2E/Config.ts b/E2E/Config.ts index ce5abf26c5..230e0a7355 100644 --- a/E2E/Config.ts +++ b/E2E/Config.ts @@ -20,3 +20,9 @@ export const REGISTERED_USER_EMAIL: string = env('E2E_TEST_REGISTERED_USER_EMAIL') || ''; export const REGISTERED_USER_PASSWORD: string = env('E2E_TEST_REGISTERED_USER_PASSWORD') || ''; + +export const STATUS_PAGE_URL: URL | null = env( + 'E2E_TEST_REGISTERED_USER_PASSWORD' +) + ? URL.fromString(env('E2E_TEST_REGISTERED_USER_PASSWORD')) + : null; diff --git a/E2E/Tests/Accounts/Login.spec.ts b/E2E/Tests/Accounts/Login.spec.ts index e69de29bb2..87242049f3 100644 --- a/E2E/Tests/Accounts/Login.spec.ts +++ b/E2E/Tests/Accounts/Login.spec.ts @@ -0,0 +1,48 @@ +import { test, expect, Page } from '@playwright/test'; +import { + BASE_URL, + IS_USER_REGISTERED, + REGISTERED_USER_EMAIL, + REGISTERED_USER_PASSWORD, +} from '../../Config'; +import URL from 'Common/Types/API/URL'; + +test.describe('Login', () => { + test('should be able to login', async ({ page }: {page: Page}) => { + if (!IS_USER_REGISTERED) { + // pass this test if the user is not registered + return; + } + + // go to login page + await page.goto( + URL.fromString(BASE_URL.toString()) + .addRoute('/accounts/') + .toString() + ); + + await page.locator('input[type="email"]').click(); + await page + .locator('input[type="email"]') + .fill(REGISTERED_USER_EMAIL.toString()); + await page.locator('input[type="email"]').press('Tab'); + await page + .locator('input[type="password"]') + .fill(REGISTERED_USER_PASSWORD.toString()); + await page.locator('input[type="password"]').press('Enter'); + + // wait for navigation with base url + await page.waitForURL( + URL.fromString(BASE_URL.toString()) + .addRoute('/dashboard/welcome') + .toString() + ); + expect(page.url()).toBe( + URL.fromString(BASE_URL.toString()) + .addRoute('/dashboard/welcome') + .toString() + ); + + await page.getByTestId('create-new-project-button').click(); + }); +}); diff --git a/E2E/Tests/StatusPage/Basic.spec.ts b/E2E/Tests/StatusPage/Basic.spec.ts new file mode 100644 index 0000000000..f106dda9b7 --- /dev/null +++ b/E2E/Tests/StatusPage/Basic.spec.ts @@ -0,0 +1,18 @@ +import { Page, test } from '@playwright/test'; +import { STATUS_PAGE_URL } from '../../Config'; +import URL from 'Common/Types/API/URL'; + +test.describe('Basic Status Page', () => { + test('should be able to load status page properly', async ({ page }: {page: Page}) => { + if (!STATUS_PAGE_URL) { + // pass this test if the user is not registered + return; + } + + // go to login page + await page.goto(URL.fromString(STATUS_PAGE_URL.toString()).toString()); + + // check if data-testid is present with status-page-overview + await page.waitForSelector('[data-testid="status-page-overview"]'); // page loaded properly. + }); +}); diff --git a/HelmChart/Public/oneuptime/templates/cleanup-cron-job.yaml b/HelmChart/Public/oneuptime/templates/cleanup-cron-job.yaml index 7856a6fa33..cc4d103102 100644 --- a/HelmChart/Public/oneuptime/templates/cleanup-cron-job.yaml +++ b/HelmChart/Public/oneuptime/templates/cleanup-cron-job.yaml @@ -36,7 +36,7 @@ spec: kubectl delete pod $pod -n $namespace fi done - + restartPolicy: OnFailure --- diff --git a/HelmChart/Public/oneuptime/templates/e2e-cron.yml b/HelmChart/Public/oneuptime/templates/e2e-cron.yml index 43130e7c44..0d4a3e4af0 100644 --- a/HelmChart/Public/oneuptime/templates/e2e-cron.yml +++ b/HelmChart/Public/oneuptime/templates/e2e-cron.yml @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: Helm date: "{{ now | unixEpoch }}" spec: - schedule: "*/5 * * * *" # At every 30 minute. + schedule: "*/30 * * * *" # At every 30 minute. activeDeadlineSeconds: 3600 # 1 hour jobTemplate: spec: @@ -30,6 +30,8 @@ spec: value: {{ $.Values.cronJobs.e2e.registeredUserEmail | quote }} - name: E2E_TEST_REGISERED_USER_PASSWORD value: {{ $.Values.cronJobs.e2e.registeredUserPassword | quote }} + - name: E2E_TEST_STATUS_PAGE_URL + value: {{ $.Values.cronJobs.e2e.statusPageUrl | quote }} restartPolicy: Never {{- end }} \ No newline at end of file diff --git a/HelmChart/Public/oneuptime/values.yaml b/HelmChart/Public/oneuptime/values.yaml index b92798f20c..1ef3cbdb1f 100644 --- a/HelmChart/Public/oneuptime/values.yaml +++ b/HelmChart/Public/oneuptime/values.yaml @@ -204,4 +204,6 @@ cronJobs: isUserRegistered: false registeredUserEmail: registeredUserPassword: + # This is the URL of the status page you want to test. This is used to check if the status page is up and running. + statusPageUrl: \ No newline at end of file diff --git a/StatusPage/src/Pages/Overview/Overview.tsx b/StatusPage/src/Pages/Overview/Overview.tsx index 88d417445a..92170aa903 100644 --- a/StatusPage/src/Pages/Overview/Overview.tsx +++ b/StatusPage/src/Pages/Overview/Overview.tsx @@ -729,7 +729,7 @@ const Overview: FunctionComponent = ( {error ? : <>} {!isLoading && !error ? ( -
+
{/* Overview Page Description */} {statusPage && statusPage.overviewPageDescription && (