Skip to content

Commit

Permalink
✅ [#3300] Add tests for product auto-select
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Sep 4, 2023
1 parent 3a280cf commit 42206bc
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,40 @@ describe('The create appointment wrapper', () => {
expect(screen.queryByRole('heading', {name: 'Contact details'})).not.toBeInTheDocument();
});
});

describe('Preselecting a product via querystring', () => {
it('displays the preselected product in the dropdown', async () => {
mswServer.use(mockSubmissionPost(buildSubmission({steps: []})), mockAppointmentProductsGet);

renderApp('/?product=166a5c79');

const productDropdown = await screen.findByRole('combobox');
expect(productDropdown).toBeVisible();
// and the product should be auto selected
expect(await screen.findByText('Paspoort aanvraag')).toBeVisible();
});

it('does not crash on invalid product IDs', async () => {
mswServer.use(mockSubmissionPost(buildSubmission({steps: []})), mockAppointmentProductsGet);
const user = userEvent.setup({delay: null});

renderApp('/?product=bb72a36b-b791');

const productDropdown = await screen.findByRole('combobox');
expect(productDropdown).toBeVisible();
// nothing should be selected
expect(screen.queryByText('Paspoort aanvraag')).not.toBeInTheDocument();
expect(screen.queryByText('Rijbewijs aanvraag (Drivers license)')).not.toBeInTheDocument();
expect(screen.queryByText('Not available with drivers license')).not.toBeInTheDocument();

// now open the dropdown and select a product
await user.click(productDropdown);
await user.keyboard('[ArrowDown]');
const option = await screen.findByText('Paspoort aanvraag');
expect(option).toBeVisible();
await user.click(option);
expect(screen.queryByText('Rijbewijs aanvraag (Drivers license)')).not.toBeInTheDocument();
expect(screen.queryByText('Not available with drivers license')).not.toBeInTheDocument();
expect(await screen.findByText('Paspoort aanvraag')).toBeVisible();
});
});

0 comments on commit 42206bc

Please sign in to comment.