Skip to content

Commit

Permalink
Add Cypress test for uninstalled interface warning
Browse files Browse the repository at this point in the history
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 <amer.mesanovic@secomind.com>
  • Loading branch information
AmerMesanovic committed Jan 22, 2025
1 parent a723d3c commit 1d3cdc4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cypress/e2e/device_page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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);
});
});
});
});
});
28 changes: 28 additions & 0 deletions cypress/fixtures/device_with_custom_introspection.json
Original file line number Diff line number Diff line change
@@ -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
}
}
16 changes: 16 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '!');
}
});
});

0 comments on commit 1d3cdc4

Please sign in to comment.