Skip to content

Commit

Permalink
Merge pull request #166 from concord-consortium/187792765-automation-…
Browse files Browse the repository at this point in the history
…for-time-series-data-display

187792765 automation for time series data display
  • Loading branch information
nstclair-cc authored Jul 17, 2024
2 parents c49a2f6 + 4fb8c38 commit 9cebb35
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"video": false,
"fixturesFolder": false,
"supportFile": false,
"defaultCommandTimeout": 8000
"defaultCommandTimeout": 12000
}
166 changes: 166 additions & 0 deletions cypress/integration/branch/experiment.setup.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ExperimentSetup from "../../supports/elements/ExperimentSetup"
import SensorData from "../../supports/elements/SensorData"

context("Testing Experiment Selection View", () => {

Expand All @@ -15,6 +16,8 @@ context("Testing Experiment Selection View", () => {
let studySite2 = "Study Site #2"
let defaultSchoolyardInvestigation = "Schoolyard Investigation #1"

let sensorData = new SensorData();

before(() => {
cy.visit(url);
});
Expand Down Expand Up @@ -100,4 +103,167 @@ context("Testing Experiment Selection View", () => {
experimentSetup.deleteExperiment()
})
})

describe("Tests Data Trial", () => {

it("collect time series data from (mock) sensor", () => {

// Constants will check that the input fields are disabled
const labelSelectors = [
'input[placeholder="Label #1"]',
'input[placeholder="Label #2"]',
'input[placeholder="Label #3"]',
'input[placeholder="Label #4"]',
'input[placeholder="Label #5"]'
]
// Open a new Data Trial
experimentSetup.openNewExperiment('Data Trial')

sensorData.getExperimentOptionsMenu() // gets the click in the helper function

// Select and verify the "Mocked Sensor: Temperature" option
cy.log('Select and verify mocked sensor')
sensorData.selectMenuOption('Connect')
sensorData.selectSensor('Temperature')
cy.get('div.sensor-module-connectionLabel-vortex select')
.should('have.value', '1')
// Assert the connection status
sensorData.getSensorConnectionStatus()
.should('contain.text', 'Connected: Mocked Sensor')

// Select the sample rate
sensorData.selectSample('100/sec')

// Start recording data trial
sensorData.getRecordButton().first().click()
// Check the data collection every 1 second for the duration of the run (10 sec)
const checkTimes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
checkTimes.forEach((time) => {
cy.wait(time * 100)
cy.get('.data-table-field-module-sparkgraphContainer-vortex')
.contains(`${time} sec`)
.should('be.visible')
})

// Check that the selectors are disabled during collection run.
labelSelectors.forEach((selector) => {
cy.get(selector).should('be.disabled')
// Check that the connected icon button is disabled
cy.get('div.sensor-module-connectionLabel-vortex select').should('be.disabled')
// Check that the sample rate dropdown is disabled
cy.get('.sensor-module-tsvInfoRow-vortex select').should('be.disabled')
})
// Checks to make sure that the run automatically stops after the max time
// and final display is 10 sec
cy.wait(10000)
cy.get('.data-table-field-module-sparkgraphContainer-vortex')
.contains(`10 sec`)

// Checks that it's possible to stop recording in the middle of a time trial
// also checks that UI disables during a run
cy.log('checks that it is possible to stop recording in the middle of a time trial')
sensorData.getRecordButton().last().click()
labelSelectors.forEach((selector) => {
cy.get(selector).should('be.disabled')
// Check that the connected icon button is disabled
cy.get('div.sensor-module-connectionLabel-vortex select').should('be.disabled')

// Check that the sample rate dropdown is disabled
cy.get('.sensor-module-tsvInfoRow-vortex select').should('be.disabled')
})
cy.wait(5000)
sensorData.getRecordButton().last().click()

// TODO: add checks that time series data displays
// for all elements in the table elements
// Blocker: PT #187949831
// also fix expected to find element 5 error (probably just need x-1)
// for (let i = 0; i <= 5; i++) {
// sensorData.getDataTrialRow(i).within(() => {
// sensorData.getRecordButton().click()
// cy.wait(20000) // wait for new sensor values
// })
// }

cy.log('Delete the trial run')
sensorData.getRecordButton().first().click({force:true})
cy.wait(1000)
// Wait for the confirmation dialog to appear and verify the text
// Check if the confirmation dialog is present and interact with it
// Intercept the window confirm dialog and automatically click "OK"
experimentSetup.deleteDataTrialExperiment()
// Checks to make sure that the top line was deleted and defaulted.
cy.get('.data-table-field-module-sparkgraphContainer-vortex').first()
.contains(/^0 sec$/)
.should('be.visible')
cy.get(labelSelectors[0]).should('have.attr', 'placeholder', 'Label #1')
})
it("checks that labels can be renamed and retain new names after a data trial run", () => {
cy.visit(url);
// Define the label selectors and new labels
const labelSelectors = [
'input[placeholder="Label #1"]',
'input[placeholder="Label #2"]',
'input[placeholder="Label #3"]',
'input[placeholder="Label #4"]',
'input[placeholder="Label #5"]'
]
const newLabels = [
'New Label #1',
'New Label #2',
'New Label #3',
'New Label #4',
'New Label #5'
]

// Open a new Data Trial
experimentSetup.openNewExperiment('Data Trial')

sensorData.getExperimentOptionsMenu() // gets the click in the helper function

// Select and verify the "Mocked Sensor: Force" option
// Used force sensor to vary it up for QA
cy.log('Select and verify mocked sensor')
sensorData.selectMenuOption('Connect')
sensorData.selectSensor('Force')
cy.get('div.sensor-module-connectionLabel-vortex select')
.should('have.value', '0')
// Assert the connection status
sensorData.getSensorConnectionStatus()
.should('contain.text', 'Connected: Mocked Sensor')

// Select the sample rate
sensorData.selectSample('20/sec')

// Ensure the input fields are not disabled before the collection run and rename labels
labelSelectors.forEach((selector, index) => {
cy.get(selector)
.should('not.be.disabled')
.clear()
.type(newLabels[index])
.should('have.value', newLabels[index])
})

// Start the data collection
sensorData.getRecordButton().first().click()

// Check that the selectors are disabled during collection run
// (this checks that the run is going)
labelSelectors.forEach((selector) => {
cy.get(selector).should('be.disabled')
})

// Wait for the data collection to go a bit (adjust time as necessary)
cy.wait(5000)
// stop the data collection
sensorData.getRecordButton().first().click()

// After the data collection, check that the labels retain their new names
labelSelectors.forEach((selector, index) => {
cy.get(selector)
.should('not.be.disabled')
.should('have.value', newLabels[index])
})
})
})
})
36 changes: 26 additions & 10 deletions cypress/integration/branch/sensor.data.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ExperimentSetup from "../../supports/elements/ExperimentSetup"
import SensorData from "../../supports/elements/SensorData";

