Skip to content

Commit

Permalink
Merge branch 'develop' into usage-statues-of-moving-items-#456
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadkitenge committed Apr 9, 2024
2 parents 0c8522e + 4e5905c commit 354da7b
Show file tree
Hide file tree
Showing 26 changed files with 2,948 additions and 187 deletions.
3 changes: 3 additions & 0 deletions cypress/e2e/with_api/catalogueCategories/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const modifyCatalogueCategory = (
cy.findAllByText(
`${values.newFormFields[0].name}${values.newFormFields[0].unit ? ` (${values.newFormFields[0].unit})` : ''}`
).should('have.length', 2);
// Two for column visibility changes (hide all and showing name column), one for actually going back
cy.go('back');
cy.go('back');
cy.go('back');
}
}
Expand Down
43 changes: 43 additions & 0 deletions cypress/e2e/with_mock_data/catalogueCategories.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,49 @@ describe('Catalogue Category', () => {
cy.findByText('actuators').should('not.exist');
});

it('should be able to navigate through categories while preserving the page state when going back', () => {
cy.editEndpointResponse({
url: '/v1/catalogue-categories',
data: createMockData(),
statusCode: 200,
});

cy.findByText('Test 1').should('exist');
cy.findByText('Test 45').should('not.exist');
cy.location('search').should('eq', '');

// Categories per page
cy.findByRole('combobox', { name: 'Categories per page' }).within(() =>
cy.findByText('30').should('be.visible')
);
cy.findByRole('combobox', { name: 'Categories per page' }).click();
cy.findByRole('listbox').within(() => {
cy.findByText('45').click();
});
cy.findByText('Test 45').should('exist');
cy.location('search').should(
'eq',
'?state=N4IgDiBcpghg5gUwMoEsBeioBYCsAacBRASQDsATRADygEYBfBoA'
);

cy.findByText('Test 1').click();
cy.location('search').should('eq', '');
cy.findByRole('combobox', { name: 'Categories per page' }).within(() =>
cy.findByText('30').should('be.visible')
);

// Ensure same state is recovered
cy.go('back');

cy.location('search').should(
'eq',
'?state=N4IgDiBcpghg5gUwMoEsBeioBYCsAacBRASQDsATRADygEYBfBoA'
);
cy.findByRole('combobox', { name: 'Categories per page' }).within(() =>
cy.findByText('45').should('be.visible')
);
});

