-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from doug-wade/add-writing-fe-tests
Add writing fe tests
- Loading branch information
Showing
14 changed files
with
423 additions
and
6 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
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {render, screen} from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import Greeter from './greeter' | ||
|
||
it('displays a greeting', async () => { | ||
// Arrange | ||
const name = "World" | ||
render(<Greeter name={name} />) | ||
|
||
// Act | ||
await screen.findByRole('heading') | ||
|
||
// Assert | ||
expect(screen.getByRole('heading')).toHaveTextContent(`Hello ${name}`) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
describe('my fake timers', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers() | ||
}) | ||
|
||
it('runs setTimeout', ...) | ||
|
||
afterEach(() => { | ||
jest.runOnlyPendingTimers() | ||
jest.useRealTimers() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {render, screen} from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import Greeter from './greeter' | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ t: (str: string) => 'Привіт' }) | ||
})) | ||
|
||
test('displays a greeting', async () => { | ||
// Arrange | ||
const name = "Світ" | ||
render(<Greeter language="ukr" name={name} />) | ||
|
||
// Act | ||
await screen.findByRole('heading') | ||
|
||
// Assert | ||
expect(screen.getByRole('heading')).toHaveTextContent(`Привіт ${name}`) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Queries Accessible to Everyone | ||
screen.getByRole('button', { hidden: true }) | ||
screen.getByLabelText('Username') | ||
screen.getByPlaceholderText('Username') | ||
screen.getByText(/about/i) | ||
screen.getByDisplayValue('Alaska') | ||
|
||
// Semantic Queries | ||
screen.getByAltText(/incredibles.*? poster/i) | ||
screen.getByTitle('Delete') | ||
|
||
// Test IDs | ||
screen.getByTestId('custom-element') |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
screen.getByRole('spinbutton', {value: {now: 5}}) | ||
// <button>Volume</button> | ||
|
||
screen.getAllByRole('spinbutton', {value: {min: 0}}) | ||
// [ | ||
// <button>Volume</button>, | ||
// <button>Pitch</button> | ||
// ] | ||
|
||
screen.queryByRole('spinbutton', {value: {now: 5}}) | ||
// null |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {render, screen} from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import Button from './button' | ||
|
||
test('calls the onClick handler', async () => { | ||
// Arrange | ||
const handleClick = jest.fn(); | ||
render(<Button onClick={handleClick} />) | ||
|
||
// Act | ||
await userEvent.click(await screen.findByRole('button')) | ||
|
||
// Assert | ||
expect(handleClick).toHaveBeenCalled() | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
pointer(input: PointerActionInput | Array<PointerActionInput>): Promise<void> | ||
pointer([ | ||
// touch the screen at element1 | ||
{keys: '[TouchA>]', target: element1}, | ||
// move the touch pointer to element2 | ||
{pointerName: 'TouchA', target: element2}, | ||
// release the touch pointer at the last position (element2) | ||
{keys: '[/TouchA]'}, | ||
]) | ||
|
||
keyboard(input: KeyboardInput): Promise<void> | ||
keyboard('{Shift>}A{/Shift}') | ||
|
||
clear(element: Element): Promise<void> | ||
clear(screen.queryByRole('spinbutton')) | ||
|
||
selectOptions( | ||
element: Element, | ||
values: HTMLElement | HTMLElement[] | string[] | string, | ||
): Promise<void> | ||
deselectOptions( | ||
element: Element, | ||
values: HTMLElement | HTMLElement[] | string[] | string, | ||
): Promise<void> | ||
selectOptions(screen.getByRole('listbox'), ['1', 'C']) | ||
|
||
upload( | ||
element: HTMLElement, | ||
fileOrFiles: File | File[], | ||
): Promise<void> | ||
upload(screen.getByLabelText(/upload file/i), new File()) | ||
|
||
hover(element: Element): Promise<void> | ||
hover(screen.getByRole('button')) | ||
|
||
unhover(element: Element): Promise<void> | ||
unhover(screen.getByRole('button')) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
test('type into an input field', async () => { | ||
const user = userEvent.setup() | ||
|
||
render(<input defaultValue="Hello," />) | ||
const input = screen.getByRole('textbox') | ||
|
||
await user.type(input, ' World!') | ||
|
||
expect(input).toHaveValue('Hello, World!') | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { DurationInput as DurationInputComponent } from './common/forms/DurationInput' | ||
|
||
const meta: Meta<typeof DurationInputComponent> = { | ||
title: 'common/forms/DurationInput', | ||
component: DurationInputComponent, | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof DurationInputComponent> | ||
|
||
export const DurationInput: Story = {} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Meta } from '@storybook/react'; | ||
|
||
import { Button } from './Button'; | ||
|
||
const meta: Meta<typeof Button> = { | ||
component: Button, | ||
argTypes: { | ||
variant: { control: 'select', options: ['primary', 'secondary', 'tertiary'] }, | ||
label: { control: 'text' } | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Button>; | ||
|
||
export const Default: Story = { | ||
render({ label, variant }) { | ||
return <Button label={label} variant={variant} /> | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { Button } from './Button'; | ||
|
||
const meta: Meta<typeof Button> = { | ||
component: Button, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Button>; | ||
|
||
export const Primary: Story = { | ||
render: () => <Button variant="primary" label="Button" />, | ||
}; | ||
|
||
export const Secondary: Story = { | ||
render: () => <Button variant="secondary" label="Other Button" />, | ||
} |
Oops, something went wrong.