Skip to content

Commit

Permalink
Update cypress testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed May 4, 2023
1 parent 4f3c5be commit ac3c8d2
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ test_html
.yalc
yalc.lock
cypress/videos
results
results
cypress/screenshots/
35 changes: 35 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
viewportWidth: 1440,
viewportHeight: 900,
defaultCommandTimeout: 10000,
reporter: "junit",
experimentalMemoryManagement: true,
numTestsKeptInMemory: 0,

reporterOptions: {
mochaFile: "results/cypress-report.xml",
toConsole: true,
},

e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require("./cypress/plugins/index.js")(on, config);
},
},

component: {
setupNodeEvents(on, config) {},
specPattern: "cypress/component/*.cy.js",
},

component: {
devServer: {
framework: "vue-cli",
bundler: "webpack",
},
},
});
15 changes: 0 additions & 15 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-alert, no-console */
import { mount } from '@cypress/vue';
import { MapContent } from '../../../src/components/index.js';
import { MapContent } from '../../src/components/index.js';

describe('MapContent', () => {

Expand All @@ -10,6 +9,7 @@ describe('MapContent', () => {
cy.fixture('scaffoldMetadata.json').as('metadata');
cy.fixture('scaffoldPrimitive.json').as('primitive');
cy.fixture('stubResponse.json').as('stub');
cy.fixture('simulation_ui.json').as('simulation_ui');
})

it('Workflow testing', () => {
Expand All @@ -21,12 +21,20 @@ describe('MapContent', () => {

cy.intercept('/sparc-api/dataset_info/using_multiple_dois/?dois=*', {statusCode: 200, body: stub.resultResponse}).as("mouseDataset");

cy.intercept('/sparc-api/get-organ-curies?', {statusCode: 200, body: stub.curiesResponse}).as("curieResponse");
cy.intercept('/sparc-api/get-organ-curies', {statusCode: 200, body: stub.curiesResponse}).as("curieResponse");

cy.intercept('/sparc-api/get_featured_datasets_identifiers', {statusCode: 200, body: stub.featuredDatasetResponse}).as("featuredDatasetResponse");

const anatomy_dataset = {
"result": [stub.datasetResult]
};

cy.intercept('/sparc-api/dataset_info/anatomy?identifier=130', {statusCode: 200, body: anatomy_dataset}).as("anatomyResponse");
})

//cy.intercept('GET', 'https://mapcore-demo.org/current/flatmap/v2/**');

mount(MapContent, {
cy.mount(MapContent, {
propsData: {
options: {
sparcApi: "https://mock-test/sparc-api/",
Expand Down Expand Up @@ -68,14 +76,23 @@ describe('MapContent', () => {
//Wait for curie response
cy.wait('@curieResponse', {timeout: 20000});

//Wait for curie response
cy.wait('@featuredDatasetResponse', {timeout: 20000});

//Wait for curie response
cy.wait('@anatomyResponse', {timeout: 20000});

cy.get('.multi-container > .el-loading-parent--relative > .el-loading-mask', {timeout: 30000}).should('not.exist');

//Search for non existance feature, expect not-found text
cy.get('.search-box > .el-input__inner').should('exist').type("NON_EXISTANCE");
cy.get('.toolbar-flex-container > .map-icon > use').should('exist').click();
cy.get('.el-autocomplete > .el-input > .el-input__inner').should('exist').type("NON_EXISTANCE");
cy.get('.search-container > .map-icon > use').should('exist').click();
cy.get('.not-found-text').should('exist');

//Search for Vague nerve, expect not-found text to be gone
cy.get('.search-box > .el-input__inner').should('exist').clear().type("'Vagus Nerve'");
cy.get('.toolbar-flex-container > .map-icon > use').should('exist').click();
cy.get('.el-autocomplete > .el-input > .el-input__inner').should('exist').clear();
cy.get('.el-autocomplete > .el-input > .el-input__inner').should('exist').type("'Vagus Nerve'");
cy.get('.search-container > .map-icon > use').should('exist').click();
cy.get('.not-found-text').should('not.exist');

//Intercept the request and stub it with preloaded fixture
Expand All @@ -91,10 +108,10 @@ describe('MapContent', () => {
})

//Click on the Open 3D Scaffold button
cy.get('.content-container > .el-button').should('be.visible').click();
cy.get('.open-scaffold').should('be.visible').click();

//Check for two content containers
cy.get('.content-container').should('have.length', 2);
cy.get('.contentvuer').should('be.visible').should('have.length', 2);

//Wait for the mouse dataset request
cy.wait('@mouseDataset', {timeout: 20000});
Expand All @@ -112,7 +129,7 @@ describe('MapContent', () => {
cy.get('.dataset-card').should('have.length', 1);

//Check how many tags in the dataset
cy.get('.box-card .container button').should('have.length', 5);
cy.get('.box-card .container button').should('have.length', 6);

//Intercept the request and stub it with preloaded fixture
cy.get('@metadata').then((metadata) => {
Expand Down Expand Up @@ -143,6 +160,11 @@ describe('MapContent', () => {
cy.get('.singlepanel-1 > .toolbar-flex-container > .el-select > .el-input > .el-input__inner').should('exist').click();
cy.get('.singlepanel-1 .el-scrollbar__view >').should('have.length', 4);

cy.get('@simulation_ui').then((simulation_ui) => {
cy.intercept('/sparc-api//sim/dataset/999',
{statusCode: 200, body: simulation_ui});
})

//Check for simulations and open it, should have five items in select now
cy.get('.box-card .container button').contains('Simulations (1)').click();
cy.get('.box-card :nth-child(1) > .details .el-button').click();
Expand Down
88 changes: 88 additions & 0 deletions cypress/fixtures/simulation_ui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"input": [
{
"defaultValue": 0.01,
"id": "dt",
"maximumValue": 0.02,
"minimumValue": 0.001,
"name": "Time step",
"stepValue": 0.001
},
{
"defaultValue": 1000,
"id": "T",
"maximumValue": 3000,
"minimumValue": 1,
"name": "Max time"
},
{
"defaultValue": 0,
"id": "forcing_factor",
"maximumValue": 10,
"minimumValue": 0,
"name": "Forcing factor"
}
],
"output": {
"data": [
{
"id": "time",
"name": "0"
},
{
"id": "rate",
"name": "1"
},
{
"id": "demand",
"name": "2"
},
{
"id": "sympathetic_efferent",
"name": "3"
}
],
"plots": [
{
"xAxisTitle": "Time (s)",
"xValue": "time",
"yAxisTitle": "Rate",
"yValue": "rate"
},
{
"xAxisTitle": "Time (s)",
"xValue": "time",
"yAxisTitle": "Demand",
"yValue": "demand"
},
{
"xAxisTitle": "Time (s)",
"xValue": "time",
"yAxisTitle": "Sympathetic efferent",
"yValue": "sympathetic_efferent"
}
]
},
"parameters": [
{
"name": "dt",
"value": "dt"
},
{
"name": "T",
"value": "T"
},
{
"name": "forcing_factor",
"value": "forcing_factor"
}
],
"simulation": {
"solvers": [
{
"name": "simcore/services/comp/kember-cardiac-model",
"version": "1.0.0"
}
]
}
}
14 changes: 13 additions & 1 deletion cypress/fixtures/stubResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"dataset_revision": "",
"dataset_version": "3",
"description": "Test this",
"doi": "https://doi.org/10.26275/234fd-12312sd",
"doi": "https://doi.org/10.26275/z1ga-dflp",
"identifier": "N:dataset:a59a7c4c-0234534e24b31",
"mbf-segmentation": [
{
Expand Down Expand Up @@ -234,6 +234,15 @@
]
},
"datasetResult": {
"anatomy": {
"organ": [
{
"curie":"UBERON:0001255",
"matchingStatus":"Exact Match",
"name":"urinary bladder"
}
]
},
"id": 32,
"sourceDatasetId": 98,
"name": "Test dataset",
Expand Down Expand Up @@ -333,5 +342,8 @@
}
]
}
},
"featuredDatasetResponse": {
"identifiers":["130"]
}
}
12 changes: 12 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
9 changes: 8 additions & 1 deletion cypress/support/index.js → cypress/support/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************
// This example support/index.js is processed and
// This example support/component.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
Expand All @@ -18,3 +18,10 @@ import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/vue2'

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(MyComponent)
Loading

0 comments on commit ac3c8d2

Please sign in to comment.