diff --git a/.github/workflows/startup-tests.yml b/.github/workflows/startup-tests.yml index ad27fc444e..1b3f47f423 100644 --- a/.github/workflows/startup-tests.yml +++ b/.github/workflows/startup-tests.yml @@ -136,7 +136,7 @@ jobs: working-directory: ${{ env.frontend-directory }} run: | response=$(curl -d "username=admin@tests.com&password=1234" -H "Origin: https://localhost:8443" https://localhost:8443/login\?/login -k) - server_reponse='{"type":"redirect","status":302,"location":""}' + server_reponse='{"type":"redirect","status":302,"location":"/?refresh=1"}' if [[ "$response" == "$server_reponse" ]]; then echo "Success" exit 0 @@ -264,7 +264,7 @@ jobs: working-directory: ${{ env.frontend-directory }} run: | response=$(curl -d "username=admin@tests.com&password=1234" -H "Origin: https://localhost:8443" https://localhost:8443/login\?/login -k) - server_reponse='{"type":"redirect","status":302,"location":""}' + server_reponse='{"type":"redirect","status":302,"location":"/?refresh=1"}' if [[ "$response" == "$server_reponse" ]]; then echo "Success" exit 0 diff --git a/frontend/tests/functional/startup.test.ts b/frontend/tests/functional/startup.test.ts index a56fee59e1..26945e1df8 100644 --- a/frontend/tests/functional/startup.test.ts +++ b/frontend/tests/functional/startup.test.ts @@ -5,7 +5,7 @@ test('startup tests', async ({ loginPage, analyticsPage, page }) => { await page.goto('/'); await loginPage.hasUrl(1); await loginPage.login(); - await analyticsPage.hasUrl(); + await analyticsPage.hasUrl(false); }); await test.step('proper redirection to the analytics page after login', async () => { diff --git a/frontend/tests/utils/base-page.ts b/frontend/tests/utils/base-page.ts index 0a65054469..46f8e22d6a 100644 --- a/frontend/tests/utils/base-page.ts +++ b/frontend/tests/utils/base-page.ts @@ -1,5 +1,15 @@ import { expect, type Locator, type Page } from './test-utils.js'; +/** + * Escape the characters of `string` to safely insert it in a regex. + * + * @param {string} string - The string to escape. + * @returns {string} The escaped string. +*/ +function escapeRegex(string: string): string { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} + export abstract class BasePage { readonly url: string; readonly name: string | RegExp; @@ -28,7 +38,17 @@ export abstract class BasePage { await expect.soft(this.pageTitle).toHaveText(title); } - async hasUrl() { + /** + * Check whether the browser's URL match the `this.url` value. + * + * @param {boolean} [strict=true] - Determines the URL matching mode. + * If `strict` is `true`, the function checks if `this.url` is strictly equal to the browser's URL. + * Otherwise, it checks if the browser's URL starts with `this.url`. + * @returns {void} + */ + async hasUrl(strict: boolean=true) { + this.url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ".*"; + const pattern = strict ? this.url : new RegExp(`${this.url}.*`); await expect(this.page).toHaveURL(this.url); }