-
Notifications
You must be signed in to change notification settings - Fork 565
refactor(value-editor): migrate to TypeScript and split by concern #8447
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
80f872b
refactor(value-editor): migrate to TypeScript and split by concern
talissoncosta bf8eb6c
fix(value-editor): read XML parser errors in Firefox
talissoncosta 208388c
test(value-editor): cover value validation and clipboard copy
talissoncosta 083dfa8
fix(a11y): make the format labels real buttons
talissoncosta dc41b28
refactor(value-editor): own the label and name the editor
talissoncosta e5ae34c
refactor(saml): use InputGroup for the IdP metadata field
talissoncosta 754fa04
refactor(mv): share the control value weight chip
talissoncosta 3196173
refactor(value-editor): move its styles out of the highlight.js overr…
talissoncosta 3f784ae
fix(value-editor): detect the format when the value arrives, not at m…
talissoncosta 3fbcf6c
refactor(value-editor): own validity instead of the format row
talissoncosta 8f42bd3
refactor(value-editor): use utilities for layout and colour
talissoncosta f97118f
fix(value-editor): show the validation icon in its own colour
talissoncosta 18ac82c
refactor(value-editor): name the validation error and tone types
talissoncosta a2878a8
fix(a11y): show a focus border on the value editor
talissoncosta d500dc5
style(value-editor): blank line before the focus comment
talissoncosta 6af00b1
refactor(value-editor): drop the E2E textarea fork
talissoncosta dfad5df
test(e2e): select the value editors by role and name
talissoncosta 8adcbe0
fix(review): tighten the E2E selector, Highlight updates and SCSS import
talissoncosta ea90fdb
test(e2e): cover format validation in the browser
talissoncosta eb04dff
refactor(saml): keep the highlighted XML editor, pin it with language
talissoncosta 41d8eba
fix(review): tighten the contract and the format row's markup
talissoncosta 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { copyToClipboard } from 'common/utils/copyToClipboard' | ||
|
|
||
| const writeText = jest.fn() | ||
| const toast = jest.fn() | ||
|
|
||
| beforeEach(() => { | ||
| writeText.mockReset().mockResolvedValue(undefined) | ||
| toast.mockReset() | ||
| ;(global as any).toast = toast | ||
| Object.defineProperty(global, 'navigator', { | ||
| configurable: true, | ||
| value: { clipboard: { writeText } }, | ||
| writable: true, | ||
| }) | ||
| }) | ||
|
|
||
| describe('copyToClipboard', () => { | ||
| it('writes the value and toasts the default success message', async () => { | ||
| await copyToClipboard('DEFAULT_VALUE') | ||
|
|
||
| expect(writeText).toHaveBeenCalledWith('DEFAULT_VALUE') | ||
| expect(toast).toHaveBeenCalledWith('Copied to clipboard') | ||
| }) | ||
|
|
||
| it('toasts a caller-supplied success message instead', async () => { | ||
| await copyToClipboard('prompt', 'Cleanup prompt copied to clipboard') | ||
|
|
||
| expect(toast).toHaveBeenCalledWith('Cleanup prompt copied to clipboard') | ||
| }) | ||
|
|
||
| it('toasts the failure and rethrows when the write is rejected', async () => { | ||
| const error = new Error('denied') | ||
| writeText.mockRejectedValue(error) | ||
|
|
||
| await expect(copyToClipboard('value')).rejects.toThrow(error) | ||
| expect(toast).toHaveBeenCalledWith('Failed to copy to clipboard') | ||
| }) | ||
|
|
||
| it('toasts a caller-supplied failure message instead', async () => { | ||
| writeText.mockRejectedValue(new Error('denied')) | ||
|
|
||
| await expect( | ||
| copyToClipboard('value', undefined, 'Could not copy the value'), | ||
| ).rejects.toThrow() | ||
| expect(toast).toHaveBeenCalledWith('Could not copy the value') | ||
| }) | ||
| }) |
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,21 @@ | ||
| /** | ||
| * Write `value` to the clipboard and toast the outcome. | ||
| * | ||
| * Rethrows after toasting so callers that need to react to a failure can, | ||
| * but the toast means most callers do not have to. | ||
| */ | ||
| export const copyToClipboard = async ( | ||
| value: string, | ||
| successMessage?: string, | ||
| errorMessage?: string, | ||
| ) => { | ||
| try { | ||
| await navigator.clipboard.writeText(value) | ||
| toast(successMessage ?? 'Copied to clipboard') | ||
| } catch (error) { | ||
| toast(errorMessage ?? 'Failed to copy to clipboard') | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| export default copyToClipboard |
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
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
Oops, something went wrong.
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.