fix: return the loader after redirect (#37432)

Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
This commit is contained in:
Ahmad Abdolsaheb
2019-10-22 14:28:35 +03:00
committed by mrugesh
parent afeb476818
commit 9337d6ad82
5 changed files with 48 additions and 15 deletions

View File

@@ -7,22 +7,36 @@ import { apiLocation } from '../../config/env.json';
import { ShowSettings } from './ShowSettings';
describe('<ShowSettings />', () => {
it('redirects to signin page when user not logged in', () => {
it('renders to the DOM when user is logged in', () => {
const shallow = new ShallowRenderer();
shallow.render(<ShowSettings {...loggedInProps} />);
expect(navigate).toHaveBeenCalledTimes(0);
const result = shallow.getRenderOutput();
expect(result.type.toString()).toBe('Symbol(react.fragment)');
// Renders Helmet component rather than Loader
expect(result.props.children[0].props.title).toEqual(
'Settings | freeCodeCamp.org'
);
});
it('redirects to sign in page when user is not logged in', () => {
const shallow = new ShallowRenderer();
shallow.render(<ShowSettings {...loggedOutProps} />);
expect(navigate).toHaveBeenCalledTimes(1);
expect(navigate).toHaveBeenCalledWith(
`${apiLocation}/signin?returnTo=settings`
);
expect(true).toBeTruthy();
const result = shallow.getRenderOutput();
// Renders Loader rather than ShowSettings
expect(result.type.displayName).toBe('Loader');
});
});
const navigate = jest.fn();
const loggedOutProps = {
const loggedInProps = {
createFlashMessage: jest.fn(),
hardGoTo: jest.fn(),
isSignedIn: false,
isSignedIn: true,
navigate: navigate,
showLoading: false,
submitNewAbout: jest.fn(),
@@ -37,3 +51,5 @@ const loggedOutProps = {
},
verifyCert: jest.fn()
};
const loggedOutProps = { ...loggedInProps };
loggedOutProps.isSignedIn = false;