Skip to content

Commit

Permalink
Adding tests to ensure the relationship code behaves as it should on …
Browse files Browse the repository at this point in the history
…the modal
  • Loading branch information
dr-bizz committed Jan 7, 2025
1 parent 4363334 commit b9c90ce
Showing 1 changed file with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,21 @@ const newContactMock = gqlMock<ContactDonorAccountsFragment>(

interface ComponentsProps {
isNewContact?: boolean;
showRelationshipCode?: boolean;
}

const Components = ({ isNewContact = false }: ComponentsProps) => (
const Components = ({
isNewContact = false,
showRelationshipCode = false,
}: ComponentsProps) => (
<LocalizationProvider dateAdapter={AdapterLuxon}>
<TestRouter>
<SnackbarProvider>
<ThemeProvider theme={theme}>
<GqlMockedProvider onCall={mutationSpy}>
<EditPartnershipInfoModal
contact={isNewContact ? newContactMock : contactMock}
showRelationshipCode={showRelationshipCode}
handleClose={handleClose}
/>
</GqlMockedProvider>
Expand Down Expand Up @@ -538,4 +543,52 @@ describe('EditPartnershipInfoModal', () => {
}),
);
});

describe('Relationship code', () => {
it('should not render relationshipCode', async () => {
const { queryByRole } = render(<Components />);

await waitFor(() => {
expect(mutationSpy).toHaveGraphqlOperation('UserOrganizationAccounts');
});

expect(
queryByRole('textbox', {
name: 'Relationship Code',
}),
).not.toBeInTheDocument();
});

it('should render relationshipCode', () => {
const { getByRole } = render(<Components showRelationshipCode />);

expect(
getByRole('textbox', {
name: 'Relationship Code',
}),
).toBeInTheDocument();
});

// Remove skip this when the UpdateContact mutation operation is updated to include the relationshipCode
it.skip('should update relationshipCode', async () => {
const { findByRole, getByText } = render(
<Components includeCruSwitzerland />,
);

const relationshipCode = await findByRole('textbox', {
name: 'Relationship Code',
});
userEvent.clear(relationshipCode);
userEvent.type(relationshipCode, '1234');
userEvent.click(getByText('Save'));

await waitFor(() =>
expect(mutationSpy).toHaveGraphqlOperation('UpdateContactPartnership', {
attributes: {
relationshipCode: '1234',
},
}),
);
});
});
});

0 comments on commit b9c90ce

Please sign in to comment.