Skip to content

Commit

Permalink
UILD-472: Comparison fix - deselect checkboxes when deselecting a res…
Browse files Browse the repository at this point in the history
…ource on the modal (#74)
  • Loading branch information
SKarolFolio authored Jan 14, 2025
1 parent 6117130 commit a17f056
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/components/Comparison/Comparison.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import './Comparison.scss';
export const Comparison = () => {
const { formatMessage } = useIntl();
const { previewContent, setPreviewContent, resetPreviewContent } = useInputsState();
const { resetSelectedInstances } = useSearchState();
const { setSelectedInstances, resetSelectedInstances } = useSearchState();
const { resetFullDisplayComponentType } = useUIState();
const { navigateToEditPage } = useNavigateToEditPage();
const [currentPage, setCurrentPage] = useState(0);
Expand All @@ -30,6 +30,7 @@ export const Comparison = () => {

const handleRemoveComparisonItem = (id: string) => {
setPreviewContent(prev => prev.filter(({ id: prevId }) => prevId !== id));
setSelectedInstances(prev => prev.filter(prevId => prevId !== id));
};

const handleNavigateToOwnEditPage = (id: string) => navigateToEditPage(generateEditResourceUrl(id));
Expand Down
25 changes: 18 additions & 7 deletions src/test/__tests__/components/Comparison.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ describe('Comparison', () => {
const resetPreviewContent = jest.fn();
const resetFullDisplayComponentType = jest.fn();
const resetSelectedInstances = jest.fn();
const setSelectedInstances = jest.fn();
const setPreviewContent = jest.fn();

const baseMockState = [
{
store: useInputsStore,
state: { previewContent: [{ id: 'mockId', title: 'mockTitle' }] },
state: { previewContent: [{ id: 'mockId', title: 'mockTitle' }], setPreviewContent },
},
];

const renderWithState = (stateArgs?: StoreWithState[]) => {
stateArgs && setInitialGlobalState(stateArgs);
if (stateArgs) {
setInitialGlobalState(stateArgs);
}

return render(
<RouterProvider
Expand All @@ -60,11 +64,18 @@ describe('Comparison', () => {
});

test('removes an entry', () => {
const { getByTestId, getByText } = renderWithState(baseMockState);
const { getByTestId } = renderWithState([
...baseMockState,
{
store: useSearchStore,
state: { setSelectedInstances },
},
]);

fireEvent.click(getByTestId('remove-comparison-entry'));

expect(getByText('ld.chooseTwoResourcesCompare')).toBeInTheDocument();
expect(setPreviewContent).toHaveBeenCalled();
expect(setSelectedInstances).toHaveBeenCalled();
});

test('closes comparison', async () => {
Expand Down Expand Up @@ -105,9 +116,9 @@ describe('Comparison', () => {
store: useInputsStore,
state: {
previewContent: [
{ id: 'mockId', title: 'mockTitle' },
{ id: 'mockId', title: 'mockTitle' },
{ id: 'mockId', title: 'mockTitle' },
{ id: 'mockId_1', title: 'mockTitle 1' },
{ id: 'mockId_2', title: 'mockTitle 2' },
{ id: 'mockId_3', title: 'mockTitle 3' },
],
},
},
Expand Down

0 comments on commit a17f056

Please sign in to comment.