-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react19): Remove findDomNode in textCopyInput
part of getsentry/frontend-tsc#68
- Loading branch information
Showing
2 changed files
with
43 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,10 +1,43 @@ | ||
import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; | ||
|
||
import TextCopyInput from 'sentry/components/textCopyInput'; | ||
|
||
describe('TextCopyInput', function () { | ||
it('renders', function () { | ||
beforeEach(() => { | ||
Object.assign(navigator, { | ||
clipboard: { | ||
writeText: jest.fn().mockResolvedValue(''), | ||
}, | ||
}); | ||
}); | ||
|
||
it('copies text to clipboard on click', async function () { | ||
render(<TextCopyInput>Text to Copy</TextCopyInput>); | ||
const button = screen.getByRole('button', {name: 'Copy'}); | ||
expect(button).toBeInTheDocument(); | ||
|
||
await userEvent.click(button); | ||
|
||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('Text to Copy'); | ||
}); | ||
|
||
it('selects text in input on click', async function () { | ||
render(<TextCopyInput>Text to Copy</TextCopyInput>); | ||
expect(screen.getByDisplayValue('Text to Copy')).toBeInTheDocument(); | ||
const input = screen.getByRole<HTMLInputElement>('textbox'); | ||
expect(input).toHaveValue('Text to Copy'); | ||
const selectSpy = jest.spyOn(input, 'select'); | ||
|
||
await userEvent.click(input); | ||
|
||
expect(selectSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('handles RTL text selection', async function () { | ||
render(<TextCopyInput rtl>Text to Copy</TextCopyInput>); | ||
const input = screen.getByRole<HTMLInputElement>('textbox'); | ||
const setSelectionRangeSpy = jest.spyOn(input, 'setSelectionRange'); | ||
|
||
await userEvent.click(input); | ||
expect(setSelectionRangeSpy).toHaveBeenCalledWith(1, input.value.length - 1); | ||
}); | ||
}); |
This file contains 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