Merge branch 'main' into dependabot/npm_and_yarn/node-fetch-3.2.0

This commit is contained in:
41666 2022-02-01 00:28:59 -05:00 committed by GitHub
commit af9cdbf796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();