-
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.
- Loading branch information
1 parent
c3cb294
commit 326caa4
Showing
37 changed files
with
720 additions
and
768 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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import { 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 { queryClient, setup, userToken } from '../../tests/utils' | ||
import BlueskyCard from './BlueskyCard' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
||
describe('BlueSkyCard', () => { | ||
beforeAll(() => { | ||
localStorage.setItem('token', token) | ||
localStorage.setItem('token', userToken) | ||
}) | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
const ticker = ({ active, connected, handle = '', appKey = '' }: { active: boolean; connected: boolean; handle?: string; appKey?: string }) => { | ||
|
@@ -27,41 +25,20 @@ describe('BlueSkyCard', () => { | |
} as Ticker | ||
} | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
function setup(ticker: Ticker) { | ||
const client = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
return render( | ||
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<NotificationProvider> | ||
<BlueskyCard ticker={ticker} /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
const component = ({ ticker }: { ticker: Ticker }) => { | ||
return <BlueskyCard ticker={ticker} /> | ||
} | ||
|
||
it('should render the component', () => { | ||
setup(ticker({ active: false, connected: false })) | ||
setup(queryClient, component({ ticker: ticker({ active: false, connected: false }) })) | ||
|
||
expect(screen.getByText('Bluesky')).toBeInTheDocument() | ||
expect(screen.getByText('You are not connected with Bluesky.')).toBeInTheDocument() | ||
expect(screen.getByRole('button', { name: 'Configure' })).toBeInTheDocument() | ||
}) | ||
|
||
it('should render the component when connected and active', async () => { | ||
setup(ticker({ active: true, connected: true, handle: 'handle.bsky.social' })) | ||
setup(queryClient, component({ ticker: ticker({ active: true, connected: true, handle: 'handle.bsky.social' }) })) | ||
|
||
expect(screen.getByText('Bluesky')).toBeInTheDocument() | ||
expect(screen.getByText('You are connected with Bluesky.')).toBeInTheDocument() | ||
|
@@ -80,7 +57,7 @@ describe('BlueSkyCard', () => { | |
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: 'Bearer ' + token, | ||
Authorization: 'Bearer ' + userToken, | ||
}, | ||
method: 'put', | ||
}) | ||
|
@@ -94,7 +71,7 @@ describe('BlueSkyCard', () => { | |
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: 'Bearer ' + token, | ||
Authorization: 'Bearer ' + userToken, | ||
}, | ||
method: 'delete', | ||
}) | ||
|
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import { screen } from '@testing-library/dom' | ||
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 { queryClient, setup, userToken } from '../../tests/utils' | ||
import BlueskyForm from './BlueskyForm' | ||
|
||
const token = sign({ id: 1, email: '[email protected]', roles: ['user'], exp: new Date().getTime() / 1000 + 600 }, 'secret') | ||
|
||
describe('BlueskyForm', () => { | ||
beforeAll(() => { | ||
localStorage.setItem('token', token) | ||
localStorage.setItem('token', userToken) | ||
}) | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
const ticker = ({ active, connected, handle = '', appKey = '' }: { active: boolean; connected: boolean; handle?: string; appKey?: string }) => { | ||
|
@@ -29,34 +27,17 @@ describe('BlueskyForm', () => { | |
|
||
const callback = vi.fn() | ||
|
||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
function setup(ticker: Ticker) { | ||
const client = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
return render( | ||
<QueryClientProvider client={client}> | ||
<MemoryRouter> | ||
<AuthProvider> | ||
<NotificationProvider> | ||
<BlueskyForm callback={callback} ticker={ticker} /> | ||
<input name="Submit" type="submit" value="Submit" form="configureBluesky" /> | ||
</NotificationProvider> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
const component = ({ ticker }: { ticker: Ticker }) => { | ||
return ( | ||
<> | ||
<BlueskyForm callback={callback} ticker={ticker} /> | ||
<input name="Submit" type="submit" value="Submit" form="configureBluesky" /> | ||
</> | ||
) | ||
} | ||
|
||
it('should render the component', async () => { | ||
setup(ticker({ active: false, connected: false })) | ||
setup(queryClient, component({ ticker: ticker({ active: false, connected: false }) })) | ||
|
||
expect(screen.getByText('You need to create a application password in Bluesky.')).toBeInTheDocument() | ||
expect(screen.getByRole('checkbox', { name: 'Active' })).toBeInTheDocument() | ||
|
@@ -78,7 +59,7 @@ describe('BlueskyForm', () => { | |
body: '{"active":true,"handle":"handle.bsky.social","appKey":"password"}', | ||
headers: { | ||
Accept: 'application/json', | ||
Authorization: 'Bearer ' + token, | ||
Authorization: 'Bearer ' + userToken, | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'put', | ||
|
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
Oops, something went wrong.