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

8
import { AlgorithmEditor as C } from '.';
9
import {  getValidAlgorithmObj as getValidObj } from '@helpers/beat';
10 11

import testAlgs from '@test/test_algs.json';
12 13
import testDfs from '@test/test_dfs.json';
import testLibs from '@test/test_libs.json';
14 15 16 17 18 19 20 21 22 23 24 25

const libs = [];
const dfs = [];

describe('<AlgorithmEditor />', () => {
	let wrapper;

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

26 27 28 29 30 31 32 33 34 35
	const aTestAlg = {
		name: 'test/non-analyzer-alg/1',
		contents: {
			language: 'python',
			description: 'A basic algorithm as a sanity test for the AlgorithmEditor',
			groups: [
				{
					name: 'group_1',
					inputs: {
						'input_1': { type: 'test/df/1' },
36
					},
37 38
					outputs: {
						'output_1': { type: 'test/df/2' },
39 40
					},
				}
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
			],
			uses: {
				'library_1': 'a/lib/1',
			},
			parameters: {
				'parameter_1': {
					type: 'string',
					choice: [
						'choice_1',
						'choice_2',
						'choice_3',
					],
					default: 'choice_1',
				}
			},
			// non-analyzer
			splittable: false,
			schema_version: 3.0,
			api_version: 2.0,
			type: 'sequential',
		}

	};
64

65 66 67
	describe('accepts', () => {
		const algs = [
			aTestAlg,
68
		].concat(testAlgs.map(a => getValidObj(a)));
69 70 71

		algs.forEach(function(alg){
			const saveFunc = () => {};
72
			const updateFunc = () => {};
73 74 75
			it(`${ alg.name }`, () => {
				wrapper = mount(
					<C
76
						data={getValidObj(alg)}
77 78 79 80
						algorithms={algs}
						dataformats={dfs}
						libraries={libs}
						saveFunc={saveFunc}
81
						updateFunc={updateFunc}
82 83 84 85
					/>
				);

				expect(wrapper).to.have.props(
86
					['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
87
				).deep.equal(
88
					[alg, algs, dfs, libs, saveFunc, updateFunc]
89 90 91 92 93
				);
			});
		});
	});

Jaden DIEFENBAUGH's avatar
Jaden DIEFENBAUGH committed
94
	describe('creates', () => {
95 96
		it('user/integers_echo/1', () => {
			const saveFunc = sinon.spy();
97 98 99 100
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
101
			const algName = 'user/integers_echo/1';
102 103
			wrapper = mount(
				<C
104
					data={getValidObj({name: algName, contents: {}})}
105 106 107 108
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
109
					updateFunc={updateFunc}
110 111 112 113
				/>
			);

			expect(wrapper).to.have.props(
114
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
115 116
			);

117
			expect(wrapper.props().data).to.have.property('name', algName);
118

119
			wrapper.find('#algSplittable input').prop('onChange')( { target: { checked: true }});
120
			expect(updateFunc.callCount).to.equal(1);
121
			expect(wrapper.props().data.contents).to.have.property('splittable', true);
122

123
			expect(updateFunc.callCount).to.equal(1);
124 125 126
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.have.property('outputs');
127

128
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
129

130
			wrapper.find('.algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
131
			expect(updateFunc.callCount).to.equal(2);
132
			wrapper.find('.algOutput').find('CacheInput').prop('onChange')( { target: { value: 'out_data' }});
133
			expect(updateFunc.callCount).to.equal(3);
134 135

			const ioType = 'system/integer/1';
136
			wrapper.find('.algInput select').prop('onChange')( { target: { value: ioType }});
137
			expect(updateFunc.callCount).to.equal(4);
138
			wrapper.find('.algOutput select').prop('onChange')( { target: { value: ioType }});
139
			expect(updateFunc.callCount).to.equal(5);
140

141 142
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
			expect(wrapper.props().data.contents.groups[0].outputs).to.have.deep.property('out_data', { type: ioType });
143

144
			expect(wrapper.props().data.contents).to.deep.equal({
145 146 147 148 149 150 151 152
				description: '',
				'groups': [
					{
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						},
153
						'name': 'group',
154 155 156 157 158 159 160 161 162 163
						'outputs': {
							'out_data': {
								'type': 'system/integer/1'
							}
						}
					}
				],
				parameters: {},
				uses: {},
				'splittable': true,
164 165 166 167
				'language': 'python',
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
168 169 170
			});
		});

Jaden DIEFENBAUGH's avatar
Jaden DIEFENBAUGH committed
171
		it('user/integers_add/1', () => {
172
			const saveFunc = sinon.spy();
173 174 175 176
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
177
			const algName = 'user/integers_add/1';
178 179
			wrapper = mount(
				<C
180
					data={getValidObj({name: algName, contents: {}})}
181 182 183 184
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
185
					updateFunc={updateFunc}
186 187
				/>
			);
188

189
			expect(wrapper).to.have.props(
190
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
191 192
			);

193
			expect(wrapper.props().data).to.have.property('name', algName);
194

195
			wrapper.find('#algSplittable input').prop('onChange')( { target: { checked: true }});
196
			expect(wrapper.props().data.contents).to.have.property('splittable', true);
197

198 199 200
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.have.property('outputs');
201

202
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
203

204 205
			wrapper.find('.algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
			wrapper.find('.algOutput').find('CacheInput').prop('onChange')( { target: { value: 'out_data' }});
206 207

			const ioType = 'system/integer/1';
208 209
			wrapper.find('.algInput select').prop('onChange')( { target: { value: ioType }});
			wrapper.find('.algOutput select').prop('onChange')( { target: { value: ioType }});
210

211 212
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
			expect(wrapper.props().data.contents.groups[0].outputs).to.have.deep.property('out_data', { type: ioType });
213 214 215 216 217

			wrapper.find('a')
			.findWhere(w => {
				const html = w.html();
				return html && html.includes('Parameters');
218 219 220
			})
			.at(0)
			.simulate('click');
221 222 223

			wrapper.find('button#newParameterBtn').simulate('click');

224 225
			wrapper.find('CacheInput[placeholder="Parameter name..."]').prop('onChange')( { target: { value: 'offset' }});
			wrapper.find('[tabId="1"] select').prop('onChange')( { target: { value: 'int32' }});
226 227
			wrapper.find('input[placeholder="Default"]').simulate('change', { target: { value: '1' }});

228
			expect(wrapper.props().data.contents.parameters).to.have.deep.property('offset', {
229 230 231 232 233 234 235 236 237
				'default': '1',
				'type': 'int32',
				'description': '',
			});

			wrapper.find('a')
			.findWhere(w => {
				const html = w.html();
				return html && html.includes('Libraries');
238 239 240
			})
			.at(0)
			.simulate('click');
241 242 243

			wrapper.find('button#newLibraryBtn').simulate('click');

244 245
			wrapper.find('[tabId="2"] CacheInput[type="text"]').prop('onChange')( { target: { value: 'lib' }});
			wrapper.find('[tabId="2"] select').prop('onChange')( { target: { value: 'user/thelib/1' }});
246

247
			expect(wrapper.props().data.contents.uses).to.have.property('lib', 'user/thelib/1');
248

249
			expect(wrapper.props().data.contents).to.deep.equal({
250 251 252 253 254 255 256 257
				description: '',
				'groups': [
					{
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						},
258
						'name': 'group',
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
						'outputs': {
							'out_data': {
								'type': 'system/integer/1'
							}
						}
					}
				],
				'parameters': {
					'offset': {
						'default': '1',
						'type': 'int32',
						description: '',
					}
				},
				'uses': {
					'lib': 'user/thelib/1'
				},
				'splittable': true,
277 278 279 280
				'language': 'python',
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
281
			});
282
		});
283 284 285

		it('user/integers_echo_analyzer/1', () => {
			const saveFunc = sinon.spy();
286 287 288 289
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
290
			const algName = 'user/integer_echo_analyzer/1';
291 292
			wrapper = mount(
				<C
293
					data={getValidObj({name: algName, contents: {}})}
294 295 296 297
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
298
					updateFunc={updateFunc}
299 300 301 302
				/>
			);

			expect(wrapper).to.have.props(
303
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
304 305
			);

306
			expect(wrapper.props().data).to.have.property('name', algName);
307

308
			wrapper.find('#algAnalyzer input').prop('onChange')( { target: { checked: true }});
309
			expect(wrapper.props().data.contents).to.have.property('results');
310

311 312 313
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.not.have.property('outputs');
314

315
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
316

317
			wrapper.find('.algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
318 319

			const ioType = 'system/integer/1';
320
			wrapper.find('.algInput select').prop('onChange')( { target: { value: ioType }});
321

322
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
323 324 325 326 327

			wrapper.find('a')
			.findWhere(w => {
				const html = w.html();
				return html && html.includes('Results');
328 329 330
			})
			.at(0)
			.simulate('click');
331 332 333 334 335 336

			wrapper.find('button#newResultBtn').simulate('click');
			wrapper.find('button#newResultBtn').simulate('click');
			wrapper.find('button#newResultBtn').simulate('click');
			wrapper.find('button#newResultBtn').simulate('click');

337 338
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(0).prop('onChange')( { target: { value: 'roc' }});
			wrapper.find('[tabId="3"] select').at(0).prop('onChange')( { target: { value: 'plot/isoroc/1' }});
339

340 341
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(1).prop('onChange')( { target: { value: 'plot' }});
			wrapper.find('[tabId="3"] select').at(1).prop('onChange')( { target: { value: 'plot/scatter/1' }});
342

343 344
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(2).prop('onChange')( { target: { value: 'out_data' }});
			wrapper.find('[tabId="3"] select').at(2).prop('onChange')( { target: { value: 'int32' }});
345

346 347
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(3).prop('onChange')( { target: { value: 'bar_plot' }});
			wrapper.find('[tabId="3"] select').at(3).prop('onChange')( { target: { value: 'plot/bar/1' }});
348

349
			expect(wrapper.props().data.contents.results).to.deep.equal({
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
				'roc': {
					'type': 'plot/isoroc/1',
					'display': false
				},
				'plot': {
					'type': 'plot/scatter/1',
					'display': false
				},
				'out_data': {
					'type': 'int32',
					'display': false
				},
				'bar_plot': {
					'type': 'plot/bar/1',
					'display': false
				}
			});
367

368
			expect(wrapper.props().data.contents).to.deep.equal({
369 370 371 372 373 374 375 376
				description: '',
				'groups': [
					{
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						},
377
						'name': 'group'
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
					}
				],
				parameters: {},
				uses: {},
				'language': 'python',
				'results': {
					'roc': {
						'type': 'plot/isoroc/1',
						'display': false
					},
					'plot': {
						'type': 'plot/scatter/1',
						'display': false
					},
					'out_data': {
						'type': 'int32',
						'display': false
					},
					'bar_plot': {
						'type': 'plot/bar/1',
						'display': false
					}
400 401 402 403
				},
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
404 405 406 407 408
			});
		});

		it('user/integers_echo_ignore/1', () => {
			const saveFunc = sinon.spy();
409 410 411 412
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
413
			const algName = 'user/integers_echo/1';
414 415
			wrapper = mount(
				<C
416
					data={getValidObj({name: algName, contents: {}})}
417 418 419 420
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
421
					updateFunc={updateFunc}
422 423 424 425
				/>
			);

			expect(wrapper).to.have.props(
426
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
427 428
			);

429
			expect(wrapper.props().data).to.have.property('name', algName);
430

431
			wrapper.find('#algSplittable input').prop('onChange')( { target: { checked: true }});
432
			expect(wrapper.props().data.contents).to.have.property('splittable', true);
433 434 435

			wrapper.find('button#newGroupBtn').simulate('click');

436 437 438 439 440
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(2);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.have.property('outputs');
			expect(wrapper.props().data.contents.groups[1]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[1]).to.not.have.property('outputs');
441 442

			// Group 1
443
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
444

445 446
			wrapper.find('#endpoint0 .algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
			wrapper.find('#endpoint0 .algOutput').find('CacheInput').prop('onChange')( { target: { value: 'out_data' }});
447 448

			const ioType = 'system/integer/1';
449 450
			wrapper.find('#endpoint0 .algInput select').prop('onChange')( { target: { value: ioType }});
			wrapper.find('#endpoint0 .algOutput select').prop('onChange')( { target: { value: ioType }});
451

452 453
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
			expect(wrapper.props().data.contents.groups[0].outputs).to.have.deep.property('out_data', { type: ioType });
454 455

			// Group 2
456
			expect(wrapper.props().data.contents.groups[1]).to.have.property('name', 'group0');
457 458 459

			wrapper.find('#endpoint1 button#newInputBtn').simulate('click');

460 461
			wrapper.find('#endpoint1 .algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data2' }});
			wrapper.find('#endpoint1 .algInput select').prop('onChange')( { target: { value: ioType }});
462
			expect(wrapper.props().data.contents.groups[1].inputs).to.have.deep.property('in_data2', { type: ioType });
463

464
			expect(wrapper.props().data.contents).to.be.deep.equal({
465 466 467 468 469 470 471 472
				description: '',
				'groups': [
					{
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						},
473
						'name': 'group',
474 475 476 477 478 479 480 481 482 483 484 485
						'outputs': {
							'out_data': {
								'type': 'system/integer/1'
							}
						}
					},
					{
						'inputs': {
							'in_data2': {
								'type': 'system/integer/1'
							}
						},
486
						'name': 'group0'
487 488 489 490 491
					}
				],
				parameters: {},
				uses: {},
				'splittable': true,
492 493 494 495
				'language': 'python',
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
496 497 498 499 500
			});
		});

		it('system/integers_echo_sleep/1', () => {
			const saveFunc = sinon.spy();
501 502 503 504
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
505
			const algName = 'user/integers_echo_sleep/1';
506 507
			wrapper = mount(
				<C
508
					data={getValidObj({name: algName, contents: {}})}
509 510 511 512
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
513
					updateFunc={updateFunc}
514 515 516 517
				/>
			);

			expect(wrapper).to.have.props(
518
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
519 520
			);

521
			expect(wrapper.props().data).to.have.property('name', algName);
522

523
			wrapper.find('#algSplittable input').prop('onChange')( { target: { checked: true }});
524
			expect(wrapper.props().data.contents).to.have.property('splittable', true);
525

526 527 528
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.have.property('outputs');
529

530
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
531

532 533
			wrapper.find('.algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
			wrapper.find('.algOutput').find('CacheInput').prop('onChange')( { target: { value: 'out_data' }});
534 535

			const ioType = 'system/integer/1';
536 537
			wrapper.find('.algInput select').prop('onChange')( { target: { value: ioType }});
			wrapper.find('.algOutput select').prop('onChange')( { target: { value: ioType }});
538

539 540
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
			expect(wrapper.props().data.contents.groups[0].outputs).to.have.deep.property('out_data', { type: ioType });
541 542 543 544 545

			wrapper.find('a')
			.findWhere(w => {
				const html = w.html();
				return html && html.includes('Parameters');
546 547 548
			})
			.at(0)
			.simulate('click');
549 550 551

			wrapper.find('button#newParameterBtn').simulate('click');

552 553
			wrapper.find('CacheInput[placeholder="Parameter name..."]').prop('onChange')( { target: { value: 'delay' }});
			wrapper.find('[tabId="1"] select').prop('onChange')( { target: { value: 'uint32' }});
554 555 556
			wrapper.find('input[placeholder="Default"]').simulate('change', { target: { value: '30' }});
			wrapper.find('input[placeholder="Description"]').simulate('change', { target: { value: 'Time to sleep in seconds' }});

557
			expect(wrapper.props().data.contents.parameters).to.have.deep.property('delay', {
558 559 560 561 562
				'default': '30',
				'type': 'uint32',
				'description': 'Time to sleep in seconds',
			});

563
			expect(wrapper.props().data.contents).to.be.deep.equal({
564 565 566 567 568 569
				description: '',
				uses: {},
				'language': 'python',
				'splittable': true,
				'groups': [
					{
570
						'name': 'group',
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						},
						'outputs': {
							'out_data': {
								'type': 'system/integer/1'
							}
						}
					}
				],
				'parameters': {
					'delay': {
						'default': '30',
						'type': 'uint32',
						'description': 'Time to sleep in seconds'
					}
589 590 591 592
				},
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
593 594 595 596 597
			});
		});

		it('user/integers_mean_analyzer/1', () => {
			const saveFunc = sinon.spy();
598 599 600 601
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
602
			const algName = 'user/integers_mean_analyzer/1';
603 604
			wrapper = mount(
				<C
605
					data={getValidObj({name: algName, contents: {}})}
606 607 608 609
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
610
					updateFunc={updateFunc}
611 612 613 614
				/>
			);

			expect(wrapper).to.have.props(
615
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
616 617
			);

618
			expect(wrapper.props().data).to.have.property('name', algName);
619

620
			wrapper.find('#algAnalyzer input').prop('onChange')( { target: { checked: true }});
621
			expect(wrapper.props().data.contents).to.have.property('results');
622

623 624 625
			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.not.have.property('outputs');
626

627
			expect(wrapper.props().data.contents.groups[0]).to.have.property('name', 'group');
628

629
			wrapper.find('.algInput').find('CacheInput').prop('onChange')( { target: { value: 'in_data' }});
630 631

			const ioType = 'system/integer/1';
632
			wrapper.find('.algInput select').prop('onChange')( { target: { value: ioType }});
633

634
			expect(wrapper.props().data.contents.groups[0].inputs).to.have.deep.property('in_data', { type: ioType });
635 636 637 638 639

			wrapper.find('a')
			.findWhere(w => {
				const html = w.html();
				return html && html.includes('Results');
640 641 642
			})
			.at(0)
			.simulate('click');
643 644 645 646

			wrapper.find('button#newResultBtn').simulate('click');
			wrapper.find('button#newResultBtn').simulate('click');

647 648
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(0).prop('onChange')( { target: { value: 'plot' }});
			wrapper.find('[tabId="3"] select').at(0).prop('onChange')( { target: { value: 'plot/scatter/1' }});
649

650 651
			wrapper.find('[tabId="3"] CacheInput[type="text"]').at(1).prop('onChange')( { target: { value: 'out_data' }});
			wrapper.find('[tabId="3"] select').at(1).prop('onChange')( { target: { value: 'float32' }});
652

653
			expect(wrapper.props().data.contents.results).to.deep.equal({
654 655 656 657 658 659 660 661 662 663
				'plot': {
					'type': 'plot/scatter/1',
					'display': false,
				},
				'out_data': {
					'type': 'float32',
					'display': false
				},
			});

664
			expect(wrapper.props().data.contents).to.deep.equal({
665 666 667 668 669 670
				description: '',
				uses: {},
				parameters: {},
				'language': 'python',
				'groups': [
					{
671
						name: 'group',
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						}
					}
				],
				'results': {
					'out_data': {
						'type': 'float32',
						'display': false
					},
					'plot': {
						'type': 'plot/scatter/1',
						'display': false
					}
688 689 690 691
				},
				schema_version: 3.0,
				api_version: 2.0,
				type: 'sequential',
692
			});
693
		});
694
	});
