From fcbf149d6b69b1a320d40f88dc573839b2ac3237 Mon Sep 17 00:00:00 2001 From: Vincent de Graaf Date: Tue, 12 Dec 2023 11:10:15 +0100 Subject: [PATCH] [fix-5575]: sorting chevron (#2783) * Sorting options styling * Fix tests --- .../__tests__/IncidentOverviewTitle.test.js | 4 ++-- .../components/List/index.test.tsx | 4 ++-- .../components/List/index.tsx | 6 ++--- .../components/SortIcon/SortIcon.test.tsx | 24 +++++++++++++++++-- .../components/SortIcon/SortIcon.tsx | 18 ++++++++------ .../IncidentOverviewPage/contants.ts | 16 ++++++------- .../containers/IncidentOverviewPage/utils.ts | 12 ++++++++-- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/signals/incident-management/containers/IncidentOverviewPage/components/IncidentOverviewTitle/__tests__/IncidentOverviewTitle.test.js b/src/signals/incident-management/containers/IncidentOverviewPage/components/IncidentOverviewTitle/__tests__/IncidentOverviewTitle.test.js index 254579cfc1..3a6802742c 100644 --- a/src/signals/incident-management/containers/IncidentOverviewPage/components/IncidentOverviewTitle/__tests__/IncidentOverviewTitle.test.js +++ b/src/signals/incident-management/containers/IncidentOverviewPage/components/IncidentOverviewTitle/__tests__/IncidentOverviewTitle.test.js @@ -139,7 +139,7 @@ describe('containers/IncidentOverviewTitle', () => { expect( screen.getByText('Zoekresultaten voor "Foo bar"') ).toBeInTheDocument() - expect(screen.getByText('Sorteer op datum (oud-nieuw)')).toBeInTheDocument() + expect(screen.getByText('Sorteer op datum (nieuw-oud)')).toBeInTheDocument() }) it('should provide the IncidentOverviewTitle component with sort information', () => { @@ -155,7 +155,7 @@ describe('containers/IncidentOverviewTitle', () => { ) ) - expect(screen.getByText('Sorteer op datum (nieuw-oud)')).toBeInTheDocument() + expect(screen.getByText('Sorteer op datum (oud-nieuw)')).toBeInTheDocument() const resetBtn = screen.getByText('Wis sortering') diff --git a/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.test.tsx b/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.test.tsx index 923441b055..b8e636fab5 100644 --- a/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.test.tsx +++ b/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.test.tsx @@ -342,7 +342,7 @@ describe('List', () => { userEvent.click(screen.getByRole('columnheader', { name: 'Datum' })) - expect(orderingChangedActionMock).toHaveBeenCalledWith('created_at') + expect(orderingChangedActionMock).toHaveBeenCalledWith('-created_at') }) it('should sort by clicking on the column header and pick the opposite reversed', () => { @@ -352,7 +352,7 @@ describe('List', () => { userEvent.click(screen.getByRole('columnheader', { name: 'Datum' })) - expect(orderingChangedActionMock).toHaveBeenCalledWith('-created_at') + expect(orderingChangedActionMock).toHaveBeenCalledWith('created_at') }) it('should not sort when sorting is disabled except date', () => { diff --git a/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.tsx b/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.tsx index 7ade8784b3..d19b9f2345 100644 --- a/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.tsx +++ b/src/signals/incident-management/containers/IncidentOverviewPage/components/List/index.tsx @@ -45,7 +45,7 @@ import { } from './styles' import { useIncidentManagementContext } from '../../../../context' import { SortOptionLabels, SortOptions } from '../../contants' -import compareSortOptions from '../../utils' +import { compareSortOptions } from '../../utils' import ThSort from '../Th' export const getDaysOpen = (incident: IncidentListItem) => { @@ -141,7 +141,7 @@ const List: FunctionComponent = ({ = ({ Dag { /> ) - expect(screen.getByTestId('chevron-up')).toBeInTheDocument() + expect(screen.getByTestId('chevron-down')).toBeInTheDocument() }) it('should render a sort icon for created at desc when its asc', () => { @@ -26,7 +26,7 @@ describe('SortIcon', () => { /> ) - expect(screen.getByTestId('chevron-down')).toBeInTheDocument() + expect(screen.getByTestId('chevron-up')).toBeInTheDocument() }) it('should render a sort icon for id when its desc', () => { @@ -74,6 +74,26 @@ describe('SortIcon', () => { expect(screen.getByTestId('chevron-up')).toBeInTheDocument() }) + it('should render a sort icon for priority desc', () => { + const { rerender } = render( + + ) + + expect(screen.getByTestId('chevron-down')).toBeInTheDocument() + + rerender( + + ) + + expect(screen.getByTestId('chevron-up')).toBeInTheDocument() + }) + it('should return null when there is no match between sortOption and selectedSortOption', () => { render( + ) + } + const rotate = selectedSortOption?.startsWith('-') return ( { + /** Priority is based on alphabetical order, therefore chevron should be reversed. */ + return ( + sortOption === SortOptions.PRIORITY_ASC || + sortOption === SortOptions.PRIORITY_DESC + ) +}