fix new-session tests, remove newly unused param

This commit is contained in:
41666 2022-02-01 00:25:36 -05:00
parent 9f870139ff
commit 872e9b8734
2 changed files with 26 additions and 6 deletions

View file

@ -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');

View file

@ -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();