Skip to content

Commit

Permalink
fix: form.displayName to populate properly (#705)
Browse files Browse the repository at this point in the history
+ test
fixes descope/etc#5861
  • Loading branch information
aviadl authored Jul 11, 2024
1 parent 725ecd6 commit 73b3af1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/sdks/web-component/src/lib/helpers/flowInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const flattenFormObject = (obj: any, prefix = '') =>
return { ...res, ...flattenFormObject(obj[el], `${prefix + el}.`) };
}
const v = typeof obj[el] === 'object' ? obj[el] : { value: obj[el] };
return { ...res, [prefix + el]: v, [`form.${prefix}${el}`]: v };
const fl = { ...res, [prefix + el]: v, [`form.${prefix}${el}`]: v };
if (el === 'displayName') {
return { ...fl, [`${prefix }fullName`]: v, [`form.${prefix}fullName`]: v };
}
return fl;
}, []);

export const transformFlowInputFormData = (formData: string) => {
Expand Down
11 changes: 9 additions & 2 deletions packages/sdks/web-component/test/descope-wc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ describe('web-component', () => {

pageContent = '<div>hey</div>';

document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc flow-id="sign-in" project-id="1" form='{"email": "test", "nested": { "key": "value" }, "another": { "value": "a", "disabled": true }}' client='{"email": "test2", "nested": { "key": "value" }}'></descope-wc>`;
document.body.innerHTML = `<h1>Custom element test</h1> <descope-wc flow-id="sign-in" project-id="1" form='{"displayName": "dn", "email": "test", "nested": { "key": "value" }, "another": { "value": "a", "disabled": true }}' client='{"email": "test2", "nested": { "key": "value" }}'></descope-wc>`;

await waitFor(() => screen.findByShadowText('hey'), {
timeout: WAIT_TIMEOUT,
Expand All @@ -1719,7 +1719,10 @@ describe('web-component', () => {
expect(startMock).toHaveBeenCalledWith(
'sign-in',
expect.objectContaining({
client: { email: 'test2', nested: { key: 'value' } },
client: {
email: 'test2',
nested: { key: 'value' },
},
}),
undefined,
'',
Expand All @@ -1732,6 +1735,10 @@ describe('web-component', () => {
'form.nested.key': 'value',
another: 'a',
'form.another': 'a',
'form.displayName': 'dn',
'form.fullName': 'dn',
displayName: 'dn',
fullName: 'dn',
},
),
);
Expand Down

0 comments on commit 73b3af1

Please sign in to comment.