Skip to content

Commit 6012e48

Browse files
committed
chore: add-tests
1 parent ffbcde5 commit 6012e48

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

e2e/davinci-app/main.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './style.css';
22

33
import { Config, FRUser, TokenManager } from '@forgerock/javascript-sdk';
44
import { davinci } from '@forgerock/davinci-client';
5-
import type { DaVinciConfig } from '@forgerock/davinci-client/types';
5+
//import type { DaVinciConfig } from '@forgerock/davinci-client/types';
66

77
import usernameComponent from './components/text.js';
88
import passwordComponent from './components/password.js';
@@ -11,9 +11,26 @@ import protect from './components/protect.js';
1111
import flowLinkComponent from './components/flow-link.js';
1212
import socialLoginButtonComponent from './components/social-login-button.js';
1313

14-
const config: DaVinciConfig = {
15-
clientId: '724ec718-c41c-4d51-98b0-84a583f450f9',
16-
redirectUri: window.location.origin + '/',
14+
const qs = window.location.search;
15+
const searchParams = new URLSearchParams(qs);
16+
17+
const query: Record<string, string | string[]> = {};
18+
19+
// Get all unique keys from the searchParams
20+
const uniqueKeys = new Set(searchParams.keys());
21+
22+
// Iterate over the unique keys
23+
for (const key of uniqueKeys) {
24+
const values = searchParams.getAll(key);
25+
query[key] = values.length > 1 ? values : values[0];
26+
}
27+
let clientId = '724ec718-c41c-4d51-98b0-84a583f450f9';
28+
if (query.clientId && query.clientId.length > 0) {
29+
clientId = query.clientId as string;
30+
}
31+
const config = {
32+
clientId,
33+
redirectUri: `${window.location.origin}/`,
1734
scope: 'openid profile email name revoke',
1835
serverConfig: {
1936
wellknown:
@@ -79,7 +96,7 @@ const config: DaVinciConfig = {
7996

8097
const loginBtn = document.getElementById('logoutButton') as HTMLButtonElement;
8198
loginBtn.addEventListener('click', async () => {
82-
await FRUser.logout({ logoutRedirectUri: window.location.href });
99+
await FRUser.logout({ logoutRedirectUri: window.location.origin });
83100

84101
window.location.reload();
85102
});
@@ -179,20 +196,6 @@ const config: DaVinciConfig = {
179196
console.log('Event emitted from store:', node);
180197
});
181198

182-
const qs = window.location.search;
183-
const searchParams = new URLSearchParams(qs);
184-
185-
const query: Record<string, string | string[]> = {};
186-
187-
// Get all unique keys from the searchParams
188-
const uniqueKeys = new Set(searchParams.keys());
189-
190-
// Iterate over the unique keys
191-
for (const key of uniqueKeys) {
192-
const values = searchParams.getAll(key);
193-
query[key] = values.length > 1 ? values : values[0];
194-
}
195-
console.log('query', query);
196199
const node = await davinciClient.start({ query });
197200

198201
formEl.addEventListener('submit', async (event) => {
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, test } from '@playwright/test';
2+
import { asyncEvents } from './utils/async-events.js';
3+
4+
test('Test happy paths on test page', async ({ page }) => {
5+
const { navigate } = asyncEvents(page);
6+
await navigate('/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
7+
8+
console.log(page.url());
9+
expect(page.url()).toBe('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
10+
11+
await expect(page.getByText('Select Test Form')).toBeVisible();
12+
13+
const formFields = page.getByRole('button', { name: 'Form Fields' });
14+
const formValidation = page.getByRole('button', { name: 'Form Validation' });
15+
16+
await expect(formFields).toBeVisible();
17+
await expect(formValidation).toBeVisible();
18+
});

0 commit comments

Comments
 (0)