-
Notifications
You must be signed in to change notification settings - Fork 6
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 #541 from systemli/Fix-TickerUsersForm
🐛 Fix TickerUsersForm
- Loading branch information
Showing
4 changed files
with
80 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { Ticker } from '../../api/Ticker' | ||
import { User } from '../../api/User' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import TickerUsersForm from './TickerUsersForm' | ||
|
||
describe('TickerUsersForm', () => { | ||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
function setup(defaultValue: Array<User>, ticker: Ticker, onSubmit: () => void) { | ||
const client = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
return render( | ||
<QueryClientProvider client={client}> | ||
<TickerUsersForm defaultValue={defaultValue} onSubmit={onSubmit} ticker={ticker} /> | ||
</QueryClientProvider> | ||
) | ||
} | ||
|
||
it('should renders correctly', async () => { | ||
const ticker = { | ||
id: 1, | ||
title: 'Ticker 1', | ||
} as Ticker | ||
const user = { | ||
id: 1, | ||
email: '[email protected]', | ||
} as User | ||
fetchMock.mockResponseOnce( | ||
JSON.stringify({ | ||
data: { | ||
users: [user], | ||
}, | ||
status: 'success', | ||
}) | ||
) | ||
|
||
const handleSubmit = jest.fn() | ||
setup([user], ticker, handleSubmit) | ||
|
||
fireEvent.mouseDown(screen.getByRole('button')) | ||
const listbox = await screen.findByRole('listbox') | ||
expect(listbox).toBeInTheDocument() | ||
const option = await screen.findByRole('option') | ||
expect(option).toBeInTheDocument() | ||
fireEvent.click(option) | ||
expect(fetchMock).toHaveBeenCalledTimes(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
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