it('should be able to change page', () => {
cy.editEndpointResponse({
url: '/v1/catalogue-categories',
Expand Down
21 changes: 21 additions & 0 deletions cypress/e2e/with_mock_data/catalogueItems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,27 @@ describe('Catalogue Items', () => {
cy.findByText('Cameras 1').should('exist');
});

it('check table state persists on page reload', () => {
cy.findByText('Cameras 1').should('exist');
cy.findByRole('button', { name: 'Clear Filters' }).should('be.disabled');
cy.findByLabelText('Filter by Name').type('Cameras 15');
cy.findByText('Cameras 1').should('not.exist');
cy.findByRole('link', { name: 'Cameras 15' }).should('exist');
cy.location('search').should(
'eq',
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJqAwg8QE5oAzgAIAjAFYQAXwC60oA'
);

cy.reload();

cy.findByRole('link', { name: 'Cameras 15' }).should('exist');
cy.findByText('Cameras 1').should('not.exist');
cy.location('search').should(
'eq',
'?state=N4IgxgYiBcDaoEsAmNwEMAuaA2B7A5gK4CmAkhsQLYB0AdmpcSADQgBuOJqAwg8QE5oAzgAIAjAFYQAXwC60oA'
);
});

it('make an item obsolete (no details)', () => {
cy.findAllByLabelText('Row Actions').eq(1).click();
cy.findByText('Obsolete').click();
Expand Down
106 changes: 106 additions & 0 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,112 @@ describe('Items', () => {
});
});

it('adds an item with only mandatory fields (serial number advanced options)', () => {
cy.findByRole('button', { name: 'Add Item' }).click();
cy.findByText('Show advanced options').click();
cy.findByLabelText('Serial number').type('test %s');
cy.findByLabelText('Quantity').type('3');
cy.findByLabelText('Starting value').type('2');

cy.startSnoopingBrowserMockedRequest();

cy.findByRole('button', { name: 'Next' }).click();
cy.findByRole('button', { name: 'Next' }).click();
cy.findByText('Giant laser').click();

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

cy.findBrowserMockedRequests({
method: 'POST',
url: '/v1/items',
}).should(async (postRequests) => {
expect(postRequests.length).eq(3);

for (let i = 0; i < 3; i++) {
expect(JSON.stringify(await postRequests[i].json())).equal(
JSON.stringify({
catalogue_item_id: '1',
system_id: '65328f34a40ff5301575a4e3',
purchase_order_number: null,
is_defective: false,
usage_status: 0,
warranty_end_date: null,
asset_number: null,
serial_number: `test ${i + 2}`,
delivered_date: null,
notes: null,
properties: [
{ name: 'Resolution', value: 12 },
{ name: 'Frame Rate', value: 30 },
{ name: 'Sensor Type', value: 'CMOS' },
{ name: 'Sensor brand', value: null },
{ name: 'Broken', value: true },
{ name: 'Older than five years', value: false },
],
})
);
}
});
});

it('displays error messages for serial number advanced options', () => {
cy.findByRole('button', { name: 'Add Item' }).click();

cy.findByText('Show advanced options').click();

cy.findByLabelText('Starting value').type('10');

cy.findByText('Please enter a quantity value').should('exist');

cy.findByLabelText('Starting value').clear();

cy.findByLabelText('Quantity').type('10a');
cy.findByLabelText('Starting value').type('10a');

cy.findAllByText('Please enter a valid number').should('have.length', 2);

cy.findByLabelText('Quantity').clear();
cy.findByLabelText('Starting value').clear();

cy.findByLabelText('Quantity').type('10.5');
cy.findByLabelText('Starting value').type('10.5');

cy.findByText('Quantity must be an integer').should('exist');
cy.findByText('Starting value must be an integer').should('exist');

cy.findByLabelText('Quantity').clear();
cy.findByLabelText('Starting value').clear();

cy.findByLabelText('Quantity').type('-1');
cy.findByLabelText('Starting value').type('-1');

cy.findByText('Quantity must be greater than 1').should('exist');
cy.findByText('Starting value must be greater than or equal to 0').should(
'exist'
);

cy.findByLabelText('Quantity').clear();
cy.findByLabelText('Starting value').clear();

cy.findByLabelText('Quantity').type('100');
cy.findByLabelText('Starting value').type('2');

cy.findByText(
'Please use %s to specify the location you want to append the number to serial number'
).should('exist');
cy.findByText('Quantity must be less than 100').should('exist');

cy.findByLabelText('Quantity').clear();
cy.findByLabelText('Starting value').clear();

cy.findByLabelText('Serial number').type('test %s');
cy.findByLabelText('Quantity').type('4');
cy.findByLabelText('Starting value').type('2');

cy.findByText('e.g. test 2').should('exist');
});

it('adds an item with only mandatory fields (allowed list of values)', () => {
cy.visit('/catalogue/item/17/items');
cy.findByRole('button', { name: 'Add Item' }).click();
Expand Down
170 changes: 170 additions & 0 deletions cypress/e2e/with_mock_data/systems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,176 @@ describe('Systems', () => {
cy.findByText('Description').should('be.visible');
});

it('should be able to use browser back to undo a pagination state change', () => {
cy.visit('/systems/65328f34a40ff5301575a4e3');

cy.findByText('Smaller laser').should('be.visible');

// Rows per page (subsystems)
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' }).eq(0).click();
cy.findByRole('listbox').within(() => {
cy.findByText(30).click();
});
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});

// Rows per page (items)
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('15').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' }).eq(1).click();
cy.findByRole('listbox').within(() => {
cy.findByText(30).click();
});
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g&state=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});

//Ensure same state is recovered
cy.go('back');

cy.findByText('Smaller laser').should('be.visible');
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('30').should('not.exist');
cy.findByText('15').should('be.visible');
});
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);

cy.go('back');
cy.findByText('Smaller laser').should('be.visible');
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('30').should('not.exist');
cy.findByText('15').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('30').should('not.exist');
cy.findByText('15').should('be.visible');
});
cy.location('search').should('eq', '');
});

it('should be able to navigate through subsystems while preserving the table states when going back', () => {
cy.visit('/systems/65328f34a40ff5301575a4e3');

cy.findByText('Smaller laser').should('be.visible');

// Rows per page (subsystems)
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' }).eq(0).click();
cy.findByRole('listbox').within(() => {
cy.findByText(30).click();
});
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});

// Rows per page (items)
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('15').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' }).eq(1).click();
cy.findByRole('listbox').within(() => {
cy.findByText(30).click();
});
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g&state=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});

// Navigate deeper
cy.findByText('Smaller laser').click();
cy.url().should('include', '/systems/65328f34a40ff5301575a4e4');
cy.location('search').should('eq', '');
cy.findByText('Pulse Laser').should('be.visible');
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => cy.findByText('15').should('be.visible'));
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => cy.findByText('15').should('be.visible'));
cy.location('search').should('eq', '');

//Ensure same state is recovered
cy.go('back');

cy.findByText('Smaller laser').should('be.visible');
cy.findByText('Pulse Laser').should('not.exist');

// Rows per page
cy.location('search').should(
'eq',
'?subState=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g&state=N4IgDiBcpghg5gUwMoEsBeioGYAMAacBRASQDsATRADylwF96g'
);
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(0)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});
cy.findAllByRole('combobox', { name: 'Rows per page' })
.eq(1)
.within(() => {
cy.findByText('15').should('not.exist');
cy.findByText('30').should('be.visible');
});
});

it('should be able to navigate to an items catalogue item landing page', () => {
cy.findByRole('cell', { name: 'Pulse Laser' }).click();
cy.findAllByRole('link', { name: 'Cameras 8' }).first().click();
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ declare global {
method,
url,
}: any): Chainable<MockedRequest[]>;
dropIMSCollections(collections: string[]): Chainable<unknown>;
/**
* Deletes the IMS collections
*
* @example cy.dropIMSCollections(['catalogue_categories']);
*/
dropIMSCollections(collections: string[]): Chainable<unknown>;
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date-fns": "3.6.0",
"history": "^5.3.0",
"loglevel": "^1.8.1",
"lz-string": "^1.5.0",
"material-react-table": "^2.0.4",
"msw": "2.2.2",
"react": "^18.2.0",
Expand Down
Loading

0 comments on commit 354da7b

Please sign in to comment.