Skip to content

Commit

Permalink
Attempt to fix startup tests
Browse files Browse the repository at this point in the history
Fix javascript keyword argument syntax

Fix missing function call

Remove debug console.log
  • Loading branch information
monsieurswag committed Nov 22, 2024
1 parent 061a4e8 commit 3b24a84
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/startup-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
working-directory: ${{ env.frontend-directory }}
run: |
response=$(curl -d "[email protected]&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
Expand Down Expand Up @@ -264,7 +264,7 @@ jobs:
working-directory: ${{ env.frontend-directory }}
run: |
response=$(curl -d "[email protected]&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
Expand Down
1 change: 0 additions & 1 deletion frontend/src/routes/(authentication)/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export const actions: Actions = {

const next = url.searchParams.get('next') || '/';
const redirectURL = getSecureRedirect(next) + '?refresh=1';
[0, 0, 0, 0, 0].forEach(() => console.log(redirectURL));
redirect(302, redirectURL);
},
mfaAuthenticate: async (event) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/functional/startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
23 changes: 21 additions & 2 deletions frontend/tests/utils/base-page.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,8 +38,17 @@ export abstract class BasePage {
await expect.soft(this.pageTitle).toHaveText(title);
}

async hasUrl() {
await expect(this.page).toHaveURL(this.url);
/**
* 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) {
const URLPattern = strict ? this.url : new RegExp(escapeRegex(this.url) + ".*");
await expect(this.page).toHaveURL(URLPattern);
}

async hasBreadcrumbPath(paths: (string | RegExp)[], fullPath = true, origin = 'Home') {
Expand Down

0 comments on commit 3b24a84

Please sign in to comment.