695

Jaden's avatar
Jaden committed
696
	describe('regression', () => {
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
		it(`adds an output and removes results when toggling from analyzer to normal`, () => {
			const contents = {
				description: '',
				uses: {},
				parameters: {},
				'language': 'python',
				'groups': [
					{
						name: 'group',
						'inputs': {
							'in_data': {
								'type': 'system/integer/1'
							}
						}
					}
				],
				'results': {
					'out_data': {
						'type': 'float32',
						'display': false
					},
					'plot': {
						'type': 'plot/scatter/1',
						'display': false
					}
				}
			};
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const algName = 'user/integers_mean_analyzer/1';
			const obj = {
				name: algName,
				contents,
			};
			wrapper = mount(
				<C
					data={getValidObj(obj)}
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
					updateFunc={updateFunc}
				/>
			);

			expect(wrapper).to.have.props(
				['data', 'algorithms', 'dataformats', 'libraries', 'saveFunc', 'updateFunc']
			);

			expect(wrapper.props().data).to.have.property('name', algName);

			wrapper.find('#algAnalyzer input').prop('onChange')( { target: { checked: false }});
			expect(wrapper.props().data.contents).to.not.have.property('results');

			expect(wrapper.props().data.contents).to.have.property('groups').with.lengthOf(1);
			expect(wrapper.props().data.contents.groups[0]).to.have.property('inputs');
			expect(wrapper.props().data.contents.groups[0]).to.have.property('outputs');
			expect(wrapper.props().data.contents.groups[0].outputs).to.have.deep.property('output', {
				type: ''
			});
		});

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
		it(`properly sets schema_version, api_version, and "type"`, () => {
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const algName = aTestAlg.name;
			wrapper = mount(
				<C
					data={aTestAlg}
					algorithms={[]}
					dataformats={testDfs}
					libraries={testLibs}
					saveFunc={saveFunc}
					updateFunc={updateFunc}
				/>
			);

			wrapper.find('Input[type="select"]#schemaversion').prop('onChange')({ target: { value: 2.0 }});
			wrapper.find('Input[type="select"]#algtype').prop('onChange')({ target: { value: 'autonomous' }});

			expect(wrapper.props().data.contents.schema_version).to.equal(2.0);
			expect(wrapper.props().data.contents.type).to.equal('autonomous');
			expect(wrapper.props().data.contents).to.deep.equal({
				...aTestAlg.contents,
				schema_version: 2.0,
				type: 'autonomous',
			});

			expect(wrapper.find('.badge-success').exists());
		});
	});
794
});