Skip to content

Commit

Permalink
Disable tour redirects until tools go live
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Sep 6, 2024
1 parent 71b6102 commit 7fe9910
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Note: there is a test account you can use. Get this from another developer if yo
- `HS_TASKS_SUGGESTIONS` - Comma-separated IDs of the HelpScout articles to suggest on the tasks page
- `PRIVACY_POLICY_URL` - URL of the privacy policy
- `TERMS_OF_USE_URL` - URL of the terms of use
- `DISABLE_SETUP_TOUR` - Set to `true` to disable starting users on the welcome tour. This should be removed from the codebase once tools are live.

#### Auth provider

Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const config = {
PRIVACY_POLICY_URL: process.env.PRIVACY_POLICY_URL,
TERMS_OF_USE_URL: process.env.TERMS_OF_USE_URL,
DD_ENV: process.env.DD_ENV ?? 'development',
DISABLE_SETUP_TOUR: process.env.DISABLE_SETUP_TOUR,
},
experimental: {
modularizeImports: {
Expand Down
51 changes: 47 additions & 4 deletions pages/accountLists.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { render } from '@testing-library/react';
import { getSession } from 'next-auth/react';
import { I18nextProvider } from 'react-i18next';
import { session } from '__tests__/fixtures/session';
import { UserSetupStageEnum } from 'src/graphql/types.generated';
import makeSsrClient from 'src/lib/apollo/ssrClient';
import i18n from 'src/lib/i18n';
import theme from 'src/theme';
Expand All @@ -22,14 +23,14 @@ interface GetServerSidePropsReturn {
const accountListId = 'accountID1';

describe('Account Lists page', () => {
const context = {};
const context = {} as GetServerSidePropsContext;

describe('NextAuth unauthorized', () => {
it('should redirect to login', async () => {
(getSession as jest.Mock).mockResolvedValue(null);

const { props, redirect } = (await getServerSideProps(
context as GetServerSidePropsContext,
context,
)) as GetServerSidePropsReturn;

expect(props).toBeUndefined();
Expand All @@ -42,9 +43,51 @@ describe('Account Lists page', () => {

describe('NextAuth authorized', () => {
beforeEach(() => {
process.env.DISABLE_SETUP_TOUR = undefined;

(getSession as jest.Mock).mockResolvedValue(session);
});

it('redirects user to the setup tour is user.setup is not null', async () => {
(makeSsrClient as jest.Mock).mockReturnValue({
query: jest.fn().mockResolvedValue({
data: {
user: { id: 'user-1', setup: UserSetupStageEnum.NoAccountLists },
accountLists: { nodes: [] },
},
}),
});

const result = await getServerSideProps(context);
expect(result).toEqual({
redirect: {
destination: '/setup/start',
permanent: false,
},
});
});

it('does not redirect to the setup tour when DISABLE_SETUP_TOUR is true', async () => {
process.env.DISABLE_SETUP_TOUR = 'true';

(makeSsrClient as jest.Mock).mockReturnValue({
query: jest.fn().mockResolvedValue({
data: {
user: { id: 'user-1', setup: UserSetupStageEnum.NoAccountLists },
accountLists: { nodes: [] },
},
}),
});

const result = await getServerSideProps(context);
expect(result).not.toEqual({
redirect: {
destination: '/setup/start',
permanent: false,
},
});
});

it('redirects user to their accountList page if only one accountList', async () => {
(makeSsrClient as jest.Mock).mockReturnValue({
query: jest.fn().mockResolvedValue({
Expand All @@ -56,7 +99,7 @@ describe('Account Lists page', () => {
});

const { props, redirect } = (await getServerSideProps(
context as GetServerSidePropsContext,
context,
)) as GetServerSidePropsReturn;

expect(props).toBeUndefined();
Expand All @@ -81,7 +124,7 @@ describe('Account Lists page', () => {
});

const { props, redirect } = (await getServerSideProps(
context as GetServerSidePropsContext,
context,
)) as GetServerSidePropsReturn;

const { getByText } = render(
Expand Down
2 changes: 1 addition & 1 deletion pages/accountLists.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getServerSideProps = makeGetServerSideProps(async (session) => {
query: GetAccountListsDocument,
});

if (data.user.setup) {
if (data.user.setup && process.env.DISABLE_SETUP_TOUR !== 'true') {
// The user has not finished setting up, so start them on the tour
return {
redirect: {
Expand Down
16 changes: 16 additions & 0 deletions src/components/Setup/SetupProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const TestComponent: React.FC<TestComponentProps> = ({
);

describe('SetupProvider', () => {
beforeEach(() => {
process.env.DISABLE_SETUP_TOUR = undefined;
});

it('renders child content', () => {
const { getByText } = render(
<TestComponent setup={UserSetupStageEnum.NoAccountLists} />,
Expand Down Expand Up @@ -137,5 +141,17 @@ describe('SetupProvider', () => {
expect(getByTestId('setting-up')).toHaveTextContent('false'),
);
});

it('is false when DISABLE_SETUP_TOUR is true', async () => {
process.env.DISABLE_SETUP_TOUR = 'true';

const { getByTestId } = render(
<TestComponent setup={null} setupPosition="start" />,
);

await waitFor(() =>
expect(getByTestId('setting-up')).toHaveTextContent('false'),
);
});
});
});
10 changes: 9 additions & 1 deletion src/components/Setup/SetupProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const SetupProvider: React.FC<Props> = ({ children }) => {
const { push, pathname } = useRouter();

useEffect(() => {
if (!data || pathname === '/setup/start') {
if (
!data ||
pathname === '/setup/start' ||
process.env.DISABLE_SETUP_TOUR === 'true'
) {
return;
}

Expand All @@ -60,6 +64,10 @@ export const SetupProvider: React.FC<Props> = ({ children }) => {
return undefined;
}

if (process.env.DISABLE_SETUP_TOUR === 'true') {
return false;
}

return (
data.userOptions.some(
(option) => option.key === 'setup_position' && option.value !== '',
Expand Down

0 comments on commit 7fe9910

Please sign in to comment.