-
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 #713 from systemli/Add-Notifications-for-Ticker
💄 Add Notifications for Ticker
- Loading branch information
Showing
24 changed files
with
248 additions
and
35 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,11 +1,12 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import sign from 'jwt-encode' | ||
import BlueskyCard from './BlueskyCard' | ||
import { MemoryRouter } from 'react-router' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { Ticker } from '../../api/Ticker' | ||
import userEvent from '@testing-library/user-event' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import BlueskyCard from './BlueskyCard' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
||
|
@@ -42,7 +43,9 @@ describe('BlueSkyCard', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<BlueskyCard ticker={ticker} /> | ||
<NotificationProvider> | ||
<BlueskyCard ticker={ticker} /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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,11 +1,12 @@ | ||
import sign from 'jwt-encode' | ||
import { Ticker } from '../../api/Ticker' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import sign from 'jwt-encode' | ||
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import BlueskyForm from './BlueskyForm' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
||
|
@@ -44,10 +45,10 @@ describe('BlueskyForm', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<div> | ||
<NotificationProvider> | ||
<BlueskyForm callback={callback} ticker={ticker} /> | ||
<input name="Submit" type="submit" value="Submit" form="configureBluesky" /> | ||
</div> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import sign from 'jwt-encode' | |
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import MastodonCard from './MastodonCard' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
@@ -42,7 +43,9 @@ describe('MastodonCard', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<MastodonCard ticker={ticker} /> | ||
<NotificationProvider> | ||
<MastodonCard ticker={ticker} /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import sign from 'jwt-encode' | |
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import MastodonForm from './MastodonForm' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
@@ -44,10 +45,10 @@ describe('MastodonForm', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<div> | ||
<NotificationProvider> | ||
<MastodonForm callback={callback} ticker={ticker} /> | ||
<input name="Submit" type="submit" value="Submit" form="configureMastodon" /> | ||
</div> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import sign from 'jwt-encode' | |
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import TelegramCard from './TelegramCard' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
@@ -42,7 +43,9 @@ describe('TelegramCard', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<TelegramCard ticker={ticker} /> | ||
<NotificationProvider> | ||
<TelegramCard ticker={ticker} /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import sign from 'jwt-encode' | |
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import TelegramForm from './TelegramForm' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
@@ -44,10 +45,10 @@ describe('TelegramForm', () => { | |
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<div> | ||
<NotificationProvider> | ||
<TelegramForm callback={callback} ticker={ticker} /> | ||
<input name="Submit" type="submit" value="Submit" form="configureTelegram" /> | ||
</div> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
|
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
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,86 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
import sign from 'jwt-encode' | ||
import { MemoryRouter } from 'react-router' | ||
import { Ticker } from '../../api/Ticker' | ||
import { AuthProvider } from '../../contexts/AuthContext' | ||
import { NotificationProvider } from '../../contexts/NotificationContext' | ||
import TickerResetModal from './TickerResetModal' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
||
describe('TickerResetModal', () => { | ||
beforeAll(() => { | ||
localStorage.setItem('token', token) | ||
}) | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
onClose.mockClear() | ||
}) | ||
|
||
const onClose = vi.fn() | ||
|
||
function setup(ticker: Ticker) { | ||
const client = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
return render( | ||
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<NotificationProvider> | ||
<TickerResetModal open={true} onClose={onClose} ticker={ticker} /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
} | ||
|
||
it('should render the component', async () => { | ||
const ticker = { | ||
id: 1, | ||
title: 'Ticker 1', | ||
} as Ticker | ||
setup(ticker) | ||
|
||
expect(screen.getByRole('button', { name: 'Reset' })).toBeInTheDocument() | ||
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument() | ||
|
||
fetchMock.mockResponseOnce(JSON.stringify({ status: 'success' })) | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Reset' })) | ||
|
||
expect(onClose).toHaveBeenCalledTimes(1) | ||
expect(fetchMock).toHaveBeenCalledTimes(1) | ||
expect(fetchMock).toHaveBeenCalledWith('http://localhost:8080/v1/admin/tickers/1/reset', { | ||
method: 'put', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}) | ||
}) | ||
|
||
it('should render the component and close the modal', async () => { | ||
const ticker = { | ||
id: 1, | ||
title: 'Ticker 1', | ||
} as Ticker | ||
setup(ticker) | ||
|
||
fetchMock.mockResponseOnce(JSON.stringify({ status: 'success' })) | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Close' })) | ||
|
||
expect(onClose).toHaveBeenCalledTimes(1) | ||
expect(fetchMock).toHaveBeenCalledTimes(0) | ||
}) | ||
}) |
Oops, something went wrong.