Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

187792765 automation for time series data display #166

Merged
merged 10 commits into from
Jul 17, 2024
177 changes: 177 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,178 @@ 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 a total of 5 seconds
// Note: after 5 sec Cypress starts failing the test because the timing
// isn't perfectly synchronized. A duration of 5 seconds will ensure that
// the trial is at least starting.
const checkTimes = [1, 2, 3, 4, 5]
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
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
nstclair-cc marked this conversation as resolved.
Show resolved Hide resolved
// 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')
// The delete tests are not working now because Cypress won't
// recognize the delete button. Putting this code here for now
// in case it's fixable
// 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"
// cy.on('window:confirm', (txt) => {
// // Assertion to check the text of the confirmation dialog
// expect(txt).to.contains('delete trial? this will delete the trial')
// return true; // This will simulate clicking the "OK" button
// })

// // 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);
nstclair-cc marked this conversation as resolved.
Show resolved Hide resolved
// 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
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
Loading