ExperimentEditor.spec.jsx 5.74 KB
Newer Older
1
2
3
4
5
6
7
8
// @flow
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { spies } from '@test';

import * as Selectors from '@store/selectors.js';
9
import { ExperimentEditor as C } from '.';
10
import {  getValidExperimentObj as getValidObj } from '@helpers/beat';
11
12
13
14
15
16

import testAlgs from '@test/test_algs.json';
import testDbs from '@test/test_dbs.json';
import testExps from '@test/test_exps.json';
import testTcs from '@test/test_tcs.json';

17
18
const envs = {
	'Scientific Python 2.7': {
19
20
21
22
		name: 'Scientific Python 2.7',
		version: '1.0.0',
		queues: {
			Default: {}
23
24
		},
		packages: {}
25
	}
26
};
27

28
describe('<ExperimentEditor />', () => {
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	let wrapper;
	const normalBlocks = Selectors.normalBlocks({ algorithm: testAlgs });
	const analyzerBlocks = Selectors.analyzerBlocks({ algorithm: testAlgs });
	const datasets = Selectors.flattenedDatabases({ database: testDbs });

	afterEach(() => {
		if(wrapper && wrapper.unmount)
			wrapper.unmount();
	});

	describe('accepts', () => {
		const exps = [
		].concat(testExps);

		exps.forEach(function(exp){
44
45
			if(exp.name !== 'user/user/single/1/single_add')
				return;
46
			const saveFunc = () => {};
47
			const updateFunc = () => {};
48
49
50
51
52
53
54
55
56
57
58
59
			const tc = testTcs.find(tc => exp.name.includes(tc.name));

			it(`${ exp.name }`, () => {
				wrapper = mount(
					<C
						data={exp}
						experiments={exps}
						normalBlocks={normalBlocks}
						analyzerBlocks={analyzerBlocks}
						datasets={datasets}
						toolchain={tc}
						saveFunc={saveFunc}
60
						environments={envs}
61
						updateFunc={updateFunc}
62
63
64
65
					/>
				);

				expect(wrapper).to.have.props(
66
					['data', 'experiments', 'normalBlocks', 'analyzerBlocks', 'datasets', 'toolchain', 'saveFunc', 'environments', 'updateFunc']
67
68
69
70
71
				);
			});
		});
	});

72
	describe('creates', () => {
73
74
75
		it(`user/user/single/1/single_add`, () => {
			const expName = 'user/user/single/1/single_add';
			const saveFunc = sinon.spy();
76
77
78
79
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
80
81
82
			const tc = testTcs.find(tc => expName.includes(tc.name));
			wrapper = mount(
				<C
83
					data={getValidObj({name: expName, contents: {}}, tc, [normalBlocks, ...analyzerBlocks])}
84
85
86
87
88
89
					experiments={[]}
					normalBlocks={normalBlocks}
					analyzerBlocks={analyzerBlocks}
					datasets={datasets}
					toolchain={tc}
					saveFunc={saveFunc}
90
					environments={envs}
91
					updateFunc={updateFunc}
92
93
94
				/>
			);

95
96
			//console.log('doing name');

97
			expect(wrapper.props().data).to.have.property('name', expName);
98

99
100
			//console.log('finished name change, doing dataset');

101
			wrapper.find('div.dataset0 select').simulate('change', { target: { value: 'protocol/set (simple/1)'}});
102
103
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.deep.property('datasets', {
104
105
106
107
108
109
110
				'set': {
					'set': 'set',
					'protocol': 'protocol',
					'database': 'simple/1'
				}
			});

111
112
113
			//console.log('finished dataset, doing block');

			wrapper.find('svg #block_echo').simulate('click');
114
			expect(wrapper.find({ name: 'echo', set: 'blocks'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
115
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_add/1'}});
116
117
			expect(updateFunc.callCount).to.equal(2);
			expect(wrapper.props().data.contents).to.have.deep.property('blocks', {
118
119
120
121
122
123
124
125
126
127
128
129
				'echo': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_add/1',
					'outputs': {
						'out_data': 'out'
					},
					parameters: {}
				}
			});

130
131
132
			//console.log('finished block, doing analyzer');

			wrapper.find('svg #block_analysis').simulate('click');
133
			expect(wrapper.find({ name: 'analysis', set: 'analyzers'}).find('.tcBlockBackground').prop('className')).to.include('highlighted');
134
			wrapper.find('div.block0 div.algorithm select').at(0).simulate('change', { target: { value: 'user/integers_echo_analyzer/1'}});
135
136
			expect(updateFunc.callCount).to.equal(3);
			expect(wrapper.props().data.contents).to.have.deep.property('analyzers', {
137
138
139
140
141
142
143
144
145
				'analysis': {
					'inputs': {
						'in_data': 'in'
					},
					'algorithm': 'user/integers_echo_analyzer/1',
					parameters: {},
				}
			});

146
147
			//console.log('finished analyzer, doing env');

148
			wrapper.find('.globals select.env').simulate('change', { target: { value: 'Scientific Python 2.7 (1.0.0)'}});
149
			expect(updateFunc.callCount).to.equal(4);
150
			wrapper.find('.globals select.queue').simulate('change', { target: { value: 'Default'}});
151
152
			expect(updateFunc.callCount).to.equal(5);
			expect(wrapper.props().data.contents).to.have.deep.property('globals', {
153
				'queue': 'Default',
154
				'environment': {
155
156
					'version': '1.0.0',
					'name': 'Scientific Python 2.7'
157
158
159
160
161
162
				},
				'user/integers_add/1': {
					offset: 1
				},
			});

163
164
			//console.log('finished env, doing cache check');

165
			expect(wrapper.props().data).to.be.deep.equal({
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
				'name': 'user/user/single/1/single_add',
				'contents': {
					description: '',
					'analyzers': {
						'analysis': {
							'inputs': {
								'in_data': 'in'
							},
							'algorithm': 'user/integers_echo_analyzer/1',
							parameters: {},
						}
					},
					'datasets': {
						'set': {
							'set': 'set',
							'protocol': 'protocol',
							'database': 'simple/1'
						}
					},
					'blocks': {
						'echo': {
							'inputs': {
								'in_data': 'in'
							},
							'algorithm': 'user/integers_add/1',
							'outputs': {
								'out_data': 'out'
							},
							parameters: {}
						}
					},
					'globals': {
198
						'queue': 'Default',
199
						'environment': {
200
201
							'version': '1.0.0',
							'name': 'Scientific Python 2.7'
202
203
204
205
206
207
208
209
210
211
						},
						'user/integers_add/1': {
							offset: 1
						},
					}
				}
			});
		});
	});
});