From 381e16aae115c0d23b6fb844d7695a5e4c6c70a8 Mon Sep 17 00:00:00 2001 From: Joshua Kitenge Date: Thu, 9 Jan 2025 12:27:17 +0000 Subject: [PATCH 1/2] improve route for home page #1233 --- cypress/e2e/with_mock_data/homePage.cy.ts | 7 +++++++ src/App.tsx | 14 ++++++++++++-- .../homePage.component.test.tsx.snap | 19 +++++++++++++++++++ src/homePage/homePage.component.test.tsx | 17 ++++++++++++++++- src/homePage/homePage.component.tsx | 10 ++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/with_mock_data/homePage.cy.ts b/cypress/e2e/with_mock_data/homePage.cy.ts index 227df7b72..716fb285b 100644 --- a/cypress/e2e/with_mock_data/homePage.cy.ts +++ b/cypress/e2e/with_mock_data/homePage.cy.ts @@ -24,4 +24,11 @@ describe('IMS HomePage', () => { 'https://www.clf.stfc.ac.uk/Pages/EPAC-Applications.aspx' ); }); + it('displays error message for invalid homepage route', () => { + cy.visit('/ims/fdsf'); + + cy.findByText( + `The route you are trying to access doesn't exist. Please click the Scigateway logo button in the header to navigate back to the Home page.` + ).should('exist'); + }); }); diff --git a/src/App.tsx b/src/App.tsx index e41581515..83e704f0e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -37,7 +37,10 @@ import CatalogueItemsLandingPage from './catalogue/items/catalogueItemsLandingPa import CatalogueItemsPage from './catalogue/items/catalogueItemsPage.component'; import ConfigProvider from './configProvider.component'; import handleIMS_APIError from './handleIMS_APIError'; -import { HomePage } from './homePage/homePage.component'; +import { + HomePage, + HomePageErrorComponent, +} from './homePage/homePage.component'; import IMSThemeProvider from './imsThemeProvider.component'; import Items from './items/items.component'; import ItemsLandingPage from './items/itemsLandingPage.component'; @@ -111,7 +114,14 @@ const routeObject: RouteObject[] = [ Component: Layout, children: [ { path: paths.root, Component: HomePage }, - { path: paths.homepage, Component: HomePage }, + { + path: paths.homepage, + Component: Outlet, + children: [ + { Component: HomePage, index: true }, + { path: '*', Component: HomePageErrorComponent }, + ], + }, { path: paths.admin, Component: AdminLayout, diff --git a/src/homePage/__snapshots__/homePage.component.test.tsx.snap b/src/homePage/__snapshots__/homePage.component.test.tsx.snap index 3d1792a60..58c95fa9b 100644 --- a/src/homePage/__snapshots__/homePage.component.test.tsx.snap +++ b/src/homePage/__snapshots__/homePage.component.test.tsx.snap @@ -1,5 +1,24 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`Home Page Error Component > renders catalogue error page correctly 1`] = ` + +
+

+ Invalid Route +

+

+ The route you are trying to access doesn't exist. Please click the Scigateway logo button in the header to navigate back to the Home page. +

