From 0bbd592b0c93c95c021c60cbce5f2d742cf03e9e Mon Sep 17 00:00:00 2001 From: pearl-truss <67110378+pearl-truss@users.noreply.github.com> Date: Fri, 3 Jan 2025 11:23:31 -0500 Subject: [PATCH] filter withdrawn rates out of linkedRateSelect component (#3041) --- .../LinkRateSelect/LinkRateSelect.tsx | 12 +- .../RateDetails/RateDetails.test.tsx | 143 ++++++++++++++++++ 2 files changed, 151 insertions(+), 4 deletions(-) diff --git a/services/app-web/src/pages/LinkYourRates/LinkRateSelect/LinkRateSelect.tsx b/services/app-web/src/pages/LinkYourRates/LinkRateSelect/LinkRateSelect.tsx index 72be66fe5f..48f3d0444a 100644 --- a/services/app-web/src/pages/LinkYourRates/LinkRateSelect/LinkRateSelect.tsx +++ b/services/app-web/src/pages/LinkYourRates/LinkRateSelect/LinkRateSelect.tsx @@ -58,17 +58,21 @@ export const LinkRateSelect = ({ const [_field, _meta, helpers] = useField({ name }) // useField only relevant for non-autofill implementations const rates = data?.indexRates.edges.map((e) => e.node) || [] - // Sort rates by latest submission in desc order and remove withdrawn - rates + // Do not display withdrawn rates as an option of a linked rate to select + const updatedRates = rates .sort( (a, b) => new Date(b.revisions[0].submitInfo?.updatedAt).getTime() - new Date(a.revisions[0].submitInfo?.updatedAt).getTime() ) - .filter((rate) => rate.withdrawInfo === undefined) + .filter( + (rate) => + rate.withdrawInfo === undefined || + rate.consolidatedStatus !== 'WITHDRAWN' + ) - const rateNames: LinkRateOptionType[] = rates.map((rate) => { + const rateNames: LinkRateOptionType[] = updatedRates.map((rate) => { const revision = rate.revisions[0] const rateProgramIDs = revision.formData.rateProgramIDs.length > 0 diff --git a/services/app-web/src/pages/StateSubmission/RateDetails/RateDetails.test.tsx b/services/app-web/src/pages/StateSubmission/RateDetails/RateDetails.test.tsx index 1188b7e3fa..40d7b7f4c8 100644 --- a/services/app-web/src/pages/StateSubmission/RateDetails/RateDetails.test.tsx +++ b/services/app-web/src/pages/StateSubmission/RateDetails/RateDetails.test.tsx @@ -1051,6 +1051,149 @@ describe('RateDetails', () => { expect(dropdownOptions[2]).toHaveTextContent('Third-Position-Rate') }) + it('omits withdrawn rates from the dropdown options', async () => { + const rates: Rate[] = [ + { + ...rateDataMock(), + id: 'test-id-123', + stateNumber: 1, + consolidatedStatus: 'WITHDRAWN', + reviewStatus: 'WITHDRAWN', + revisions: [ + { + ...rateRevisionDataMock(), + submitInfo: { + __typename: 'UpdateInformation', + updatedAt: new Date('2022-04-10'), + updatedBy: { + email: 'aang@example.com', + role: 'ADMIN_USER', + familyName: 'Hotman', + givenName: 'Iroh', + }, + updatedReason: 'Resubmit', + }, + formData: { + ...rateRevisionDataMock().formData, + rateCertificationName: 'Third-Position-Rate', + }, + }, + ], + }, + { + ...rateDataMock(), + id: 'test-id-124', + stateNumber: 2, + revisions: [ + { + ...rateRevisionDataMock(), + submitInfo: { + __typename: 'UpdateInformation', + updatedAt: new Date('2024-04-10'), + updatedBy: { + email: 'aang@example.com', + role: 'STATE_USER', + familyName: 'Airman', + givenName: 'Aang', + }, + updatedReason: 'Resubmit', + }, + formData: { + ...rateRevisionDataMock().formData, + rateCertificationName: 'First-Position-Rate', + }, + }, + ], + }, + { + ...rateDataMock(), + id: 'test-id-125', + stateNumber: 3, + revisions: [ + { + ...rateRevisionDataMock(), + submitInfo: { + __typename: 'UpdateInformation', + updatedAt: new Date('2024-04-08'), + updatedBy: { + email: 'aang@example.com', + role: 'STATE_USER', + familyName: 'Airman', + givenName: 'Aang', + }, + updatedReason: 'Resubmit', + }, + formData: { + ...rateRevisionDataMock().formData, + rateCertificationName: 'Second-Position-Rate', + }, + }, + ], + }, + ] + + const { user } = renderWithProviders( + + } + /> + , + { + apolloProvider: { + mocks: [ + indexRatesMockSuccess(undefined, rates), + fetchCurrentUserMock({ statusCode: 200 }), + fetchContractMockSuccess({ + contract: mockContractWithLinkedRateDraft(), + }), + ], + }, + routerProvider: { + route: `/submissions/test-abc-123/edit/rate-details`, + }, + featureFlags: { + 'rate-edit-unlock': false, + }, + } + ) + + //Making sure page loads + await screen.findByText('Rate Details') + expect( + screen.getByText( + 'Was this rate certification included with another submission?' + ) + ).toBeInTheDocument() + + //Click the yes button and assert it's clickable and checked + const yesRadioButton = screen.getByRole('radio', { + name: 'Yes, this rate certification is part of another submission', + }) + expect(yesRadioButton).toBeInTheDocument() + await user.click(yesRadioButton) + expect(yesRadioButton).toBeChecked() + + // Assert the dropdown has rendered + await waitFor(() => { + expect( + screen.getByText('Which rate certification was it?') + ).toBeInTheDocument() + expect(screen.getByRole('combobox')).toBeInTheDocument() + }) + + // Assert the options menu is open when clicked + const dropdown = screen.getByRole('combobox') + expect(dropdown).toBeInTheDocument() + await user.click(dropdown) + const dropdownMenu = screen.getByRole('listbox') + expect(dropdownMenu).toBeInTheDocument() + + // Assert options are present + const dropdownOptions = screen.getAllByRole('option') + expect(dropdownOptions).toHaveLength(2) + }) + it('removes the selected option from the dropdown list', async () => { const rateID = 'test-abc-123' const { user } = renderWithProviders(