Skip to content

Commit

Permalink
Add test that save button is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Aug 30, 2024
1 parent 21ec986 commit 983acac
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions pages/setup/account.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@ const context = {
req: {},
} as unknown as GetServerSidePropsContext;

const mutationSpy = jest.fn();

const TestComponent: React.FC = () => {
const accountListOptions = {
accountLists: {
nodes: [1, 2, 3].map((id) => ({
id: `account-list-${id}`,
name: `Account List ${id}`,
})),
},
};

return (
<TestRouter router={router}>
<GqlMockedProvider onCall={mutationSpy}>
<AccountPage accountListOptions={accountListOptions} />
</GqlMockedProvider>
</TestRouter>
);
};

describe('Setup account page', () => {
it('renders account options, saves default account, and advances to the next page', async () => {
const accountListOptions = {
accountLists: {
nodes: [1, 2, 3].map((id) => ({
id: `account-list-${id}`,
name: `Account List ${id}`,
})),
},
};

const mutationSpy = jest.fn();
const { getByRole } = render(
<TestRouter router={router}>
<GqlMockedProvider onCall={mutationSpy}>
<AccountPage accountListOptions={accountListOptions} />
</GqlMockedProvider>
</TestRouter>,
);
const { getByRole } = render(<TestComponent />);

expect(
getByRole('heading', { name: 'Set default account' }),
Expand All @@ -59,6 +64,16 @@ describe('Setup account page', () => {
'/accountLists/account-list-1/settings/preferences',
);
});

it('disables save button until the user selects an account', () => {
const { getByRole } = render(<TestComponent />);

expect(getByRole('button', { name: 'Continue Tour' })).toBeDisabled();

userEvent.click(getByRole('combobox', { name: 'Account' }));
userEvent.click(getByRole('option', { name: 'Account List 1' }));
expect(getByRole('button', { name: 'Continue Tour' })).not.toBeDisabled();
});
});

describe('getServerSideProps', () => {
Expand Down

0 comments on commit 983acac

Please sign in to comment.