Skip to content

Commit

Permalink
Merge pull request #1142 from CruGlobal/1243276-prepopulate-designati…
Browse files Browse the repository at this point in the history
…on-account

[HS-1243276] Prepopulate donation designation account with only option
  • Loading branch information
canac authored Oct 17, 2024
2 parents ff5531a + c5f502d commit 61e6870
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fragment ContactPartnerAccounts on Contact {

query GetAccountListSalaryOrganization($accountListId: ID!) {
accountList(id: $accountListId) {
id
salaryOrganizationId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { SnackbarProvider } from 'notistack';
import { GqlMockedProvider } from '__tests__/util/graphqlMocking';
import { GetDesignationAccountsQuery } from 'src/components/EditDonationModal/EditDonationModal.generated';
import theme from '../../../../../../../../theme';
import { AddDonation } from './AddDonation';
import { AddDonationMutation } from './AddDonation.generated';
Expand Down Expand Up @@ -149,4 +150,44 @@ describe('AddDonation', () => {
}),
);
}, 20000);

it('auto fills designation account when there is only one option', async () => {
const { getByRole } = render(
<LocalizationProvider dateAdapter={AdapterLuxon}>
<ThemeProvider theme={theme}>
<SnackbarProvider>
<GqlMockedProvider<{
GetDesignationAccounts: GetDesignationAccountsQuery;
}>
mocks={{
GetDesignationAccounts: {
designationAccounts: [
{
designationAccounts: [
{
id: '321',
name: 'Cool Designation Account',
},
],
},
],
},
}}
>
<AddDonation
accountListId={accountListId}
handleClose={handleClose}
/>
</GqlMockedProvider>
</SnackbarProvider>
</ThemeProvider>
</LocalizationProvider>,
);

await waitFor(() =>
expect(
getByRole('combobox', { name: 'Designation Account' }),
).toHaveValue('Cool Designation Account (321)'),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export const AddDonation = ({
appealAmount: null,
appealId: null,
currency: accountListData?.accountList.currency ?? '',
designationAccountId: '',
designationAccountId:
designationAccounts?.length === 1 ? designationAccounts[0].id : '',
donationDate: DateTime.local().startOf('day'),
donorAccountId: '',
memo: null,
Expand Down Expand Up @@ -411,7 +412,7 @@ export const AddDonation = ({
({ id }) => id === accountId,
);
return account
? `${account?.name} (${account.id}) `
? `${account?.name} (${account.id})`
: '';
}}
renderInput={(params): ReactElement => (
Expand Down

0 comments on commit 61e6870

Please sign in to comment.