-
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 #719 from systemli/Add-Reload-Button-for-Messages
✨ Add Reload Button for Messages
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { screen } from '@testing-library/dom' | ||
import userEvent from '@testing-library/user-event' | ||
import { Ticker } from '../../api/Ticker' | ||
import { queryClient, setup } from '../../tests/utils' | ||
import MessageListReload from './MessageListReload' | ||
|
||
describe('MessageListReload', () => { | ||
const ticker = { id: 1 } as Ticker | ||
|
||
it('should render', async () => { | ||
setup(queryClient, <MessageListReload ticker={ticker} />) | ||
|
||
vi.spyOn(queryClient, 'invalidateQueries') | ||
|
||
expect(screen.getByRole('button', { name: 'reload' })).toBeInTheDocument() | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'reload' })) | ||
|
||
expect(queryClient.invalidateQueries).toHaveBeenCalledTimes(1) | ||
expect(queryClient.invalidateQueries).toHaveBeenCalledWith({ queryKey: ['messages', ticker.id] }) | ||
}) | ||
}) |
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,30 @@ | ||
import { Refresh } from '@mui/icons-material' | ||
import { Box, Button } from '@mui/material' | ||
import { useQueryClient } from '@tanstack/react-query' | ||
import { FC, useState } from 'react' | ||
import { Ticker } from '../../api/Ticker' | ||
|
||
interface Props { | ||
ticker: Ticker | ||
} | ||
|
||
const MessageListReload: FC<Props> = ({ ticker }) => { | ||
const [loading, setLoading] = useState<boolean>(false) | ||
const queryClient = useQueryClient() | ||
|
||
const handleClick = async () => { | ||
setLoading(true) | ||
await queryClient.invalidateQueries({ queryKey: ['messages', ticker.id] }) | ||
setLoading(false) | ||
} | ||
|
||
return ( | ||
<Box sx={{ textAlign: 'right' }}> | ||
<Button aria-label="reload" onClick={handleClick} size="small" startIcon={<Refresh />} loading={loading} loadingPosition="start"> | ||
Reload Messages | ||
</Button> | ||
</Box> | ||
) | ||
} | ||
|
||
export default MessageListReload |
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