Skip to content

Commit 632d6c5

Browse files
committed
chore: fix-logic-add-tests
1 parent b475a46 commit 632d6c5

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

.husky/install.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
33
process.exit(0)
44
}
55
const husky = (await import('husky')).default
6-
console.log(husky.install())
6+
console.log(husky())
+37-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
import { expect, test } from '@playwright/test';
2-
import { asyncEvents } from './utils/async-events.js';
32

4-
test('Test happy paths on test page', async ({ page }) => {
5-
const { navigate } = asyncEvents(page);
6-
await navigate('/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
3+
test('Should render form fields', async ({ page }) => {
4+
await page.goto('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
5+
await page.getByRole('heading', { name: 'Select Test Form' }).click();
6+
await page.getByRole('button', { name: 'Form Fields' }).click();
7+
await page.getByRole('textbox', { name: 'Text Input Label' }).click();
8+
await page.getByRole('textbox', { name: 'Text Input Label' }).click();
79

8-
console.log(page.url());
9-
expect(page.url()).toBe('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
10+
const txtInput = page.getByRole('textbox', { name: 'Text Input Label' });
11+
await txtInput.fill('This is some text');
12+
expect(txtInput).toHaveValue('This is some text');
1013

11-
await expect(page.getByText('Select Test Form')).toBeVisible();
14+
const flowLink = page.getByRole('button', { name: 'Flow Link' });
15+
await flowLink.click();
1216

13-
const formFields = page.getByRole('button', { name: 'Form Fields' });
14-
const formValidation = page.getByRole('button', { name: 'Form Validation' });
17+
const flowButton = page.getByRole('button', { name: 'Flow Button' });
18+
await flowButton.click();
1519

16-
await expect(formFields).toBeVisible();
17-
await expect(formValidation).toBeVisible();
20+
await page.getByRole('button', { name: 'Submit' }).click();
21+
});
22+
23+
test('should render form validation fields', async ({ page }) => {
24+
await page.goto('http://localhost:5829/?clientId=60de77d5-dd2c-41ef-8c40-f8bb2381a359');
25+
await expect(page.getByRole('link', { name: 'Vite logo' })).toBeVisible();
26+
await expect(page.getByRole('button', { name: 'Form Validation' })).toBeVisible();
27+
await expect(page.locator('#form')).toContainText('Form Validation');
28+
await page.getByRole('button', { name: 'Form Validation' }).click();
29+
await expect(page.getByRole('heading', { name: 'Form Fields Validation' })).toBeVisible();
30+
await expect(page.getByText('Username')).toBeVisible();
31+
await expect(page.getByRole('textbox', { name: 'Username' })).toBeVisible();
32+
await expect(page.getByText('Email Address')).toBeVisible();
33+
await expect(page.getByRole('textbox', { name: 'Email Address' })).toBeVisible();
34+
await expect(page.getByRole('button', { name: 'Submit' })).toBeVisible();
35+
await page.getByRole('textbox', { name: 'Username' }).click();
36+
await page.getByRole('textbox', { name: 'Username' }).fill('sdk-user');
37+
await expect(page.getByRole('textbox', { name: 'Username' })).toHaveValue('sdk-user');
38+
await page.getByRole('textbox', { name: 'Email Address' }).click();
39+
await page.getByRole('textbox', { name: 'Email Address' }).fill('[email protected]');
40+
await expect(page.getByRole('textbox', { name: 'Email Address' })).toHaveValue(
41+
42+
);
43+
await page.getByRole('button', { name: 'Submit' }).click();
1844
});

packages/davinci-client/src/lib/collector.utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export function returnSingleValueCollector<
112112
CollectorType extends SingleValueCollectorTypes = 'SingleValueCollector',
113113
>(field: Field, idx: number, collectorType: CollectorType, data?: string) {
114114
let error = '';
115+
console.log('the field ', field);
115116
if (!('key' in field)) {
116117
error = `${error}Key is not found in the field object. `;
117118
}

packages/davinci-client/src/lib/davinci.utils.ts

+17-4
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,25 @@ export function handleResponse(cacheEntry: DaVinciCacheEntry, dispatch: Dispatch
172172
*/
173173
if (cacheEntry.isSuccess) {
174174
const requestId = cacheEntry.requestId;
175-
if ('eventName' in cacheEntry.data && cacheEntry.data.eventName === 'continue') {
176-
const data = cacheEntry.data as DaVinciNextResponse;
177-
dispatch(nodeSlice.actions.next({ data, requestId, httpStatus: status }));
178-
} else if ('session' in cacheEntry.data || 'authorizeResponse' in cacheEntry.data) {
175+
const hasNextUrl = () => {
176+
const data = cacheEntry.data;
177+
178+
if ('_links' in data) {
179+
if ('next' in data._links) {
180+
if ('href' in data._links.next) {
181+
return true;
182+
}
183+
}
184+
}
185+
return false;
186+
};
187+
188+
if ('session' in cacheEntry.data || 'authorizeResponse' in cacheEntry.data) {
179189
const data = cacheEntry.data as DaVinciSuccessResponse;
180190
dispatch(nodeSlice.actions.success({ data, requestId, httpStatus: status }));
191+
} else if (hasNextUrl()) {
192+
const data = cacheEntry.data as DaVinciNextResponse;
193+
dispatch(nodeSlice.actions.next({ data, requestId, httpStatus: status }));
181194
} else {
182195
// If we got here, the response type is unknown and therefore an unrecoverable failure
183196
const data = cacheEntry.data as DaVinciFailureResponse;

0 commit comments

Comments
 (0)