+
+
+`; + exports[`Home page component > homepage renders correctly 1`] = `
{ @@ -13,3 +16,15 @@ describe('Home page component', () => { expect(asFragment()).toMatchSnapshot(); }); }); + +describe('Home Page Error Component', () => { + const createView = () => { + return renderComponentWithRouterProvider(); + }; + + it('renders catalogue error page correctly', async () => { + const view = createView(); + + expect(view.asFragment()).toMatchSnapshot(); + }); +}); diff --git a/src/homePage/homePage.component.tsx b/src/homePage/homePage.component.tsx index 7e351ea8c..43b98f429 100644 --- a/src/homePage/homePage.component.tsx +++ b/src/homePage/homePage.component.tsx @@ -2,6 +2,7 @@ import { Box, Button, Grid, Paper, alpha, styled } from '@mui/material'; import Typography from '@mui/material/Typography'; import React from 'react'; import { Link } from 'react-router-dom'; +import ErrorPage from '../common/errorPage.component'; import { InventoryManagementSystemSettingsContext } from '../configProvider.component'; import BackgroundImage from '/images/background.jpg'; import Decal1Image from '/images/decal1.svg'; @@ -13,6 +14,15 @@ import GreenSwirl1Image from '/images/green-swirl1.png'; import GreenSwirl2Image from '/images/green-swirl2.png'; import DGLogo from '/images/scigateway-white-text-blue-mark-logo.svg'; +export const HomePageErrorComponent = () => { + return ( + + ); +}; + export interface BaseHomePageProps { logo: string; backgroundImage: string; From 56204601a473cfd9841c7c9d832f8b74516d53df Mon Sep 17 00:00:00 2001 From: Joshua Kitenge Date: Thu, 9 Jan 2025 13:08:34 +0000 Subject: [PATCH 2/2] Address review comments #1218 --- ...catalogueContainer.component.test.tsx.snap | 857 ------------------ ...eItemsDetailsPanel.component.test.tsx.snap | 46 +- ...catalogueItemsPage.component.test.tsx.snap | 202 +++-- ...alogueItemsDetailsPanel.component.test.tsx | 28 +- .../catalogueItemsPage.component.test.tsx | 4 + src/mocks/handlers.ts | 1 - 6 files changed, 173 insertions(+), 965 deletions(-) delete mode 100644 src/catalogue/__snapshots__/catalogueContainer.component.test.tsx.snap diff --git a/src/catalogue/__snapshots__/catalogueContainer.component.test.tsx.snap b/src/catalogue/__snapshots__/catalogueContainer.component.test.tsx.snap deleted file mode 100644 index c51390234..000000000 --- a/src/catalogue/__snapshots__/catalogueContainer.component.test.tsx.snap +++ /dev/null @@ -1,857 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`CatalogueLayout > renders a catalogue categories page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; - -exports[`CatalogueLayout > renders a catalogue items landing page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; - -exports[`CatalogueLayout > renders a catalogue items page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; - -exports[`CatalogueLayout > renders catalogue home page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; - -exports[`CatalogueLayout > renders the item landing page page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; - -exports[`CatalogueLayout > renders the items page correctly 1`] = ` - -
-
-
-
- - - - -
-
-
-
-
-`; diff --git a/src/catalogue/items/__snapshots__/catalogueItemsDetailsPanel.component.test.tsx.snap b/src/catalogue/items/__snapshots__/catalogueItemsDetailsPanel.component.test.tsx.snap index 03e833579..a4a05f1e2 100644 --- a/src/catalogue/items/__snapshots__/catalogueItemsDetailsPanel.component.test.tsx.snap +++ b/src/catalogue/items/__snapshots__/catalogueItemsDetailsPanel.component.test.tsx.snap @@ -1287,25 +1287,12 @@ exports[`Catalogue Items details panel > renders details panel correctly (with o

- - - - - + Click here +

renders details panel correctly 1`] = `

- - - - - + Click here +

renders a catalogue items page correctly 1`] = ` Add Catalogue Item + -
- - -
-
-
- - - +
@@ -248,22 +231,98 @@ exports[`CatalogueItemsPage > renders a catalogue items page correctly 1`] = ` /> - -

- No results found: Try adding an item by using the Add Catalogue Item button on the top left of your screen -

- - + aria-label="Cameras 1 row" + class="MuiTableRow-root MuiTableRow-root css-i1y727-MuiTableRow-root-MuiTableRow-root" + data-index="0" + role="row" + /> + + + + + + + + + + + + + + renders a catalogue items page correctly 1`] = `
-
-
-
- - - - -
-
-
renders a catalogue items page correctly 1`] = ` class="MuiCollapse-wrapperInner MuiCollapse-vertical css-9l5vo-MuiCollapse-wrapperInner" >