Skip to content

Commit

Permalink
Merge pull request #4309 from FlowFuse/fix-bulk-intermittant-e2e-tests
Browse files Browse the repository at this point in the history
Fix bulk intermittent e2e tests
  • Loading branch information
cstns authored Aug 2, 2024
2 parents c547148 + 70d2c8d commit 19f6fe1
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions test/e2e/frontend/cypress/tests/devices/bulk.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="cypress" />
describe('FlowForge - Devices', () => {
beforeEach(() => {
cy.login('bob', 'bbPassword')
Expand Down Expand Up @@ -31,6 +32,10 @@ describe('FlowForge - Devices', () => {
cy.wait(['@getDevices']).then(({ response }) => {
const devices = response.body.devices

// initial checks to help better understand test fail output
expect(devices).to.be.an('array')
expect(devices.length).to.be.greaterThan(3)

// select a single device
cy.get('[data-el="devices-browser"] tbody tr').eq(0).find('.checkbox').click()
// click the "Delete" button
Expand All @@ -51,9 +56,17 @@ describe('FlowForge - Devices', () => {

// select all devices
cy.get('[data-el="devices-browser"] thead .checkbox').click()

// introduce a small delay to ensure the devices are selected before continuing
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(30)

// ensure the delete button is now enabled
cy.get('[data-action="bulk-delete-devices"]').should('not.be.disabled')
// click the "Delete" button
cy.get('[data-action="bulk-delete-devices"]').click()
// ensure the dialog is visible and has the correct number of devices listed
cy.get('[data-el="team-bulk-device-delete-dialog"]').should('be.visible')
cy.get('[data-el="team-bulk-device-delete-dialog"] ul li').should('have.length', devices.length)

// ensure all device names are displayed in the dialog
Expand All @@ -71,17 +84,34 @@ describe('FlowForge - Devices', () => {
cy.wait(['@getDevices']).then(({ response }) => {
const devices = response.body.devices

// initial checks to help better understand test fail output
expect(devices).to.be.an('array')
expect(devices.length).to.be.greaterThan(3)

// wait for device browser to load table
cy.get('[data-el="devices-browser"] tbody tr').should('have.length', devices.length)

// find 3 sacrificial devices with names ending "bulk-test-#" (where # is 1 ~ 3)
const sacrificialDevices = devices.filter((device) => device.name.match(/bulk-test-\d$/))
// select the sacrificial devices. NOTE the .chekbox is in col0 but the text is in col1

// select the sacrificial devices. NOTE the .checkbox is in col0 but the text is in col1
sacrificialDevices.forEach((device) => {
cy.get('[data-el="devices-browser"] tbody tr').contains(device.name).parent().closest('tr').find('.checkbox').click()
cy.get('[data-el="devices-browser"] tbody tr').contains(device.name).parent().parent().find('.checkbox').click()
})

// introduce a delay to ensure the devices are selected before continuing
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(30)

// ensure 3 devices are selected
cy.get('[data-el="devices-browser"] tbody tr input[type="checkbox"]:checked').should('have.length', 3)

// click the "Delete" button
cy.get('[data-action="bulk-delete-devices"]').should('not.be.disabled')
cy.get('[data-action="bulk-delete-devices"]').click()

// click the "Confirm" button
// click the dialog "Confirm" button
cy.get('[data-el="team-bulk-device-delete-dialog"]').should('be.visible')
cy.get('[data-el="team-bulk-device-delete-dialog"] button').contains('Confirm').click()

// wait for the devices API call to complete
Expand Down

0 comments on commit 19f6fe1

Please sign in to comment.