context.skip("Testing Experiment Selection View", () => {
context("Testing Experiment Selection View", () => {

//const branch = "master"

Expand Down Expand Up @@ -70,23 +70,31 @@ context.skip("Testing Experiment Selection View", () => {
})

describe("Sensor Connection", () => {

it("connects to (mock) sensor", () => {
sensorData.getExperimentOptionsMenu().should('be.visible').click()
sensorData.selectMenuOption('Connect')
cy.wait(2000)
sensorData.getTab('Collect').should('be.visible').click()
sensorData.getSensorConnectionStatus().contains('No Sensor Connected').click()
// Assert the connection status
sensorData.getSensorConnectionStatus()
.should('contain.text', 'Connected: Mocked Sensor')
})
it("returning to experiments list should disconnect from sensor", () => {
sensorData.getBackButton().click()
experimentSetup.getExperiment('Schoolyard Investigation', 1).click()
sensorData.getTab('Collect').click()
// Assert the disconnect status
sensorData.getSensorConnectionStatus().should('contain', 'No Sensor Connected')
sensorData.getExperimentOptionsMenu().click()
sensorData.getExperimentOptionsMenu() // gets the click in the helper function
sensorData.selectMenuOption('Connect')
cy.wait(2000)
// Assert the connection status
sensorData.getSensorConnectionStatus()
.should('contain.text', 'Connected: Mocked Sensor')
})
it("verifies enabled sensor connection UI", () => {
sensorData.assertRecordButtonStatus('enabled')
sensorData.getBackButton().click()
experimentSetup.getExperiment('Schoolyard Investigation', 1).click()
sensorData.getTab('Collect').click()
sensorData.getExperimentOptionsMenu() // gets the click in the helper function
sensorData.selectMenuOption('Connect')
sensorData.getSensorConnectionStatus().contains(sensorLabels.mockSensorLabel)
sensorData.getConnectedSensorValue('Temperature').should('not.contain', '--')
// Not able to get a second sensor value, Temp is enough for now
Expand All @@ -95,15 +103,23 @@ context.skip("Testing Experiment Selection View", () => {
// sensorData.getConnectedSensorValue('Light').should('not.contain','--')
})
it("disconnects from mock sensor and verify UI", () => {
sensorData.getExperimentOptionsMenu().click()
sensorData.getBackButton().click()
experimentSetup.getExperiment('Schoolyard Investigation', 1).click()
sensorData.getTab('Collect').click()
sensorData.getExperimentOptionsMenu() // gets the click in the helper function
sensorData.selectMenuOption('Connect')
sensorData.getExperimentOptionsMenu()
sensorData.selectMenuOption('Disconnect')

sensorData.getSensorConnectionStatus().contains('No Sensor Connected')
sensorData.getDisconnectSensorStateIcon().should('exist')
sensorData.getDisconnectedSensorValue('Temperature').should('contain', '--')
})
it("collects data from (mock) sensor", () => {
sensorData.getExperimentOptionsMenu().click()
sensorData.getBackButton().click()
experimentSetup.getExperiment('Schoolyard Investigation', 1).click()
sensorData.getTab('Collect').click()
sensorData.getExperimentOptionsMenu() // gets the click in the helper function
sensorData.selectMenuOption('Connect')

for (let i = 0; i <= 5; i++) {
Expand Down
6 changes: 5 additions & 1 deletion cypress/supports/elements/ExperimentSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class ExperimentSetup {
cy.get('.menu-module-menu-vortex').contains('Delete').click()
})
}

deleteDataTrialExperiment() {
return cy.get('[data-test="record-sensor"]').first().click()//.then(() => {
//cy.get('.menu-module-menu-vortex').contains('Delete').click()
// })
}
// Label Tab UI selectors needed

getBackButton() {
Expand Down
49 changes: 47 additions & 2 deletions cypress/supports/elements/SensorData.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,53 @@ class SensorData {
cy.get('.sensor-value-module-connectedValue-vortex')
})
}

selectSensor(input){
// Click to focus on the select dropdown (adjust the selector as needed)
cy.get('div.sensor-module-connectionLabel-vortex select').focus();

if (input === 'Force') {
// Select the "Mocked Sensor: Force" option
cy.get('div.sensor-module-connectionLabel-vortex select').select('Mocked Sensor: Force');
return 'Mocked Sensor: Force';
} else if (input === 'Temperature') {
// Select the "Mocked Sensor: Temperature" option
cy.get('div.sensor-module-connectionLabel-vortex select').select('Mocked Sensor: Temperature');
return 'Mocked Sensor: Temperature';
} else {
throw new Error('Invalid input: please specify either "Force" or "Temperature"');
}
}
selectSample(input) {
// Click to focus on the select dropdown (adjust the selector as needed)
cy.get('div.sensor-module-tsvInfoRow-vortex select').focus();

// Define the valid options
const options = [
'0.1/sec',
'0.5/sec',
'1/sec',
'2/sec',
'5/sec',
'20/sec',
'50/sec',
'100/sec'
];

// Check if the input is one of the valid options
if (options.includes(input)) {
// Select the specified option
cy.get('div.sensor-module-tsvInfoRow-vortex select').select(input);
return input;
} else {
throw new Error(`Invalid input: please specify one of the following options: ${options.join(', ')}`);
}
}
getDataRow(index) {
return cy.get('.data-table-field-module-refreshSensorReading-vortex').eq(index - 1).parent().parent()
}
getDataTrialRow(index) {
return cy.get('.data-table-field-module-refreshSensorReading-vortex').eq(index).parent().parent()
}

getCompletedDataRow(index) {
// this is only the complete data row with data recorded from sensor/mock sensor
Expand All @@ -63,6 +106,9 @@ class SensorData {
getExperimentOptionsMenu() {
return cy.get('.data-table-field-module-dataTable-vortex').within(() => {
cy.get('.menu-module-menuIcon-vortex')
.should('exist')
.and('be.visible')
.click({ force: true }) // click is here to get the helper function to work
})
}

Expand All @@ -74,7 +120,6 @@ class SensorData {
getRecordButton() {
return cy.get('[data-test="record-sensor"]')
}

assertRecordButtonStatus(status) {
if (status == 'enabled') {
return this.getRecordButton().should('have.class', 'data-table-field-module-active-vortex')
Expand Down

0 comments on commit 9cebb35

Please sign in to comment.