-
Notifications
You must be signed in to change notification settings - Fork 21
[Call node] Add support for href with action #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ThaminduDilshan
merged 1 commit into
thunder-id:main
from
ThaminduDilshan:call-node-rich-text-action
Jul 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/javascript/src/models/__tests__/embedded-flow.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import {describe, expect, it} from 'vitest'; | ||
| import { | ||
| EmbeddedFlowComponent, | ||
| EmbeddedFlowComponentAction, | ||
| EmbeddedFlowComponentType, | ||
| EmbeddedFlowEventType, | ||
| } from '../embedded-flow'; | ||
|
|
||
| describe('EmbeddedFlowComponentAction', () => { | ||
| it('accepts a ref-only action (defaults to SUBMIT semantics at the renderer)', () => { | ||
| const action: EmbeddedFlowComponentAction = {ref: 'action_signup'}; | ||
| expect(action.ref).toBe('action_signup'); | ||
| expect(action.eventType).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('accepts an explicit TRIGGER eventType', () => { | ||
| const action: EmbeddedFlowComponentAction = { | ||
| eventType: EmbeddedFlowEventType.Trigger, | ||
| ref: 'action_signup', | ||
| }; | ||
| expect(action.eventType).toBe('TRIGGER'); | ||
| }); | ||
|
|
||
| it('accepts a string eventType for forward-compatibility', () => { | ||
| const action: EmbeddedFlowComponentAction = { | ||
| eventType: 'CUSTOM_EVENT', | ||
| ref: 'action_signup', | ||
| }; | ||
| expect(action.eventType).toBe('CUSTOM_EVENT'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('EmbeddedFlowComponent.action', () => { | ||
| it('is optional — a plain rich-text component has no action', () => { | ||
| const component: EmbeddedFlowComponent = { | ||
| id: 'text_1', | ||
| label: '<p>Hello</p>', | ||
| type: EmbeddedFlowComponentType.RichText, | ||
| }; | ||
| expect(component.action).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('can carry an action wiring on a RICH_TEXT component', () => { | ||
| const component: EmbeddedFlowComponent = { | ||
| action: {eventType: EmbeddedFlowEventType.Submit, ref: 'action_signup'}, | ||
| id: 'text_1', | ||
| label: '<p>Have an account? <a data-action-ref="action_signup">Sign in</a></p>', | ||
| type: EmbeddedFlowComponentType.RichText, | ||
| }; | ||
| expect(component.action?.ref).toBe('action_signup'); | ||
| expect(component.action?.eventType).toBe('SUBMIT'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
packages/react/src/components/presentation/auth/__tests__/AuthOptionFactory.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /** | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import {render} from '@testing-library/react'; | ||
| import {EmbeddedFlowComponent, EmbeddedFlowComponentType, EmbeddedFlowEventType} from '@thunderid/browser'; | ||
| import {describe, expect, it, vi} from 'vitest'; | ||
| import {renderSignInComponents} from '../AuthOptionFactory'; | ||
|
|
||
| const richTextWithLink = (label: string, action?: {ref: string; eventType?: string}): EmbeddedFlowComponent => ({ | ||
| action, | ||
| id: 'text_1', | ||
| label, | ||
| type: EmbeddedFlowComponentType.RichText, | ||
| }); | ||
|
|
||
| const renderInto = ( | ||
| component: EmbeddedFlowComponent, | ||
| onSubmit?: (submitted: EmbeddedFlowComponent, data?: Record<string, string>, skipValidation?: boolean) => void, | ||
| ): {container: HTMLElement} => { | ||
| const elements = renderSignInComponents( | ||
| [component], | ||
| {empty: '', username: 'alice'}, | ||
| {}, | ||
| {}, | ||
| false, | ||
| true, | ||
| () => undefined, | ||
| {onSubmit}, | ||
| ); | ||
| return render(<div>{elements}</div>); | ||
| }; | ||
|
|
||
| describe('AuthOptionFactory rich-text action', () => { | ||
| it('renders a plain rich-text component without any click handler', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p>Have an account? <a href="/signin" data-action-ref="action_signin">Sign in</a></p>'), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| const anchor = container.querySelector<HTMLAnchorElement>('a[data-action-ref="action_signin"]')!; | ||
| expect(anchor).not.toBeNull(); | ||
| anchor.click(); | ||
| expect(onSubmit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('dispatches a synthetic action with SUBMIT semantics when the sentinel anchor is clicked', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p>Have an account? <a href="/signin" data-action-ref="action_signin">Sign in</a></p>', { | ||
| eventType: EmbeddedFlowEventType.Submit, | ||
| ref: 'action_signin', | ||
| }), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLAnchorElement>('a[data-action-ref="action_signin"]')!.click(); | ||
|
|
||
| expect(onSubmit).toHaveBeenCalledTimes(1); | ||
| const call = onSubmit.mock.calls[0] as [EmbeddedFlowComponent, Record<string, string>, boolean]; | ||
| expect(call[0].type).toBe(EmbeddedFlowComponentType.Action); | ||
| expect(call[0].ref).toBe('action_signin'); | ||
| expect(call[0].eventType).toBe('SUBMIT'); | ||
| expect(call[1]).toEqual({empty: '', username: 'alice'}); | ||
| expect(call[2]).toBe(false); | ||
| }); | ||
|
|
||
| it('bypasses validation when the wired eventType is TRIGGER', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><a data-action-ref="action_signup">Sign up</a></p>', { | ||
| eventType: EmbeddedFlowEventType.Trigger, | ||
| ref: 'action_signup', | ||
| }), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLAnchorElement>('a[data-action-ref="action_signup"]')!.click(); | ||
|
|
||
| expect(onSubmit).toHaveBeenCalledTimes(1); | ||
| const call = onSubmit.mock.calls[0] as [EmbeddedFlowComponent, Record<string, string>, boolean]; | ||
| expect(call[2]).toBe(true); | ||
| }); | ||
|
|
||
| it('defaults to SUBMIT semantics when the eventType is omitted', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><a data-action-ref="action_signup">Sign up</a></p>', {ref: 'action_signup'}), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLAnchorElement>('a[data-action-ref="action_signup"]')!.click(); | ||
|
|
||
| expect(onSubmit).toHaveBeenCalledTimes(1); | ||
| const call = onSubmit.mock.calls[0] as [EmbeddedFlowComponent, Record<string, string>, boolean]; | ||
| expect(call[0].eventType).toBe('SUBMIT'); | ||
| expect(call[2]).toBe(false); | ||
| }); | ||
|
|
||
| it('walks up from a descendant to the nearest anchor before dispatching', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><a data-action-ref="action_signup"><span class="child">Sign up</span></a></p>', { | ||
| ref: 'action_signup', | ||
| }), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLSpanElement>('span.child')!.click(); | ||
|
|
||
| expect(onSubmit).toHaveBeenCalledTimes(1); | ||
| const call = onSubmit.mock.calls[0] as [EmbeddedFlowComponent, Record<string, string>, boolean]; | ||
| expect(call[0].ref).toBe('action_signup'); | ||
| }); | ||
|
|
||
| it('ignores clicks on anchors whose data-action-ref does not match the wired ref', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><a data-action-ref="action_other">Other</a></p>', {ref: 'action_signup'}), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLAnchorElement>('a[data-action-ref="action_other"]')!.click(); | ||
|
|
||
| expect(onSubmit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('ignores clicks on anchors that lack the data-action-ref sentinel', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p>Have an account? <a href="/plain" target="_blank">Sign up</a></p>', {ref: 'action_signup'}), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLAnchorElement>('a')!.click(); | ||
|
|
||
| expect(onSubmit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('ignores clicks outside any anchor in an action-bearing rich text', () => { | ||
| const onSubmit = vi.fn(); | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><span class="outside">Not a link</span></p>', {ref: 'action_signup'}), | ||
| onSubmit, | ||
| ); | ||
|
|
||
| container.querySelector<HTMLSpanElement>('span.outside')!.click(); | ||
|
|
||
| expect(onSubmit).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not throw when onSubmit is omitted from options', () => { | ||
| const {container} = renderInto( | ||
| richTextWithLink('<p><a data-action-ref="action_signup">Sign up</a></p>', {ref: 'action_signup'}), | ||
| ); | ||
|
|
||
| expect(() => container.querySelector<HTMLAnchorElement>('a')!.click()).not.toThrow(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.