Skip to content

Commit

Permalink
fix: first visit redirect (#859)
Browse files Browse the repository at this point in the history
* fix: first visit redirect

* chore: update tests for first visit
  • Loading branch information
adamstankiewicz authored Oct 20, 2023
1 parent 8413a67 commit 57b3161
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useEffect } from 'react';
import { Redirect } from 'react-router-dom';
import { Redirect, useParams } from 'react-router-dom';
import Cookies from 'universal-cookie';

const EnterpriseLearnerFirstVisitRedirect = () => {
const { enterpriseSlug } = useParams();

const cookies = new Cookies();

const isFirstVisit = () => {
Expand All @@ -17,7 +19,7 @@ const EnterpriseLearnerFirstVisitRedirect = () => {
});

if (isFirstVisit()) {
return <Redirect to="/r/search" />;
return <Redirect to={`/${enterpriseSlug}/search`} />;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const TEST_ENTERPRISE = {
slug: 'test-enterprise',
};

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn().mockReturnValue({
enterpriseSlug: TEST_ENTERPRISE.slug,
}),
}));

describe('<EnterpriseLearnerFirstVisitRedirect />', () => {
beforeEach(() => {
const cookies = new Cookies();
Expand All @@ -20,7 +27,7 @@ describe('<EnterpriseLearnerFirstVisitRedirect />', () => {

test('redirects to search if user is visiting for the first time.', async () => {
const { history } = renderWithRouter(<EnterpriseLearnerFirstVisitRedirect />, { route: `/${TEST_ENTERPRISE.slug}` });
expect(history.location.pathname).toEqual('/r/search');
expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE.slug}/search`);
});

test('Does not redirect the returning user to search.', async () => {
Expand Down

0 comments on commit 57b3161

Please sign in to comment.