Skip to content

Commit

Permalink
Merge pull request #1232 from ral-facilities/nested-routes-for-catalo…
Browse files Browse the repository at this point in the history
…gue-#1218

Nested routes for catalogue #1218
  • Loading branch information
joshuadkitenge authored Jan 13, 2025
2 parents 017b068 + df22100 commit d87a01e
Show file tree
Hide file tree
Showing 45 changed files with 3,623 additions and 2,104 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/with_api/app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('App', () => {
cy.visit('/catalogue');
cy.wait('@getCatalogueCategoryDataRoot', { timeout: 10000 });
cy.findByText(
'There are no catalogue categories. Please add a category using the plus icon in the top left of your screen'
'There are no catalogue categories. Please add a category using the button in the top left of your screen.'
).should('exist');
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/with_api/catalogueCategories/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const modifyCatalogueCategory = (
cy.findByLabelText('Catalogue Items').click();
}
} else {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
}

if (values.name !== undefined) {
Expand Down
35 changes: 14 additions & 21 deletions cypress/e2e/with_mock_data/catalogueCategories.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Catalogue Category', () => {
name: 'Test ' + index.toString(),
parent_id: null,
code: index.toString(),
is_leaf: true,
is_leaf: false,
created_time: '2024-01-01T12:00:00.000+00:00',
modified_time: '2024-01-02T13:10:10.000+00:00',
properties: [],
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('Catalogue Category', () => {
});

it('display error message when there is no name when adding a catalogue category', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByRole('button', { name: 'Save' }).click();
cy.findByRole('dialog')
.should('be.visible')
Expand All @@ -149,7 +149,7 @@ describe('Catalogue Category', () => {
});

it('adds a catalogue category where isLeaf is false', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.startSnoopingBrowserMockedRequest();
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('Catalogue Category', () => {
});

it('adds a catalogue category where isLeaf is true', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -296,7 +296,7 @@ describe('Catalogue Category', () => {
});

it('adds a catalogue category where isLeaf is true with a list of allowed values', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -353,7 +353,7 @@ describe('Catalogue Category', () => {
});

it('displays the allowed values list error states missing values (Text)', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('Catalogue Category', () => {
});

it('displays the allowed values list error states duplicate values (Text)', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -415,7 +415,7 @@ describe('Catalogue Category', () => {
});

it('displays the allowed values list error states and check if the error states are in the correct location (number)', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('Catalogue Category', () => {
});

it('displays error message when duplicate names for properties are entered', () => {
cy.findByRole('button', { name: 'add catalogue category' }).click();
cy.findByRole('button', { name: 'Add Catalogue Category' }).click();
cy.findByLabelText('Name *').type('test');

cy.findByLabelText('Catalogue Items').click();
Expand Down Expand Up @@ -816,7 +816,7 @@ describe('Catalogue Category', () => {
it('category with no data displays no results found', () => {
cy.visit('/catalogue/16');
cy.findByText(
'There are no catalogue categories. Please add a category using the plus icon in the top left of your screen'
'There are no catalogue categories. Please add a category using the button in the top left of your screen.'
).should('exist');
});

Expand All @@ -828,28 +828,21 @@ describe('Catalogue Category', () => {
});

it('expired url displays search not found message', () => {
cy.visit('/catalogue/not-exist');
cy.visit('/catalogue/not_exist');
cy.findByText(
'The category you searched for does not exist. Please navigate home by pressing the home button at the top left of your screen.'
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`,
{ timeout: 10000 }
).should('exist');
});

it('add button disabled when expired url is used', () => {
cy.visit('/catalogue/not-exist');

cy.findByRole('button', { name: 'add catalogue category' }).should(
'be.disabled'
);
});

it('when root has no data it displays no categories error message', () => {
cy.editEndpointResponse({
url: '/v1/catalogue-categories',
data: [],
statusCode: 200,
});
cy.findByText(
'There are no catalogue categories. Please add a category using the plus icon in the top left of your screen'
'There are no catalogue categories. Please add a category using the button in the top left of your screen.'
).should('exist');
});

Expand Down
28 changes: 22 additions & 6 deletions cypress/e2e/with_mock_data/catalogueItems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ describe('Catalogue Items', () => {
afterEach(() => {
cy.clearMocks();
});

it('should navigate back to the catalogue items table from the landing page using the breadcrumbs', () => {
cy.visit('/catalogue/5/items/89');

cy.findByRole('link', { name: 'Energy Meters' }).click();

cy.findByRole('button', { name: 'Add Catalogue Item' }).should('exist');
});
it('adds a catalogue item', () => {
cy.findByRole('button', { name: 'Add Catalogue Item' }).click();

Expand Down Expand Up @@ -510,17 +518,25 @@ describe('Catalogue Items', () => {
});

it('displays the expired landing page message and navigates back to the catalogue home', () => {
cy.visit('/catalogue/item/1fds');
cy.visit('/catalogue/4/items/1fds');

cy.findByText(
`This catalogue item doesn't exist. Please click the Home button on the top left of your screen to navigate to the catalogue home.`
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`
).should('exist');

cy.findByRole('button', { name: 'navigate to catalogue home' }).click();

cy.findByText('Motion').should('exist');
});

it('displays the expired landing page message if the catalogue_category_id does not match the catalogue_item_id ', () => {
cy.visit('/catalogue/4/items/89');

cy.findByText(
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`
).should('exist');
});

it('displays error message when user tries to delete a catalogue item that has children elements', () => {
cy.visit('/catalogue/5');
cy.findAllByLabelText('Row Actions').eq(1).click();
Expand Down Expand Up @@ -739,7 +755,7 @@ describe('Catalogue Items', () => {

it('can load and clear date filters', () => {
cy.visit(
'/catalogue/4?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0luSCAZgsUgPoYKXEgA0IANxwkY8EBgCeABx7QQSTD35DsIuQCYADOoAsAWk0BGAwGYAKps3RL1zdUuaAWiAC%2BvUJJmoAzhgBOCAB2%2BHyCwrIgrgC6LjFAA'
'/catalogue/4/items?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0luSCAZgsUgPoYKXEgA0IANxwkY8EBgCeABx7QQSTD35DsIuQCYADOoAsAWk0BGAwGYAKps3RL1zdUuaAWiAC%2BvUJJmoAzhgBOCAB2%2BHyCwrIgrgC6LjFAA'
);

cy.findByText('Cameras 25').should('exist');
Expand Down Expand Up @@ -890,15 +906,15 @@ describe('Catalogue Items', () => {

cy.findAllByRole('link', { name: 'Click here' }).eq(1).click();

cy.url().should('contain', 'catalogue/item/6');
cy.url().should('contain', 'catalogue/5/items/6');
});

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.url().should('contain', 'catalogue/item/89/items');
cy.url().should('contain', 'catalogue/5/items/89/items');
});

it('can navigate to an items page from the landing page', () => {
Expand All @@ -907,7 +923,7 @@ describe('Catalogue Items', () => {

cy.findAllByRole('link', { name: 'Items' }).eq(0).click();

cy.url().should('contain', 'catalogue/item/89/items');
cy.url().should('contain', 'catalogue/5/items/89/items');
});

it('opens add dialog for categories in directory and has functionality of duplicate', () => {
Expand Down
34 changes: 31 additions & 3 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,39 @@ import { delay, HttpResponse } from 'msw';

describe('Items', () => {
beforeEach(() => {
cy.visit('/catalogue/item/1/items');
cy.visit('/catalogue/4/items/1/items');
});
afterEach(() => {
cy.clearMocks();
});

it('displays the expired landing page message and navigates back to the catalogue home', () => {
cy.visit('/catalogue/4/items/1/items/1fds');

cy.findByText(
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`
).should('exist');

cy.findByRole('button', { name: 'navigate to catalogue home' }).click();

cy.findByText('Motion').should('exist');
});

it('displays the expired landing page message if the catalogue_category_id does not match the catalogue_item_id ', () => {
cy.visit('/catalogue/5/items/1/items/KvT2Ox7n');

cy.findByText(
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`
).should('exist');
});

it('displays the expired landing page message if the catalogue_item_id does not match the item_id ', () => {
cy.visit('/catalogue/4/items/89/items/G463gOIA');

cy.findByText(
`The catalogue route you are trying to access doesn't exist. Please click the Home button to navigate back to the Catalogue Home page.`
).should('exist');
});
it('should be able to navigate back to the catalogue catalogue item table view', () => {
cy.findByRole('link', { name: 'Cameras' }).click();
cy.findByText('Cameras 1').should('be.visible');
Expand All @@ -21,7 +49,7 @@ describe('Items', () => {
});

it('should be able to navigate back to the catalogue home step by step', () => {
cy.visit('/catalogue/item/1/items/KvT2Ox7n');
cy.visit('/catalogue/4/items/1/items/KvT2Ox7n');

cy.findByRole('link', { name: 'Items' }).click();

Expand Down Expand Up @@ -224,7 +252,7 @@ describe('Items', () => {
});

it('adds an item with only mandatory fields (allowed list of values)', () => {
cy.visit('/catalogue/item/17/items');
cy.visit('/catalogue/12/items/17/items');
cy.findByRole('button', { name: 'Add Item' }).click();

cy.findByLabelText('Usage status *').click();
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/with_mock_data/systems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Systems', () => {
cy.findAllByRole('link', { name: 'Cameras 8' }).first().click();

// Check now on landing page for the catalogue item
cy.url().should('include', '/catalogue/item/27');
cy.url().should('include', '/catalogue/4/items/27');
cy.findByText('Properties').should('be.visible');
});

Expand All @@ -228,7 +228,7 @@ describe('Systems', () => {
cy.findByRole('link', { name: 'QnfSKahnQuze' }).click();

// Check now on landing page for the item
cy.url().should('include', '/catalogue/item/28/items/z1hJvV8Z');
cy.url().should('include', '/catalogue/4/items/28/items/z1hJvV8Z');
cy.findByText('Properties').should('be.visible');
});

Expand Down
Loading

0 comments on commit d87a01e

Please sign in to comment.