mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
Merge branch 'main' into dependabot/npm_and_yarn/node-fetch-3.2.0
This commit is contained in:
commit
af9cdbf796
2 changed files with 26 additions and 6 deletions
|
@ -1,17 +1,29 @@
|
|||
import { createHistory, createMemorySource, LocationProvider } from '@reach/router';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { useSessionContext } from '../../contexts/session/SessionContext';
|
||||
import NewSession from './new-session';
|
||||
|
||||
// for some types of tests you want a memory source
|
||||
const testSessionID = 'sessionid1234';
|
||||
let source = createMemorySource(`/machinery/new-session#/${testSessionID}`);
|
||||
let history = createHistory(source);
|
||||
|
||||
beforeEach(() => {
|
||||
history.location.hash = `#/${testSessionID}`;
|
||||
});
|
||||
|
||||
const setupSessionMock = jest.fn();
|
||||
(useSessionContext as jest.Mock) = jest.fn(() => ({
|
||||
setupSession: setupSessionMock,
|
||||
isAuthenticated: true,
|
||||
}));
|
||||
|
||||
const testSessionID = 'sessionid1234';
|
||||
|
||||
it('sets up the session', () => {
|
||||
render(<NewSession sessionID={testSessionID} />);
|
||||
render(
|
||||
<LocationProvider history={history}>
|
||||
<NewSession />
|
||||
</LocationProvider>
|
||||
);
|
||||
|
||||
expect(useSessionContext).toBeCalled();
|
||||
expect(setupSessionMock).toBeCalledWith('sessionid1234');
|
||||
|
@ -19,7 +31,11 @@ it('sets up the session', () => {
|
|||
|
||||
it('redirects to the correct location when rp_postauth_redirect is set', async () => {
|
||||
localStorage.setItem('rp_postauth_redirect', '/hello_world');
|
||||
render(<NewSession sessionID={testSessionID} />);
|
||||
render(
|
||||
<LocationProvider history={history}>
|
||||
<NewSession />
|
||||
</LocationProvider>
|
||||
);
|
||||
|
||||
const bounceLink = screen.getByText("If you aren't redirected soon, click here.");
|
||||
expect(bounceLink.getAttribute('href')).toBe('/hello_world');
|
||||
|
@ -27,7 +43,11 @@ it('redirects to the correct location when rp_postauth_redirect is set', async (
|
|||
|
||||
it('redirects to the correct location by default', async () => {
|
||||
localStorage.setItem('rp_postauth_redirect', '/servers');
|
||||
render(<NewSession sessionID={testSessionID} />);
|
||||
render(
|
||||
<LocationProvider history={history}>
|
||||
<NewSession />
|
||||
</LocationProvider>
|
||||
);
|
||||
|
||||
const bounceLink = screen.getByText("If you aren't redirected soon, click here.");
|
||||
expect(bounceLink.getAttribute('href')).toBe('/servers');
|
||||
|
|
|
@ -6,7 +6,7 @@ import * as React from 'react';
|
|||
import { useSessionContext } from '../../contexts/session/SessionContext';
|
||||
import { Title } from '../../utils/metaTitle';
|
||||
|
||||
const NewSession = (props: { sessionID: string }) => {
|
||||
const NewSession = () => {
|
||||
const { setupSession, sessionID } = useSessionContext();
|
||||
const [postauthUrl, setPostauthUrl] = React.useState('/servers');
|
||||
const navigate = useNavigate();
|
||||
|
|
Loading…
Add table
Reference in a new issue