Commit bbd42e2a authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH

[js][exp] refactor exp editor and tests

parent 1dbb4ab7
...@@ -7,6 +7,7 @@ import { spies } from '@test'; ...@@ -7,6 +7,7 @@ import { spies } from '@test';
import * as Selectors from '@store/selectors.js'; import * as Selectors from '@store/selectors.js';
import { ExperimentEditor as C } from '.'; import { ExperimentEditor as C } from '.';
import { getValidExperimentObj as getValidObj } from '@helpers/beat';
import testAlgs from '@test/test_algs.json'; import testAlgs from '@test/test_algs.json';
import testDbs from '@test/test_dbs.json'; import testDbs from '@test/test_dbs.json';
...@@ -40,7 +41,10 @@ describe('<ExperimentEditor />', () => { ...@@ -40,7 +41,10 @@ describe('<ExperimentEditor />', () => {
].concat(testExps); ].concat(testExps);
exps.forEach(function(exp){ exps.forEach(function(exp){
if(exp.name !== 'user/user/single/1/single_add')
return;
const saveFunc = () => {}; const saveFunc = () => {};
const updateFunc = () => {};
const tc = testTcs.find(tc => exp.name.includes(tc.name)); const tc = testTcs.find(tc => exp.name.includes(tc.name));
it(`${ exp.name }`, () => { it(`${ exp.name }`, () => {
...@@ -54,11 +58,12 @@ describe('<ExperimentEditor />', () => { ...@@ -54,11 +58,12 @@ describe('<ExperimentEditor />', () => {
toolchain={tc} toolchain={tc}
saveFunc={saveFunc} saveFunc={saveFunc}
environments={envs} environments={envs}
updateFunc={updateFunc}
/> />
); );
expect(wrapper).to.have.props( expect(wrapper).to.have.props(
['data', 'experiments', 'normalBlocks', 'analyzerBlocks', 'datasets', 'toolchain', 'saveFunc', 'environments'] ['data', 'experiments', 'normalBlocks', 'analyzerBlocks', 'datasets', 'toolchain', 'saveFunc', 'environments', 'updateFunc']
); );
}); });
}); });
...@@ -68,10 +73,14 @@ describe('<ExperimentEditor />', () => { ...@@ -68,10 +73,14 @@ describe('<ExperimentEditor />', () => {
it(`user/user/single/1/single_add`, () => { it(`user/user/single/1/single_add`, () => {
const expName = 'user/user/single/1/single_add'; const expName = 'user/user/single/1/single_add';
const saveFunc = sinon.spy(); const saveFunc = sinon.spy();
const _updateFunc = (obj) => {
wrapper.setProps && wrapper.setProps({ data: obj });
};
const updateFunc = sinon.spy(_updateFunc);
const tc = testTcs.find(tc => expName.includes(tc.name)); const tc = testTcs.find(tc => expName.includes(tc.name));
wrapper = mount( wrapper = mount(
<C <C
data={{name: expName, contents: {}}} data={getValidObj({name: expName, contents: {}}, tc, [normalBlocks, ...analyzerBlocks])}
experiments={[]} experiments={[]}
normalBlocks={normalBlocks} normalBlocks={normalBlocks}
analyzerBlocks={analyzerBlocks} analyzerBlocks={analyzerBlocks}
...@@ -79,17 +88,19 @@ describe('<ExperimentEditor />', () => { ...@@ -79,17 +88,19 @@ describe('<ExperimentEditor />', () => {
toolchain={tc} toolchain={tc}
saveFunc={saveFunc} saveFunc={saveFunc}
environments={envs} environments={envs}
updateFunc={updateFunc}
/> />
); );
//console.log('doing name'); //console.log('doing name');
expect(wrapper.state('cache')).to.have.property('name', expName); expect(wrapper.props().data).to.have.property('name', expName);
//console.log('finished name change, doing dataset'); //console.log('finished name change, doing dataset');
wrapper.find('div.dataset0 select').simulate('change', { target: { value: 'protocol/set (simple/1)'}}); wrapper.find('div.dataset0 select').simulate('change', { target: { value: 'protocol/set (simple/1)'}});
expect(wrapper.state('cache').contents).to.have.deep.property('datasets', { expect(updateFunc.callCount).to.equal(1);
expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
'set': { 'set': {
'set': 'set', 'set': 'set',
'protocol': 'protocol', 'protocol': 'protocol',
...@@ -102,7 +113,8 @@ describe('<ExperimentEditor />', () => { ...@@ -102,7 +113,8 @@ describe('<ExperimentEditor />', () => {
wrapper.find('svg #block_echo').simulate('click'); wrapper.find('svg #block_echo').simulate('click');
expect(wrapper.find({ name: 'echo', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted'); expect(wrapper.find({ name: 'echo', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_add/1'}}); wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_add/1'}});
expect(wrapper.state('cache').contents).to.have.deep.property('blocks', { expect(updateFunc.callCount).to.equal(2);
expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
'echo': { 'echo': {
'inputs': { 'inputs': {
'in_data': 'in' 'in_data': 'in'
...@@ -120,7 +132,8 @@ describe('<ExperimentEditor />', () => { ...@@ -120,7 +132,8 @@ describe('<ExperimentEditor />', () => {
wrapper.find('svg #block_analysis').simulate('click'); wrapper.find('svg #block_analysis').simulate('click');
expect(wrapper.find({ name: 'analysis', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted'); expect(wrapper.find({ name: 'analysis', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_echo_analyzer/1'}}); wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_echo_analyzer/1'}});
expect(wrapper.state('cache').contents).to.have.deep.property('analyzers', { expect(updateFunc.callCount).to.equal(3);
expect(wrapper.props().data.contents).to.have.deep.property('analyzers', {
'analysis': { 'analysis': {
'inputs': { 'inputs': {
'in_data': 'in' 'in_data': 'in'
...@@ -133,8 +146,10 @@ describe('<ExperimentEditor />', () => { ...@@ -133,8 +146,10 @@ describe('<ExperimentEditor />', () => {
//console.log('finished analyzer, doing env'); //console.log('finished analyzer, doing env');
wrapper.find('.globals select.env').simulate('change', { target: { value: 'Scientific Python 2.7 (1.0.0)'}}); wrapper.find('.globals select.env').simulate('change', { target: { value: 'Scientific Python 2.7 (1.0.0)'}});
expect(updateFunc.callCount).to.equal(4);
wrapper.find('.globals select.queue').simulate('change', { target: { value: 'Default'}}); wrapper.find('.globals select.queue').simulate('change', { target: { value: 'Default'}});
expect(wrapper.state('cache').contents).to.have.deep.property('globals', { expect(updateFunc.callCount).to.equal(5);
expect(wrapper.props().data.contents).to.have.deep.property('globals', {
'queue': 'Default', 'queue': 'Default',
'environment': { 'environment': {
'version': '1.0.0', 'version': '1.0.0',
...@@ -147,7 +162,7 @@ describe('<ExperimentEditor />', () => { ...@@ -147,7 +162,7 @@ describe('<ExperimentEditor />', () => {
//console.log('finished env, doing cache check'); //console.log('finished env, doing cache check');
expect(wrapper.state('cache')).to.be.deep.equal({ expect(wrapper.props().data).to.be.deep.equal({
'name': 'user/user/single/1/single_add', 'name': 'user/user/single/1/single_add',
'contents': { 'contents': {
description: '', description: '',
......
...@@ -457,6 +457,9 @@ ...@@ -457,6 +457,9 @@
"environment": { "environment": {
"version": "1.2.0", "version": "1.2.0",
"name": "Python 2.7" "name": "Python 2.7"
},
"user/integers_add/1": {
"offset": 2
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment