From 60f7903cc94e760374175db365b6e9c0380c1407 Mon Sep 17 00:00:00 2001 From: AmerMesanovic Date: Tue, 7 Jan 2025 08:48:55 +0100 Subject: [PATCH] Add Cypress test for uninstalled interface warning Introduced a test to verify that a warning is displayed when a device's introspection includes an interface that is not installed. Signed-off-by: AmerMesanovic --- cypress/e2e/device_page.cy.js | 15 +++++++++- .../device_with_custom_introspection.json | 28 +++++++++++++++++++ cypress/support/e2e.js | 16 +++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 cypress/fixtures/device_with_custom_introspection.json diff --git a/cypress/e2e/device_page.cy.js b/cypress/e2e/device_page.cy.js index 9662c4eb..93136ea9 100644 --- a/cypress/e2e/device_page.cy.js +++ b/cypress/e2e/device_page.cy.js @@ -17,6 +17,8 @@ describe('Device page tests', () => { cy.fixture('device').as('device'); cy.fixture('device_detailed').as('deviceDetailed'); cy.fixture('groups').as('groups'); + cy.fixture('device_with_custom_introspection').as('deviceWithCustomIntrospection'); + cy.fixture('interfaces').as('interfaces'); cy.intercept('POST', '/appengine/v1/*/groups/*/devices', { statusCode: 201, body: '', @@ -703,7 +705,6 @@ describe('Device page tests', () => { it('correctly renders Device Stats', function () { cy.intercept('GET', '/appengine/v1/*/devices/*', { fixture: 'device_detailed' }); cy.visit(`/devices/${this.deviceDetailed.data.id}/edit`); - const formatBytes = (bytes) => { if (bytes < 1024) { return bytes + 'B'; @@ -906,5 +907,17 @@ describe('Device page tests', () => { }); }); }); + + it.only('displays a warning when the device introspection contains an uninstalled interface', function () { + cy.intercept('GET', '/appengine/v1/*/devices/*', { fixture: 'device_with_custom_introspection' }); + cy.intercept('GET', '/realmmanagement/v1/*/interfaces?detailed=true', { fixture: 'interfaces' }); + cy.visit(`/devices/${this.device.data.id}/edit`); + cy.location('pathname').should('eq', `/devices/${this.device.data.id}/edit`); + Object.entries(this.device.data.introspection).forEach(([interfaceName]) => { + cy.wrap(null).then(() => { + cy.checkInterfaceWarning(interfaceName, this.interfaces.data); + }); + }); + }); }); }); diff --git a/cypress/fixtures/device_with_custom_introspection.json b/cypress/fixtures/device_with_custom_introspection.json new file mode 100644 index 00000000..035dbfa0 --- /dev/null +++ b/cypress/fixtures/device_with_custom_introspection.json @@ -0,0 +1,28 @@ +{ + "data": { + "id": "0ma4SioESHKk28VhYGcW1w", + "aliases": {}, + "introspection": { + "non.existingInterface": { + "major": 2, + "minor": 0, + "exchanged_msgs": 20, + "exchanged_bytes": 200 + }, + "test.astarte.AggregatedObjectInterface": { + "major": 1, + "minor": 0, + "exchanged_msgs": 3, + "exchanged_bytes": 42 + } + }, + "last_connection": null, + "last_credentials_request_ip": null, + "last_disconnection": null, + "last_seen_ip": null, + "attributes": {}, + "previous_interfaces": [], + "total_received_bytes": 0, + "total_received_msgs": 0 + } +} diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 25fc5444..316e5136 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -103,3 +103,19 @@ Cypress.Commands.add( }); }, ); + +Cypress.Commands.add('checkInterfaceWarning', (interfaceName, interfacesData) => { + const interfaceNameString = typeof interfaceName === 'object' ? JSON.stringify(interfaceName) : interfaceName; + const isInterfaceInInterfaces = interfacesData.some(i => i.name.trim().toLowerCase() === interfaceNameString.trim().toLowerCase()); + cy.contains(interfaceNameString) + .parent() + .find('span.d-inline-flex') + .then(($badge) => { + if (isInterfaceInInterfaces) { + cy.wrap($badge).should('not.contain', '!'); + } else { + cy.wrap($badge).should('exist'); + cy.wrap($badge).should('contain', '!'); + } + }); +});