PlotterParameterEditor.spec.jsx 3.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// @flow
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { spies } from '@test';

import { PlotterParameterEditor as C } from '.';
import {  getValidPlotterparameterObj as getValidObj } from '@helpers/beat';

import testPlotterParameters from '@test/test_plotterparameters.json';
import testPlotters from '@test/test_plotters.json';

const libs = [];

describe.only('<PlotterParameterEditor />', () => {
	let wrapper;

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

	describe('accepts', () => {
		const plotparams = [
			{
				name: 'test/myplotterparameter/1',
				contents: {
					description: 'A basic plotterparameter as a sanity test for the PlotterParameterEditor',
					data: {
						legend_loc: 'string'
					},
					plotter: "plot/bar/1"
				}
			}
		].concat(testPlotterParameters.map(a => getValidObj(a)));

		plotparams.forEach(function(plotparam){
			const saveFunc = () => {};
			const updateFunc = () => {};
			const plotters = testPlotters.filter(d => d.name.startsWith('plot')).map(testPlotters => testPlotters.name);
			it(`${ plotparam.name }`, () => {
				wrapper = mount(
					<C
						data={getValidObj(plotparam)}
						plotterparameters={plotparams}
						plotters={plotters}
						plotterNames={plotters}
						saveFunc={saveFunc}
						updateFunc={updateFunc}
					/>
				);
				expect(wrapper).to.have.props(
					['data', 'plotterparameters', 'plotters', 'saveFunc', 'updateFunc']
				)
			});
		});
	});

	describe('creates', () => {
		it('test/createplotparam/1', () => {
			const saveFunc = sinon.spy();
			const _updateFunc = (obj) => {
				wrapper.setProps && wrapper.setProps({ data: obj });
			};
			const updateFunc = sinon.spy(_updateFunc);
			const plotparamName = 'test/createplotparam/1';
			const plotters = testPlotters.filter(d => d.name.startsWith('plot')).map(testPlotters => testPlotters);
			wrapper = mount(
				<C
					data={getValidObj({name: plotparamName, contents: {}})}
					plotterparameters={[]}
					plotters={plotters}
					plotterNames={plotters}
					saveFunc={saveFunc}
					updateFunc={updateFunc}
				/>
			);

			expect(wrapper).to.have.props(
				['data', 'plotterparameters', 'plotters', 'saveFunc', 'updateFunc']
			);

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

			expect(wrapper.props().data.contents).to.have.property('description');
			expect(wrapper.props().data.contents).to.have.property('description').with.lengthOf(0);
			wrapper.find('#ppPl select').simulate('change', { target: { value: 'user/anotherploter/1'}});
			expect(updateFunc.callCount).to.equal(0);
			wrapper.find('#ppPl select').simulate('change', { target: { value: 'plot/bar/1'}});
			expect(updateFunc.callCount).to.equal(1);
			expect(wrapper.props().data.contents).to.have.property('plotter', 'plot/bar/1');

			expect(wrapper.props().data.contents).to.have.property('description').with.lengthOf(0);
			expect(wrapper.props().data.contents).to.have.property('plotter').with.lengthOf(10);
			expect(wrapper.props().data.contents).to.have.property('data');
			expect(wrapper.props().data.contents).to.deep.equal({
				'description': '',
				'plotter': 'plot/bar/1',
				'data': {
					'axis-fontsize': 10,
					'bar-alpha': 0.75,
					'bar-norm': true,
					'bar_attributes': '',
					'content_type': 'image/png',
					'dpi': 60,
					'grid': false,
					'height': 300,
					'legend': '',
					'legend-bbox-to-anchor': 1,
					'legend-fontsize': 12,
					'legend-loc': 'best',
					'title': 'Bar plot',
					'title-fontsize': 10,
					'width': 400,
					'xaxis_multiplier': 1,
					'xlabel': '',
					'yaxis_log': false,
					'yaxis_multiplier': 1,
					'ylabel': ''
				}
			});

		});
	});
});