diff --git a/cypress/e2e/with_api/items/functions.ts b/cypress/e2e/with_api/items/functions.ts index c9f152094..53144fb23 100644 --- a/cypress/e2e/with_api/items/functions.ts +++ b/cypress/e2e/with_api/items/functions.ts @@ -284,3 +284,27 @@ export const editItem = () => { system: 'optics 1', }); }; + +export const spareDefinition = () => { + cy.visit('/admin-ims'); + + cy.findByText('Spares definition').click(); + + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'Used' }).click(); + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'New' }).click(); + + cy.findByLabelText('Confirm understanding and proceed checkbox').click(); + + cy.findByRole('button', { name: 'Save' }).click(); + + cy.findByRole('dialog').should('not.exist'); + + cy.findByText('Spares definition').click(); + + cy.findByText('New').should('exist'); + cy.findByText('Used').should('exist'); + + cy.go('back'); +}; diff --git a/cypress/e2e/with_api/items/items.cy.ts b/cypress/e2e/with_api/items/items.cy.ts index ea08b3501..5e3bc72af 100644 --- a/cypress/e2e/with_api/items/items.cy.ts +++ b/cypress/e2e/with_api/items/items.cy.ts @@ -8,9 +8,10 @@ import { addItem, addProperty, deleteItem, + duplicateItem, editItem, editProperty, - duplicateItem, + spareDefinition, } from './functions'; describe('items', () => { @@ -47,6 +48,7 @@ describe('items', () => { 'systems', 'units', 'usage_statuses', + 'settings', ]); }); @@ -56,6 +58,7 @@ describe('items', () => { duplicateItem('MX4332424', 0); addProperty(); editProperty(); + spareDefinition(); deleteItem('MX4332424', 0); deleteItem('MX4332424', 0); }); diff --git a/cypress/e2e/with_mock_data/admin.cy.ts b/cypress/e2e/with_mock_data/admin.cy.ts index 59f4872d9..20bc174fd 100644 --- a/cypress/e2e/with_mock_data/admin.cy.ts +++ b/cypress/e2e/with_mock_data/admin.cy.ts @@ -1,10 +1,266 @@ describe('Admin Page', () => { - beforeEach(() => { - cy.visit('/admin-ims'); - }); - it('should render admin page correctly', () => { + cy.visit('/admin-ims'); cy.findByText('Units').should('be.visible'); cy.findByText('Usage Statuses').should('be.visible'); }); + + describe('UsageStatus', () => { + beforeEach(() => { + cy.visit('/admin-ims/usage-statuses'); + }); + afterEach(() => { + cy.clearMocks(); + }); + + it('should render table correctly', () => { + cy.findByText('Value').should('be.visible'); + cy.findByText('Last modified').should('be.visible'); + cy.findByText('Created').should('be.visible'); + + cy.findByText('New').should('be.visible'); + }); + + it('adds a usage status and deals with errors correctly', () => { + cy.findByRole('button', { name: 'Add Usage Status' }).click(); + + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByText('Please enter a value.').should('be.visible'); + + cy.findByLabelText('Value *').type('test_dup'); + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByText( + 'A usage status with the same value already exists. Please enter a different value.' + ).should('be.visible'); + + cy.findByLabelText('Value *').clear(); + cy.findByLabelText('Value *').type('test'); + + cy.startSnoopingBrowserMockedRequest(); + + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByRole('dialog').should('not.exist'); + + cy.findBrowserMockedRequests({ + method: 'POST', + url: '/v1/usage-statuses', + }).should(async (postRequests) => { + expect(postRequests.length).equal(1); + const request = postRequests[0]; + expect(JSON.stringify(await request.json())).equal('{"value":"test"}'); + }); + }); + + it('deletes a usage status', () => { + cy.findAllByLabelText('Row Actions').first().click(); + cy.findByText('Delete').click(); + + cy.startSnoopingBrowserMockedRequest(); + + cy.findByRole('button', { name: 'Continue' }).click(); + + cy.findBrowserMockedRequests({ + method: 'DELETE', + url: '/v1/usage-statuses/:id', + }).should((patchRequests) => { + expect(patchRequests.length).equal(1); + const request = patchRequests[0]; + expect(request.url.toString()).to.contain('1'); + }); + }); + + it('shows error if trying to delete a unit that is in a catalogue category', () => { + cy.findAllByLabelText('Row Actions').eq(2).click(); + cy.findByText('Delete').click(); + + cy.findByRole('button', { name: 'Continue' }).click(); + + cy.findByText( + 'This usage status is currently used by one or more items. Remove all uses before deleting it here.' + ); + }); + }); + describe('Units', () => { + beforeEach(() => { + cy.visit('/admin-ims/units'); + }); + afterEach(() => { + cy.clearMocks(); + }); + + it('should render table correctly', () => { + cy.findByText('Value').should('be.visible'); + cy.findByText('Last modified').should('be.visible'); + cy.findByText('Created').should('be.visible'); + + cy.findByText('megapixels').should('be.visible'); + }); + + it('adds a unit and deals with errors correctly', () => { + cy.findByRole('button', { name: 'Add Unit' }).click(); + + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByText('Please enter a value.').should('be.visible'); + + cy.findByLabelText('Value *').type('test_dup'); + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByText( + 'A unit with the same value already exists. Please enter a different value.' + ).should('be.visible'); + + cy.findByLabelText('Value *').clear(); + cy.findByLabelText('Value *').type('test'); + + cy.startSnoopingBrowserMockedRequest(); + + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByRole('dialog').should('not.exist'); + + cy.findBrowserMockedRequests({ + method: 'POST', + url: '/v1/units', + }).should(async (postRequests) => { + expect(postRequests.length).equal(1); + const request = postRequests[0]; + expect(JSON.stringify(await request.json())).equal('{"value":"test"}'); + }); + }); + + it('deletes a unit', () => { + cy.findAllByLabelText('Row Actions').first().click(); + cy.findByText('Delete').click(); + + cy.startSnoopingBrowserMockedRequest(); + + cy.findByRole('button', { name: 'Continue' }).click(); + + cy.findBrowserMockedRequests({ + method: 'DELETE', + url: '/v1/units/:id', + }).should((patchRequests) => { + expect(patchRequests.length).equal(1); + const request = patchRequests[0]; + expect(request.url.toString()).to.contain('1'); + }); + }); + + it('shows error if trying to delete a unit that is in a catalogue category', () => { + cy.findAllByLabelText('Row Actions').eq(1).click(); + cy.findByText('Delete').click(); + + cy.findByRole('button', { name: 'Continue' }).click(); + + cy.findByText( + 'This unit is currently used by one or more catalogue categories. Remove all uses before deleting it here.' + ); + }); + }); + + describe('Spares Definition', () => { + beforeEach(() => { + cy.visit('/admin-ims'); + }); + afterEach(() => { + cy.clearMocks(); + }); + + it('disables save button when checkbox is not checked', () => { + cy.findByText('Spares definition').click(); + + cy.findByRole('button', { name: 'Save' }).should('be.disabled'); + + cy.findByLabelText('Confirm understanding and proceed checkbox').click(); + + cy.findByRole('button', { name: 'Save' }).should('be.enabled'); + }); + + it('closes the dialog when Cancel button is clicked', () => { + cy.findByText('Spares definition').click(); + + cy.findByRole('dialog').should('exist'); + + cy.findByRole('button', { name: 'Cancel' }).click(); + + cy.findByRole('dialog').should('not.exist'); + }); + + it('should modify spares definition', () => { + cy.findByText('Spares definition').click(); + + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'Scrapped' }).click(); + + cy.findByLabelText('Confirm understanding and proceed checkbox').click(); + cy.startSnoopingBrowserMockedRequest(); + + cy.findByRole('button', { name: 'Save' }).click(); + cy.findByRole('dialog').should('not.exist'); + + cy.findBrowserMockedRequests({ + method: 'PUT', + url: '/v1/settings/spares_definition', + }).should(async (postRequests) => { + expect(postRequests.length).equal(1); + const request = postRequests[0]; + expect(JSON.stringify(await request.json())).equal( + JSON.stringify({ + usage_statuses: [ + { + id: '0', + }, + { + id: '2', + }, + { + id: '3', + }, + ], + }) + ); + }); + }); + + it('displays error message if spares definition has not changed and clears when value is changed', () => { + cy.findByText('Spares definition').click(); + + cy.findByLabelText('Confirm understanding and proceed checkbox').click(); + + cy.findByRole('button', { name: 'Save' }).click(); + + cy.findByText( + 'No changes detected in the spares definition. Please update the spares definition or select Cancel to exit.' + ).should('exist'); + + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'Scrapped' }).click(); + + cy.findByText( + 'No changes detected in the spares definition. Please update the spares definition or select Cancel to exit.' + ).should('not.exist'); + }); + + it('displays error message if spares definition has less then 1 usage status and clears when value is changed', () => { + cy.findByText('Spares definition').click(); + + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'Used' }).click(); + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'New' }).click(); + + cy.findByLabelText('Confirm understanding and proceed checkbox').click(); + + cy.findByRole('button', { name: 'Save' }).click(); + + cy.findByText( + 'The list must have at least one item. Please add a usage status.' + ).should('exist'); + + cy.findByRole('combobox').click(); + cy.findByRole('option', { name: 'Scrapped' }).click(); + + cy.findByText( + 'The list must have at least one item. Please add a usage status.' + ).should('not.exist'); + }); + }); }); diff --git a/cypress/e2e/with_mock_data/units.cy.ts b/cypress/e2e/with_mock_data/units.cy.ts deleted file mode 100644 index cf766bf2d..000000000 --- a/cypress/e2e/with_mock_data/units.cy.ts +++ /dev/null @@ -1,75 +0,0 @@ -describe('Units', () => { - beforeEach(() => { - cy.visit('/admin-ims/units'); - }); - afterEach(() => { - cy.clearMocks(); - }); - - it('should render table correctly', () => { - cy.findByText('Value').should('be.visible'); - cy.findByText('Last modified').should('be.visible'); - cy.findByText('Created').should('be.visible'); - - cy.findByText('megapixels').should('be.visible'); - }); - - it('adds a unit and deals with errors correctly', () => { - cy.findByRole('button', { name: 'Add Unit' }).click(); - - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByText('Please enter a value.').should('be.visible'); - - cy.findByLabelText('Value *').type('test_dup'); - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByText( - 'A unit with the same value already exists. Please enter a different value.' - ).should('be.visible'); - - cy.findByLabelText('Value *').clear(); - cy.findByLabelText('Value *').type('test'); - - cy.startSnoopingBrowserMockedRequest(); - - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByRole('dialog').should('not.exist'); - - cy.findBrowserMockedRequests({ - method: 'POST', - url: '/v1/units', - }).should(async (postRequests) => { - expect(postRequests.length).equal(1); - const request = postRequests[0]; - expect(JSON.stringify(await request.json())).equal('{"value":"test"}'); - }); - }); - - it('deletes a unit', () => { - cy.findAllByLabelText('Row Actions').first().click(); - cy.findByText('Delete').click(); - - cy.startSnoopingBrowserMockedRequest(); - - cy.findByRole('button', { name: 'Continue' }).click(); - - cy.findBrowserMockedRequests({ - method: 'DELETE', - url: '/v1/units/:id', - }).should((patchRequests) => { - expect(patchRequests.length).equal(1); - const request = patchRequests[0]; - expect(request.url.toString()).to.contain('1'); - }); - }); - - it('shows error if trying to delete a unit that is in a catalogue category', () => { - cy.findAllByLabelText('Row Actions').eq(1).click(); - cy.findByText('Delete').click(); - - cy.findByRole('button', { name: 'Continue' }).click(); - - cy.findByText( - 'This unit is currently used by one or more catalogue categories. Remove all uses before deleting it here.' - ); - }); -}); diff --git a/cypress/e2e/with_mock_data/usageStatus.cy.ts b/cypress/e2e/with_mock_data/usageStatus.cy.ts deleted file mode 100644 index c762cace8..000000000 --- a/cypress/e2e/with_mock_data/usageStatus.cy.ts +++ /dev/null @@ -1,75 +0,0 @@ -describe('UsageStatus', () => { - beforeEach(() => { - cy.visit('/admin-ims/usage-statuses'); - }); - afterEach(() => { - cy.clearMocks(); - }); - - it('should render table correctly', () => { - cy.findByText('Value').should('be.visible'); - cy.findByText('Last modified').should('be.visible'); - cy.findByText('Created').should('be.visible'); - - cy.findByText('New').should('be.visible'); - }); - - it('adds a usage status and deals with errors correctly', () => { - cy.findByRole('button', { name: 'Add Usage Status' }).click(); - - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByText('Please enter a value.').should('be.visible'); - - cy.findByLabelText('Value *').type('test_dup'); - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByText( - 'A usage status with the same value already exists. Please enter a different value.' - ).should('be.visible'); - - cy.findByLabelText('Value *').clear(); - cy.findByLabelText('Value *').type('test'); - - cy.startSnoopingBrowserMockedRequest(); - - cy.findByRole('button', { name: 'Save' }).click(); - cy.findByRole('dialog').should('not.exist'); - - cy.findBrowserMockedRequests({ - method: 'POST', - url: '/v1/usage-statuses', - }).should(async (postRequests) => { - expect(postRequests.length).equal(1); - const request = postRequests[0]; - expect(JSON.stringify(await request.json())).equal('{"value":"test"}'); - }); - }); - - it('deletes a usage status', () => { - cy.findAllByLabelText('Row Actions').first().click(); - cy.findByText('Delete').click(); - - cy.startSnoopingBrowserMockedRequest(); - - cy.findByRole('button', { name: 'Continue' }).click(); - - cy.findBrowserMockedRequests({ - method: 'DELETE', - url: '/v1/usage-statuses/:id', - }).should((patchRequests) => { - expect(patchRequests.length).equal(1); - const request = patchRequests[0]; - expect(request.url.toString()).to.contain('1'); - }); - }); - - it('shows error if trying to delete a unit that is in a catalogue category', () => { - cy.findAllByLabelText('Row Actions').eq(2).click(); - cy.findByText('Delete').click(); - - cy.findByRole('button', { name: 'Continue' }).click(); - - cy.findByText( - 'This usage status is currently used by one or more items. Remove all uses before deleting it here.' - ); - }); -}); diff --git a/src/admin/__snapshots__/adminCard.component.test.tsx.snap b/src/admin/__snapshots__/adminCard.component.test.tsx.snap new file mode 100644 index 000000000..fc9d9d6cd --- /dev/null +++ b/src/admin/__snapshots__/adminCard.component.test.tsx.snap @@ -0,0 +1,553 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`AdminCard Component > dialog > renders correctly with "dialog" type 1`] = ` + +
+ +
+
+ +
+ +`; + +exports[`AdminCard Component > link > link > renders correctly with "page" type and link 1`] = ` + +
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+ +`; + +exports[`AdminCard Component > link > renders correctly with "page" type and link 1`] = ` + +
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+ +`; + +exports[`AdminCard Component > page > dialog > renders correctly with "dialog" type 1`] = ` + +
+ +
+
+ +
+ +`; + +exports[`AdminCard Component > page > dialog > renders correctly with "dialog" type and link 1`] = ` + +
+ +
+
+ +
+ +`; + +exports[`AdminCard Component > page > dialog > renders correctly with "page" type and link 1`] = ` + +
+ +
+
+ +
+ +`; + +exports[`AdminCard Component > page > renders correctly with "page" type 1`] = ` + +
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+ +`; + +exports[`AdminCard Component > page > renders correctly with "page" type and link 1`] = ` + +
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+
+ +
+
+
+
+

+ Go to Dashboard +

+
+
+
+
+ +
+
+ +`; diff --git a/src/admin/__snapshots__/sparesDefinitionDialog.component.test.tsx.snap b/src/admin/__snapshots__/sparesDefinitionDialog.component.test.tsx.snap new file mode 100644 index 000000000..d2a5ec95d --- /dev/null +++ b/src/admin/__snapshots__/sparesDefinitionDialog.component.test.tsx.snap @@ -0,0 +1,421 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`SparesDefinitionDialog Component > renders correctly when opened 1`] = ` + +