Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cypress/e2e/with_api/catalogueCategories/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ export const addCatalogueCategories = (ignoreChecks?: boolean) => {
};

export const editCatalogueCategories = () => {
cy.findByRole('button', { name: 'navigate to catalogue home' }).click();
cy.findByText('Spherical Lenses').should('not.exist');
cy.get('body').type('{esc}');
cy.intercept({
method: 'GET',
url: '**/catalogue-categories?parent_id=null',
}).as('getCatalogueCategoryDataRoot');
cy.findByRole('button', { name: 'navigate to catalogue home' }).click();
cy.wait('@getCatalogueCategoryDataRoot', { timeout: 10000 });
cy.findByText('Spherical Lenses').should('not.exist');

cy.findByText('Lenses').should('exist');

modifyCatalogueCategory({
Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/with_api/catalogueItems/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export const copyToCatalogueItems = (values: { checkedItems: string[] }) => {
}
cy.go('back');
cy.go('back');
cy.go('back');
};

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

cy.findByRole('dialog').should('be.visible');
cy.findByRole('dialog').should('exist');

cy.findByRole('button', { name: 'Continue' }).click();
cy.findByRole('dialog').should('not.exist');
};

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

cy.findByRole('dialog').should('be.visible');
cy.findByRole('dialog').should('exist');

cy.findByRole('button', { name: 'Continue' }).click();
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/with_api/systems/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const navigateToItemsTableViaSpares = () => {
cy.findByText('Number of spares').should('exist');
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000);
cy.findByRole('link', { name: '1' }).click();
cy.findAllByRole('link', { name: '1' }).first().click();
cy.findByText('MX432424').should('exist');

// Catalogue items landing page
Expand All @@ -226,7 +226,7 @@ export const navigateToItemsTableViaSpares = () => {
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(100);
cy.findByText('Number of spares').should('exist');
cy.findByRole('link', { name: '1' }).click();
cy.findAllByRole('link', { name: '1' }).first().click();
cy.findByText('MX432424').should('exist');
cy.visit('/systems');
};
47 changes: 41 additions & 6 deletions cypress/e2e/with_mock_data/catalogueItems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Catalogue Items', () => {
it('navigates to items page with spares definition applied', () => {
cy.visit('/catalogue/9/items');

cy.findByRole('link', { name: '1' }).click();
cy.findAllByRole('link', { name: '1' }).first().click();

cy.findByText('dfzqkOJbqifO').should('exist');

Expand All @@ -96,7 +96,7 @@ describe('Catalogue Items', () => {
it('navigates to items page with spares definition applied (from landing page)', () => {
cy.visit('/catalogue/9/items/11');

cy.findByRole('link', { name: '1' }).click();
cy.findAllByRole('link', { name: '1' }).first().click();

cy.findByText('dfzqkOJbqifO').should('exist');

Expand All @@ -113,7 +113,7 @@ describe('Catalogue Items', () => {

cy.findAllByLabelText('Expand').eq(1).click();

cy.findByRole('link', { name: '1' }).click();
cy.findAllByRole('link', { name: '1' }).first().click();

cy.findByText('dfzqkOJbqifO').should('exist');

Expand Down Expand Up @@ -429,6 +429,29 @@ describe('Catalogue Items', () => {
cy.findByText('Cameras 4').should('exist');
});

it('displays the table view correctly (Criticality)', () => {
cy.visit('/catalogue/6');

cy.setMode({ critical: true });
cy.findByText('Wavefront Sensors 31').should('exist');
cy.findByText('Wavefront Sensors 30').should('exist');

cy.findByTestId('ErrorIcon').should('exist');
cy.findByTestId('ErrorIcon').trigger('mouseover');
cy.findByText('This catalogue item is critical.').should('exist');
});

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

cy.setMode({ critical: true });

cy.findByTestId('ErrorIcon').should('exist');
cy.findByTestId('ErrorIcon').trigger('mouseover');
cy.findByText('This catalogue item is critical.').should('exist');
cy.findAllByText('-4.6').should('have.length', 2);
});

it('navigates to the landing page and navigates back to the table view', () => {
cy.findByText('Cameras 1').click();
cy.findByText(
Expand Down Expand Up @@ -502,8 +525,6 @@ describe('Catalogue Items', () => {
cy.url().should('contain', '/manufacturers/1');
});



it('checks the href property of the manufacturer link', () => {
cy.findByRole('button', { name: 'Show/Hide columns' }).click();
cy.findByText('Hide all').click();
Expand Down Expand Up @@ -758,6 +779,7 @@ describe('Catalogue Items', () => {
});

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

Expand Down Expand Up @@ -940,7 +962,14 @@ describe('Catalogue Items', () => {
it('can navigate to an items page from the table view', () => {
cy.visit('/catalogue/5');

cy.findAllByRole('link', { name: 'Click here' }).eq(0).click();
cy.findAllByRole('link', { name: 'Click here' }).first().scrollIntoView();
cy.findAllByRole('link', { name: 'Click here' })
.first()
.should('be.visible');

cy.findAllByRole('link', { name: 'Click here' })
.first()
.click({ force: true });

cy.url().should('contain', 'catalogue/5/items/89/items');
});
Expand Down Expand Up @@ -1102,6 +1131,9 @@ describe('Catalogue Items', () => {
created_time: '2024-01-01T12:00:00.000+00:00',
modified_time: '2024-01-02T13:10:10.000+00:00',
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: false,
})
);
expect(JSON.stringify(await patchRequests[1].json())).equal(
Expand All @@ -1128,6 +1160,9 @@ describe('Catalogue Items', () => {
created_time: '2024-01-01T12:00:00.000+00:00',
modified_time: '2024-01-02T13:10:10.000+00:00',
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: false,
})
);
});
Expand Down
11 changes: 11 additions & 0 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ describe('Items', () => {
cy.findByText('Cameras 3').should('be.visible');
});

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

cy.setMode({ critical: true });

cy.findByTestId('ErrorIcon').should('exist');
cy.findByTestId('ErrorIcon').trigger('mouseover');
cy.findByText('This catalogue item is critical.').should('exist');
cy.findAllByText('(Item Details)').should('exist');
});

it('should be able to navigate back to the catalogue home', () => {
cy.findByRole('button', { name: 'navigate to catalogue home' }).click();
cy.findByText('Motion').should('be.visible');
Expand Down
17 changes: 9 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CatalogueLayout, {
catalogueLayoutLoader,
} from './catalogue/catalogueLayout.component';
import CatalogueCardView from './catalogue/category/catalogueCardView.component';
import CatalogueItemLayout from './catalogue/items/catalogueItemLayout.component';
import CatalogueItemsLandingPage from './catalogue/items/catalogueItemsLandingPage.component';
import CatalogueItemsPage from './catalogue/items/catalogueItemsPage.component';
import SettingsMenuItems from './common/settingsMenuItems.component';
Expand Down Expand Up @@ -155,7 +156,7 @@ const routeObject: RouteObject[] = [
},
{
path: paths.catalogueItem,
Component: Outlet,
Component: CatalogueItemLayout,
children: [
{
index: true,
Expand Down Expand Up @@ -269,13 +270,13 @@ export function Layout() {
const role = getUserRole();
const state = store.getState();
const privilegedRoles = state.config.settings.privilegedRoles;

dispatch(
setAuthorisation({
role,
isAdminUser: privilegedRoles.includes(role),
})
);
if (typeof role === 'string')
dispatch(
setAuthorisation({
role,
isAdminUser: privilegedRoles.includes(role),
})
);
});
}, [dispatch]);
// We need to call forceUpdate if SciGateway tells us to rerender
Expand Down
36 changes: 20 additions & 16 deletions src/api/api.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface Rule {
export interface SparesDefinition {
system_types: SystemType[];
}

// ------------------------------------- IN USE -----------------------------------------------------

export type InUseDefinition = SparesDefinition;
// ------------------------------------ MANUFACTURERS -----------------------------------------------

interface AddressPost {
Expand All @@ -46,14 +50,14 @@ export interface ManufacturerPost {
telephone?: string | null;
}

export interface ManufacturerPatch
extends Partial<Omit<ManufacturerPost, 'address'>> {
export interface ManufacturerPatch extends Partial<
Omit<ManufacturerPost, 'address'>
> {
address?: AddressPatch;
}

export interface Manufacturer
extends Required<Omit<ManufacturerPost, 'address'>>,
CreatedModifiedMixin {
extends Required<Omit<ManufacturerPost, 'address'>>, CreatedModifiedMixin {
id: string;
code: string;
address: Address;
Expand Down Expand Up @@ -138,8 +142,7 @@ export interface CatalogueCategoryPostProperty {
allowed_values?: AllowedValues | null;
}

export interface CatalogueCategoryPropertyPost
extends CatalogueCategoryPostProperty {
export interface CatalogueCategoryPropertyPost extends CatalogueCategoryPostProperty {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
default_value: any;
}
Expand All @@ -150,8 +153,7 @@ export interface CatalogueCategoryPropertyPatch {
unit_id?: string | null;
}

export interface CatalogueCategoryProperty
extends Required<CatalogueCategoryPostProperty> {
export interface CatalogueCategoryProperty extends Required<CatalogueCategoryPostProperty> {
id: string;
unit: string | null;
}
Expand All @@ -166,7 +168,8 @@ export interface CatalogueCategoryPost {
export type CatalogueCategoryPatch = Partial<CatalogueCategoryPost>;

export interface CatalogueCategory
extends Required<Omit<CatalogueCategoryPost, 'properties'>>,
extends
Required<Omit<CatalogueCategoryPost, 'properties'>>,
CreatedModifiedMixin {
id: string;
code: string;
Expand Down Expand Up @@ -208,11 +211,15 @@ export interface CatalogueItemPost {

export type CatalogueItemPatch = Partial<CatalogueItemPost>;
export interface CatalogueItem
extends CreatedModifiedMixin,
extends
CreatedModifiedMixin,
Required<Omit<CatalogueItemPost, 'properties'>> {
id: string;
properties: Property[];
number_of_spares: number | null;
number_of_spares_required: number | null;
criticality: number | null;
is_flagged: boolean | null;
}

// ------------------------------------ ITEMS ------------------------------------------------
Expand All @@ -234,8 +241,7 @@ export interface ItemPost {
export type ItemPatch = Partial<ItemPost>;

export interface Item
extends CreatedModifiedMixin,
Required<Omit<ItemPost, 'properties'>> {
extends CreatedModifiedMixin, Required<Omit<ItemPost, 'properties'>> {
id: string;
usage_status: string;
properties: Property[];
Expand Down Expand Up @@ -265,8 +271,7 @@ export interface AttachmentUploadInfo {
}

export interface AttachmentMetadata
extends Required<AttachmentPostMetadata>,
CreatedModifiedMixin {
extends Required<AttachmentPostMetadata>, CreatedModifiedMixin {
id: string;
}

Expand All @@ -288,8 +293,7 @@ export interface ImagePost extends ObjectFileUploadMetadata {
}

export interface APIImage
extends Required<Omit<ImagePost, 'upload_file'>>,
CreatedModifiedMixin {
extends Required<Omit<ImagePost, 'upload_file'>>, CreatedModifiedMixin {
id: string;
primary: boolean;
thumbnail_base64: string;
Expand Down
15 changes: 15 additions & 0 deletions src/api/catalogueItems.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ describe('catalogue items api functions', () => {
obsolete_reason: null,
properties: [],
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: null,
...CREATED_MODIFIED_TIME_VALUES,
};
});
Expand Down Expand Up @@ -266,6 +269,9 @@ describe('catalogue items api functions', () => {
obsolete_reason: null,
obsolete_replacement_catalogue_item_id: null,
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: null,
properties: [
{
id: '90',
Expand Down Expand Up @@ -294,6 +300,9 @@ describe('catalogue items api functions', () => {
obsolete_reason: null,
obsolete_replacement_catalogue_item_id: null,
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: null,
properties: [
{
id: '90',
Expand Down Expand Up @@ -401,6 +410,9 @@ describe('catalogue items api functions', () => {
obsolete_reason: null,
obsolete_replacement_catalogue_item_id: null,
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: null,
properties: [
{
id: '90',
Expand Down Expand Up @@ -429,6 +441,9 @@ describe('catalogue items api functions', () => {
obsolete_reason: null,
obsolete_replacement_catalogue_item_id: null,
number_of_spares: 0,
number_of_spares_required: null,
criticality: null,
is_flagged: null,
properties: [
{
id: '90',
Expand Down
Loading
Loading