From 7fe991025f4f4830c96b4c014fad88ed627f98da Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Fri, 6 Sep 2024 09:57:26 -0500 Subject: [PATCH] Disable tour redirects until tools go live --- README.md | 1 + next.config.js | 1 + pages/accountLists.page.test.tsx | 51 +++++++++++++++++++-- pages/accountLists.page.tsx | 2 +- src/components/Setup/SetupProvider.test.tsx | 16 +++++++ src/components/Setup/SetupProvider.tsx | 10 +++- 6 files changed, 75 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7967b4925..4eb7ca1343 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/next.config.js b/next.config.js index 86d0e4f0ca..07e0763708 100644 --- a/next.config.js +++ b/next.config.js @@ -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: { diff --git a/pages/accountLists.page.test.tsx b/pages/accountLists.page.test.tsx index ac42776545..f035ff37d0 100644 --- a/pages/accountLists.page.test.tsx +++ b/pages/accountLists.page.test.tsx @@ -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'; @@ -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(); @@ -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({ @@ -56,7 +99,7 @@ describe('Account Lists page', () => { }); const { props, redirect } = (await getServerSideProps( - context as GetServerSidePropsContext, + context, )) as GetServerSidePropsReturn; expect(props).toBeUndefined(); @@ -81,7 +124,7 @@ describe('Account Lists page', () => { }); const { props, redirect } = (await getServerSideProps( - context as GetServerSidePropsContext, + context, )) as GetServerSidePropsReturn; const { getByText } = render( diff --git a/pages/accountLists.page.tsx b/pages/accountLists.page.tsx index cc63d09f51..b218129566 100644 --- a/pages/accountLists.page.tsx +++ b/pages/accountLists.page.tsx @@ -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: { diff --git a/src/components/Setup/SetupProvider.test.tsx b/src/components/Setup/SetupProvider.test.tsx index caead16308..18fd0d69eb 100644 --- a/src/components/Setup/SetupProvider.test.tsx +++ b/src/components/Setup/SetupProvider.test.tsx @@ -53,6 +53,10 @@ const TestComponent: React.FC = ({ ); describe('SetupProvider', () => { + beforeEach(() => { + process.env.DISABLE_SETUP_TOUR = undefined; + }); + it('renders child content', () => { const { getByText } = render( , @@ -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( + , + ); + + await waitFor(() => + expect(getByTestId('setting-up')).toHaveTextContent('false'), + ); + }); }); }); diff --git a/src/components/Setup/SetupProvider.tsx b/src/components/Setup/SetupProvider.tsx index bf0d1489d6..b84974af97 100644 --- a/src/components/Setup/SetupProvider.tsx +++ b/src/components/Setup/SetupProvider.tsx @@ -37,7 +37,11 @@ export const SetupProvider: React.FC = ({ children }) => { const { push, pathname } = useRouter(); useEffect(() => { - if (!data || pathname === '/setup/start') { + if ( + !data || + pathname === '/setup/start' || + process.env.DISABLE_SETUP_TOUR === 'true' + ) { return; } @@ -60,6 +64,10 @@ export const SetupProvider: React.FC = ({ children }) => { return undefined; } + if (process.env.DISABLE_SETUP_TOUR === 'true') { + return false; + } + return ( data.userOptions.some( (option) => option.key === 'setup_position' && option.value !== '',