Skip to content

Commit bd50c90

Browse files
committed
only render critical mode if spares is defined #1656
1 parent 0ab1735 commit bd50c90

19 files changed

+1324
-336
lines changed

cypress/e2e/with_api/catalogueCategories/functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,15 @@ export const addCatalogueCategories = (ignoreChecks?: boolean) => {
258258
};
259259

260260
export const editCatalogueCategories = () => {
261-
cy.findByRole('button', { name: 'navigate to catalogue home' }).click();
262-
cy.findByText('Spherical Lenses').should('not.exist');
261+
cy.get('body').type('{esc}');
263262
cy.intercept({
264263
method: 'GET',
265264
url: '**/catalogue-categories?parent_id=null',
266265
}).as('getCatalogueCategoryDataRoot');
266+
cy.findByRole('button', { name: 'navigate to catalogue home' }).click();
267267
cy.wait('@getCatalogueCategoryDataRoot', { timeout: 10000 });
268+
cy.findByText('Spherical Lenses').should('not.exist');
269+
268270
cy.findByText('Lenses').should('exist');
269271

270272
modifyCatalogueCategory({

cypress/e2e/with_api/catalogueItems/functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export const copyToCatalogueItems = (values: { checkedItems: string[] }) => {
254254
}
255255
cy.go('back');
256256
cy.go('back');
257+
cy.go('back');
257258
};
258259

259260
export const moveToCatalogueItems = (values: { checkedItems: string[] }) => {
@@ -454,9 +455,10 @@ export const downloadFile = (
454455
cy.findByLabelText(`Download ${fileName} attachment`).click();
455456
}
456457

457-
cy.findByRole('dialog').should('be.visible');
458+
cy.findByRole('dialog').should('exist');
458459

459460
cy.findByRole('button', { name: 'Continue' }).click();
461+
cy.findByRole('dialog').should('not.exist');
460462
};
461463

462464
export const deleteFile = (
@@ -476,7 +478,7 @@ export const deleteFile = (
476478
cy.findByLabelText(`Delete attachment ${fileName}`).click();
477479
}
478480

479-
cy.findByRole('dialog').should('be.visible');
481+
cy.findByRole('dialog').should('exist');
480482

481483
cy.findByRole('button', { name: 'Continue' }).click();
482484
});

cypress/e2e/with_mock_data/catalogueItems.cy.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -436,24 +436,20 @@ describe('Catalogue Items', () => {
436436
cy.findByText('Wavefront Sensors 31').should('exist');
437437
cy.findByText('Wavefront Sensors 30').should('exist');
438438

439-
cy.findByTestId('WarningIcon').should('exist');
440-
cy.findByTestId('WarningIcon').trigger('mouseover');
441-
cy.findByText('Items are running low in this catalogue item').should(
442-
'exist'
443-
);
439+
cy.findByTestId('ErrorIcon').should('exist');
440+
cy.findByTestId('ErrorIcon').trigger('mouseover');
441+
cy.findByText('This catalogue item is critical.').should('exist');
444442
});
445443

446444
it('displays the catalogue item landing page (Criticality)', () => {
447445
cy.visit('/catalogue/6/items/10');
448446

449447
cy.setMode({ critical: true });
450448

451-
cy.findByTestId('WarningIcon').should('exist');
452-
cy.findByTestId('WarningIcon').trigger('mouseover');
453-
cy.findByText('Items are running low in this catalogue item').should(
454-
'exist'
455-
);
456-
cy.findAllByText('-4.55').should('have.length', 2);
449+
cy.findByTestId('ErrorIcon').should('exist');
450+
cy.findByTestId('ErrorIcon').trigger('mouseover');
451+
cy.findByText('This catalogue item is critical.').should('exist');
452+
cy.findAllByText('-4.6').should('have.length', 2);
457453
});
458454

459455
it('navigates to the landing page and navigates back to the table view', () => {
@@ -529,8 +525,6 @@ describe('Catalogue Items', () => {
529525
cy.url().should('contain', '/manufacturers/1');
530526
});
531527

532-
533-
534528
it('checks the href property of the manufacturer link', () => {
535529
cy.findByRole('button', { name: 'Show/Hide columns' }).click();
536530
cy.findByText('Hide all').click();
@@ -785,6 +779,7 @@ describe('Catalogue Items', () => {
785779
});
786780

787781
it('check table state persists on page reload', () => {
782+
cy.setMode({ critical: false });
788783
cy.findByText('Cameras 1').should('exist');
789784
cy.findByRole('button', { name: 'Clear Filters' }).should('be.disabled');
790785

@@ -795,7 +790,7 @@ describe('Catalogue Items', () => {
795790
cy.findByRole('link', { name: 'Cameras 15' }).should('exist');
796791
cy.location('search').should(
797792
'eq',
798-
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJMoGAngA5NoIAM4YATglr4W7TkJABhBsXFoRAAgCMAVhABffQF19QA'
793+
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJMoGAngA5NoIAM4YATglr4W7TkJABhBsXFoRAAgCMAVhABffQF1WYAGoIR3dFjxEyFGmHHFMxJAH0MCRjABmOCLEhkA'
799794
);
800795

801796
cy.reload();
@@ -804,11 +799,12 @@ describe('Catalogue Items', () => {
804799
cy.findByText('Cameras 1').should('not.exist');
805800
cy.location('search').should(
806801
'eq',
807-
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJMoGAngA5NoIAM4YATglr4W7TkJABhBsXFoRAAgCMAVhABffQF19QA'
802+
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJMoGAngA5NoIAM4YATglr4W7TkJABhBsXFoRAAgCMAVhABffQF1WYAGoIR3dFjxEyFGmHHFMxJAH0MCRjABmOCLEhkA'
808803
);
809804
});
810805

811806
it('can load and clear date filters', () => {
807+
cy.setMode({ critical: true });
812808
cy.visit(
813809
'/catalogue/4/items?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0luSCAZgsUgPoYKXEgA0IANxwkY8EBgCeABx7QQSTD35DsIuQCYADOoAsAWk0BGAwGYAKps3RL1zdUuaAWiAC%2BvUJJmoAzhgBOCAB2%2BHyCwrIgrgC6LjFAA'
814810
);
@@ -967,7 +963,9 @@ describe('Catalogue Items', () => {
967963
it('can navigate to an items page from the table view', () => {
968964
cy.visit('/catalogue/5');
969965

970-
cy.findAllByRole('link', { name: 'Click here' }).eq(0).click();
966+
cy.findAllByRole('link', { name: 'Click here' }).first().scrollIntoView();
967+
968+
cy.findAllByRole('link', { name: 'Click here' }).first().click();
971969

972970
cy.url().should('contain', 'catalogue/5/items/89/items');
973971
});
@@ -1131,7 +1129,7 @@ describe('Catalogue Items', () => {
11311129
number_of_spares: 0,
11321130
number_of_spares_required: null,
11331131
criticality: null,
1134-
is_flagged: null,
1132+
is_flagged: false,
11351133
})
11361134
);
11371135
expect(JSON.stringify(await patchRequests[1].json())).equal(
@@ -1160,7 +1158,7 @@ describe('Catalogue Items', () => {
11601158
number_of_spares: 0,
11611159
number_of_spares_required: null,
11621160
criticality: null,
1163-
is_flagged: null,
1161+
is_flagged: false,
11641162
})
11651163
);
11661164
});

cypress/e2e/with_mock_data/items.cy.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ describe('Items', () => {
5555

5656
cy.setMode({ critical: true });
5757

58-
cy.findByTestId('WarningIcon').should('exist');
59-
cy.findByTestId('WarningIcon').trigger('mouseover');
60-
cy.findByText('Items are running low in this catalogue item').should(
61-
'exist'
62-
);
58+
cy.findByTestId('ErrorIcon').should('exist');
59+
cy.findByTestId('ErrorIcon').trigger('mouseover');
60+
cy.findByText('This catalogue item is critical.').should('exist');
6361
cy.findAllByText('(Item Details)').should('exist');
6462
});
6563

src/catalogue/category/catalogueCard.component.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
type MRT_Row,
1313
type MRT_TableInstance,
1414
} from 'material-react-table';
15+
import React from 'react';
1516
import { Link } from 'react-router';
1617
import { CatalogueCategory } from '../../api/api.types';
18+
import { APISettingsContext } from '../../apiConfigProvider.component';
1719
import CriticalityTooltipIcon from '../../common/criticalityTooltipIcon.component';
1820
import { useAppSelector } from '../../state/hook';
1921
import { selectCriticality } from '../../state/slices/criticalitySlice';
@@ -41,6 +43,9 @@ export const getCriticalityLabel = (isCritical: boolean | null) => {
4143

4244
function CatalogueCard(props: CatalogueCardProps) {
4345
const { table, card } = props;
46+
47+
const apiSettings = React.useContext(APISettingsContext);
48+
const isSparesDefinitionDefined = !!apiSettings.spares;
4449
const selectedCategories = table
4550
.getSelectedRowModel()
4651
.rows.map((row) => row.original);
@@ -74,7 +79,9 @@ function CatalogueCard(props: CatalogueCardProps) {
7479
backgroundColor: isSelected
7580
? table.options.mrtTheme.selectedRowBackgroundColor
7681
: undefined,
77-
...(isCriticalMode && criticalityCardStyle({ theme, showFlagged })),
82+
...(isCriticalMode &&
83+
isSparesDefinitionDefined &&
84+
criticalityCardStyle({ theme, showFlagged })),
7885
})}
7986
>
8087
<CardActions>
@@ -88,7 +95,7 @@ function CatalogueCard(props: CatalogueCardProps) {
8895
/>
8996
</CardActions>
9097
<CardContent sx={{ display: 'flex', alignItems: 'center', padding: 0 }}>
91-
{isCriticalMode && (
98+
{isCriticalMode && isSparesDefinitionDefined && (
9299
<CriticalityTooltipIcon
93100
showFlagged={showFlagged}
94101
label={getCriticalityLabel(showFlagged)}

src/catalogue/category/catalogueCardView.component.test.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { screen, waitFor } from '@testing-library/react';
22
import userEvent, { UserEvent } from '@testing-library/user-event';
33
import { http, HttpResponse } from 'msw';
44
import { CatalogueCategory } from '../../api/api.types';
5+
import APIConfigProvider from '../../apiConfigProvider.component';
56
import { server } from '../../mocks/server';
67
import { URLPathKeyType } from '../../paths';
78
import { RootState } from '../../state/store';
@@ -17,7 +18,9 @@ describe('CardView', () => {
1718
preloadedState?: Partial<RootState>
1819
) => {
1920
return renderComponentWithRouterProvider(
20-
<CardView />,
21+
<APIConfigProvider>
22+
<CardView />
23+
</APIConfigProvider>,
2124
urlPathKey || 'catalogue',
2225
path || '/catalogue',
2326
preloadedState
@@ -93,7 +96,7 @@ describe('CardView', () => {
9396
expect(screen.queryByRole('progressbar')).not.toBeInTheDocument()
9497
);
9598

96-
const addButton = screen.getByRole('button', {
99+
const addButton = await screen.findByRole('button', {
97100
name: 'Add Catalogue Category',
98101
});
99102
await user.click(addButton);
@@ -354,6 +357,26 @@ describe('CardView', () => {
354357
).toBeInTheDocument();
355358
});
356359

360+
it('does not show criticality states for catalogue categories and the filter button', async () => {
361+
server.use(
362+
http.get('/v1/settings/spares-definition', () => {
363+
return HttpResponse.json(undefined, { status: 204 });
364+
})
365+
);
366+
createView('/catalogue', undefined, {
367+
criticality: { isCriticalMode: true },
368+
});
369+
370+
await waitFor(() => {
371+
expect(screen.getByText('Beam Characterization')).toBeInTheDocument();
372+
});
373+
await waitFor(() => {
374+
expect(
375+
screen.queryByRole('button', { name: 'Show Critical Categories' })
376+
).not.toBeInTheDocument();
377+
});
378+
});
379+
357380
it('clicks on shows critical Categories filter button', async () => {
358381
createView('/catalogue', undefined, {
359382
criticality: { isCriticalMode: true },
@@ -487,7 +510,7 @@ describe('CardView', () => {
487510
);
488511

489512
await user.click(
490-
screen.getByRole('button', { name: 'Show/Hide filters' })
513+
await screen.findByRole('button', { name: 'Show/Hide filters' })
491514
);
492515

493516
const dropdownButtons = await screen.findAllByTestId('FilterListIcon');

src/catalogue/category/catalogueCardView.component.tsx

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import Grid from '@mui/material/Grid2';
2121
import {
2222
MRT_BottomToolbar,
23+
MRT_Column,
2324
MRT_ColumnDef,
2425
MRT_TopToolbar,
2526
useMaterialReactTable,
@@ -54,6 +55,7 @@ import CatalogueCard from './catalogueCard.component';
5455
import CatalogueCategoryDialog from './catalogueCategoryDialog.component';
5556

5657
import InfoOutlined from '@mui/icons-material/InfoOutlined';
58+
import { APISettingsContext } from '../../apiConfigProvider.component';
5759
import ErrorPage from '../../common/errorPage.component';
5860
import MRTTopTableAlert from '../../common/mrtTopTableAlert.component';
5961
import { useAppSelector } from '../../state/hook';
@@ -198,6 +200,9 @@ function CatalogueCardView() {
198200
!catalogueCategoryId ? 'null' : catalogueCategoryId
199201
);
200202

203+
const apiSettings = React.useContext(APISettingsContext);
204+
const isSparesDefinitionDefined = !!apiSettings.spares;
205+
201206
const catalogueCategoryNames: string[] = catalogueCategoryData
202207
? catalogueCategoryData.map((item) => item.name)
203208
: [];
@@ -323,25 +328,34 @@ function CatalogueCardView() {
323328
filterSelectOptions: ['Catalogue Categories', 'Catalogue Items'],
324329
enableGrouping: false,
325330
},
326-
{
327-
header: 'Is Critical',
328-
Header: ({ column }) => (
329-
<Box sx={{ display: 'flex', alignItems: 'center' }}>
330-
<Tooltip title={CriticalTooltipText}>
331-
<InfoOutlined sx={{ mr: 1 }} fontSize="small" />
332-
</Tooltip>
333-
<OverflowTip>{column.columnDef.header}</OverflowTip>
334-
</Box>
335-
),
336-
accessorFn: (row: CatalogueCategory) => (row.is_flagged ? 'Yes' : 'No'),
337-
id: 'is_flagged',
338-
filterVariant: COLUMN_FILTER_VARIANTS.boolean,
339-
enableColumnFilterModes: false,
340-
size: 200,
341-
filterSelectOptions: COLUMN_FILTER_BOOLEAN_OPTIONS,
342-
},
331+
...(isSparesDefinitionDefined
332+
? [
333+
{
334+
header: 'Is Critical',
335+
Header: ({
336+
column,
337+
}: {
338+
column: MRT_Column<CatalogueCategory, unknown>;
339+
}) => (
340+
<Box sx={{ display: 'flex', alignItems: 'center' }}>
341+
<Tooltip title={CriticalTooltipText}>
342+
<InfoOutlined sx={{ mr: 1 }} fontSize="small" />
343+
</Tooltip>
344+
<OverflowTip>{column.columnDef.header}</OverflowTip>
345+
</Box>
346+
),
347+
accessorFn: (row: CatalogueCategory) =>
348+
row.is_flagged ? 'Yes' : 'No',
349+
id: 'is_flagged',
350+
filterVariant: COLUMN_FILTER_VARIANTS.boolean,
351+
enableColumnFilterModes: false,
352+
size: 200,
353+
filterSelectOptions: COLUMN_FILTER_BOOLEAN_OPTIONS,
354+
},
355+
]
356+
: []),
343357
];
344-
}, [propertyNames]);
358+
}, [isSparesDefinitionDefined, propertyNames]);
345359

346360
const initialColumnFilterFnState = React.useMemo(() => {
347361
return getInitialColumnFilterFnState(columns);
@@ -458,7 +472,7 @@ function CatalogueCardView() {
458472
</Button>
459473
</>
460474
)}
461-
{isCriticalMode && (
475+
{isCriticalMode && isSparesDefinitionDefined && (
462476
<Button
463477
sx={{ mx: 0.5 }}
464478
startIcon={

0 commit comments

Comments
 (0)