@pie-lib/config-ui 11.9.25-next.0 → 11.10.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +13 -115
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/package.json +8 -5
  4. package/src/__tests__/__snapshots__/langs.test.jsx.snap +32 -0
  5. package/src/__tests__/__snapshots__/settings-panel.test.js.snap +115 -0
  6. package/src/__tests__/__snapshots__/two-choice.test.js.snap +171 -0
  7. package/src/__tests__/choice-utils.test.js +12 -0
  8. package/src/__tests__/langs.test.jsx +37 -0
  9. package/src/__tests__/number-text-field.test.jsx +148 -0
  10. package/src/__tests__/settings-panel.test.js +204 -0
  11. package/src/__tests__/two-choice.test.js +24 -0
  12. package/src/alert-dialog.jsx +27 -7
  13. package/src/checkbox.jsx +8 -1
  14. package/src/choice-configuration/__tests__/__snapshots__/feedback-menu.test.jsx.snap +51 -0
  15. package/src/choice-configuration/__tests__/__snapshots__/index.test.jsx.snap +519 -0
  16. package/src/choice-configuration/__tests__/feedback-menu.test.jsx +10 -0
  17. package/src/choice-configuration/__tests__/index.test.jsx +92 -0
  18. package/src/choice-configuration/index.jsx +14 -3
  19. package/src/feedback-config/__tests__/__snapshots__/feedback-config.test.jsx.snap +27 -0
  20. package/src/feedback-config/__tests__/__snapshots__/feedback-selector.test.jsx.snap +38 -0
  21. package/src/feedback-config/__tests__/feedback-config.test.jsx +71 -0
  22. package/src/feedback-config/__tests__/feedback-selector.test.jsx +60 -0
  23. package/src/feedback-config/feedback-selector.jsx +0 -0
  24. package/src/inputs.jsx +9 -2
  25. package/src/layout/__tests__/__snapshots__/config.layout.test.jsx.snap +59 -0
  26. package/src/layout/__tests__/config.layout.test.jsx +42 -0
  27. package/src/layout/__tests__/layout-content.test.jsx +3 -0
  28. package/src/layout/config-layout.jsx +16 -8
  29. package/src/number-text-field-custom.jsx +86 -28
  30. package/src/number-text-field.jsx +6 -5
  31. package/src/radio-with-label.jsx +6 -2
  32. package/src/settings/index.js +2 -1
  33. package/src/settings/panel.jsx +5 -2
  34. package/src/settings/settings-radio-label.jsx +6 -2
  35. package/src/settings/toggle.jsx +20 -2
  36. package/src/tags-input/__tests__/__snapshots__/index.test.jsx.snap +170 -0
  37. package/src/tags-input/__tests__/index.test.jsx +62 -0
  38. package/README.md +0 -12
  39. package/lib/alert-dialog.js +0 -44
  40. package/lib/alert-dialog.js.map +0 -1
  41. package/lib/checkbox.js +0 -94
  42. package/lib/checkbox.js.map +0 -1
  43. package/lib/choice-configuration/feedback-menu.js +0 -164
  44. package/lib/choice-configuration/feedback-menu.js.map +0 -1
  45. package/lib/choice-configuration/index.js +0 -434
  46. package/lib/choice-configuration/index.js.map +0 -1
  47. package/lib/choice-utils.js +0 -54
  48. package/lib/choice-utils.js.map +0 -1
  49. package/lib/feedback-config/feedback-selector.js +0 -195
  50. package/lib/feedback-config/feedback-selector.js.map +0 -1
  51. package/lib/feedback-config/group.js +0 -75
  52. package/lib/feedback-config/group.js.map +0 -1
  53. package/lib/feedback-config/index.js +0 -189
  54. package/lib/feedback-config/index.js.map +0 -1
  55. package/lib/form-section.js +0 -46
  56. package/lib/form-section.js.map +0 -1
  57. package/lib/help.js +0 -147
  58. package/lib/help.js.map +0 -1
  59. package/lib/index.js +0 -216
  60. package/lib/index.js.map +0 -1
  61. package/lib/input.js +0 -139
  62. package/lib/input.js.map +0 -1
  63. package/lib/inputs.js +0 -133
  64. package/lib/inputs.js.map +0 -1
  65. package/lib/langs.js +0 -179
  66. package/lib/langs.js.map +0 -1
  67. package/lib/layout/config-layout.js +0 -126
  68. package/lib/layout/config-layout.js.map +0 -1
  69. package/lib/layout/index.js +0 -24
  70. package/lib/layout/index.js.map +0 -1
  71. package/lib/layout/layout-contents.js +0 -191
  72. package/lib/layout/layout-contents.js.map +0 -1
  73. package/lib/layout/settings-box.js +0 -86
  74. package/lib/layout/settings-box.js.map +0 -1
  75. package/lib/mui-box/index.js +0 -79
  76. package/lib/mui-box/index.js.map +0 -1
  77. package/lib/number-text-field-custom.js +0 -367
  78. package/lib/number-text-field-custom.js.map +0 -1
  79. package/lib/number-text-field.js +0 -268
  80. package/lib/number-text-field.js.map +0 -1
  81. package/lib/radio-with-label.js +0 -41
  82. package/lib/radio-with-label.js.map +0 -1
  83. package/lib/settings/display-size.js +0 -77
  84. package/lib/settings/display-size.js.map +0 -1
  85. package/lib/settings/index.js +0 -141
  86. package/lib/settings/index.js.map +0 -1
  87. package/lib/settings/panel.js +0 -460
  88. package/lib/settings/panel.js.map +0 -1
  89. package/lib/settings/settings-radio-label.js +0 -45
  90. package/lib/settings/settings-radio-label.js.map +0 -1
  91. package/lib/settings/toggle.js +0 -56
  92. package/lib/settings/toggle.js.map +0 -1
  93. package/lib/tabs/index.js +0 -110
  94. package/lib/tabs/index.js.map +0 -1
  95. package/lib/tags-input/index.js +0 -198
  96. package/lib/tags-input/index.js.map +0 -1
  97. package/lib/two-choice.js +0 -180
  98. package/lib/two-choice.js.map +0 -1
  99. package/lib/with-stateful-model.js +0 -84
  100. package/lib/with-stateful-model.js.map +0 -1
@@ -0,0 +1,148 @@
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import { NumberTextField } from '../number-text-field';
4
+ import TextField from '@material-ui/core/TextField';
5
+
6
+ describe('NumberTextField', () => {
7
+ describe('render', () => {
8
+ let value = 1;
9
+ let onChange, component, textField, onBlur;
10
+ let min = 1;
11
+ let max = 10;
12
+
13
+ describe('TextField', () => {
14
+ beforeEach(() => {
15
+ onChange = jest.fn();
16
+ onBlur = jest.fn();
17
+ component = shallow(
18
+ <NumberTextField value={value} min={min} max={max} classes={{}} onChange={onChange} onBlur={onBlur} />,
19
+ );
20
+ textField = component.find(TextField);
21
+ });
22
+
23
+ it('should render mui TextField', () => {
24
+ expect(textField.length).toEqual(1);
25
+ });
26
+
27
+ describe('props', () => {
28
+ let props;
29
+
30
+ beforeEach(() => {
31
+ props = textField.props();
32
+ });
33
+
34
+ it('should contain value', () => {
35
+ expect(props.value).toEqual(value);
36
+ });
37
+ });
38
+
39
+ describe('logic', () => {
40
+ describe('clamp', () => {
41
+ const assertClamp = (input, expected) => {
42
+ it(`${input} => ${expected}`, () => {
43
+ const result = component.instance().clamp(input);
44
+ expect(result).toEqual(expected);
45
+ });
46
+ };
47
+
48
+ assertClamp('foo', 1);
49
+ assertClamp(1, 1);
50
+ assertClamp(2, 2);
51
+ assertClamp(0, 1);
52
+ assertClamp(-1, 1);
53
+ assertClamp(10, 10);
54
+ assertClamp(11, 10);
55
+ });
56
+
57
+ describe('onBlur', () => {
58
+ const event = (value) => ({
59
+ target: { value },
60
+ });
61
+
62
+ describe('called with valid string representation of int', () => {
63
+ it('should be called with parsed int', () => {
64
+ const e = event('1');
65
+
66
+ textField.simulate('change', e);
67
+
68
+ expect(component.state('value')).toEqual('1');
69
+
70
+ e.target.value = '100';
71
+
72
+ textField.simulate('change', e);
73
+
74
+ expect(component.state('value')).toEqual('100');
75
+
76
+ const beforeMax = (max - 1).toString();
77
+ e.target.value = beforeMax;
78
+
79
+ textField.simulate('blur', e);
80
+
81
+ expect(component.state('value')).toEqual(beforeMax);
82
+ });
83
+ });
84
+
85
+ describe('called with invalid string representation of int', () => {
86
+ it('should be called with min value', () => {
87
+ const e = event('aa');
88
+
89
+ textField.simulate('change', e);
90
+
91
+ expect(component.state('value')).toEqual('aa');
92
+
93
+ textField.simulate('blur', e);
94
+
95
+ expect(component.state('value')).toEqual(min.toString());
96
+ });
97
+ });
98
+
99
+ describe('called with empty string', () => {
100
+ it('should be called with min value', () => {
101
+ const e = event('');
102
+
103
+ textField.simulate('change', e);
104
+
105
+ expect(component.state('value')).toEqual('');
106
+
107
+ textField.simulate('blur', e);
108
+
109
+ expect(component.state('value')).toEqual(min.toString());
110
+ });
111
+ });
112
+
113
+ describe('string int less than min', () => {
114
+ const value = (min - 1).toString();
115
+
116
+ it('should be called with value of min', () => {
117
+ const e = event(value);
118
+
119
+ textField.simulate('change', e);
120
+
121
+ expect(component.state('value')).toEqual(value);
122
+
123
+ textField.simulate('blur', e);
124
+
125
+ expect(component.state('value')).toEqual(min.toString());
126
+ });
127
+ });
128
+
129
+ describe('string int exceeds max', () => {
130
+ const value = (max + 1).toString();
131
+
132
+ it('should be called with value of max', () => {
133
+ const e = event(value);
134
+
135
+ textField.simulate('change', e);
136
+
137
+ expect(component.state('value')).toEqual(value);
138
+
139
+ textField.simulate('blur', e);
140
+
141
+ expect(component.state('value')).toEqual(max.toString());
142
+ });
143
+ });
144
+ });
145
+ });
146
+ });
147
+ });
148
+ });
@@ -0,0 +1,204 @@
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import { Panel } from '../settings/panel';
4
+ import { toggle, radio, dropdown, numberField, numberFields } from '../settings';
5
+
6
+ describe('Settings Panel', () => {
7
+ let w;
8
+ let onChange = jest.fn();
9
+ let configure = {
10
+ orientationLabel: 'Orientation',
11
+
12
+ settingsOrientation: true,
13
+ editChoiceLabel: false,
14
+ };
15
+ let model = {
16
+ choiceAreaLayout: 'vertical',
17
+ };
18
+
19
+ let groups = ({ configure }) => ({
20
+ 'Group 1': {
21
+ choiceAreaLayout: configure.settingsOrientation && {
22
+ type: 'radio',
23
+ label: configure.orientationLabel,
24
+ choices: [
25
+ { label: 'opt1', value: 'opt1' },
26
+ { label: 'opt2', value: 'opt2' },
27
+ ],
28
+ equationEditor: dropdown('Dropdown', ['geometry', 'advanced-algebra', 'statistics', 'miscellaneous']),
29
+ graph: numberFields('Graph Display Size', {
30
+ domain: {
31
+ label: 'Domain',
32
+ suffix: 'px',
33
+ },
34
+ range: {
35
+ label: 'Range',
36
+ suffix: 'px',
37
+ },
38
+ width: {
39
+ label: 'Width',
40
+ suffix: 'px',
41
+ min: 50,
42
+ max: 250,
43
+ },
44
+ }),
45
+ },
46
+ editChoiceLabel: { type: 'toggle', label: 'Edit choice label', isConfigProperty: true },
47
+ },
48
+ });
49
+
50
+ const wrapper = (extras) => {
51
+ return shallow(
52
+ <Panel
53
+ model={model}
54
+ configuration={configure}
55
+ onChangeModel={onChange}
56
+ onChangeConfiguration={onChange}
57
+ groups={groups({ configure })}
58
+ {...extras}
59
+ />,
60
+ );
61
+ };
62
+
63
+ describe('snapshot', () => {
64
+ it('renders', () => {
65
+ w = wrapper();
66
+
67
+ expect(w).toMatchSnapshot();
68
+ });
69
+
70
+ it('does not render radio buttons', () => {
71
+ w = wrapper({
72
+ groups: groups({
73
+ configure: {
74
+ ...configure,
75
+ settingsOrientation: false,
76
+ },
77
+ }),
78
+ });
79
+
80
+ expect(w).toMatchSnapshot();
81
+ });
82
+ });
83
+
84
+ describe('logic', () => {
85
+ describe('onChange gets called', () => {
86
+ it('updates model props', () => {
87
+ w.instance().change('test', false);
88
+
89
+ expect(onChange).toBeCalledWith(
90
+ {
91
+ ...model,
92
+ test: false,
93
+ },
94
+ 'test',
95
+ );
96
+ });
97
+
98
+ it('updates configuration props', () => {
99
+ w.instance().change('test.test', true, true);
100
+
101
+ expect(onChange).toBeCalledWith(
102
+ {
103
+ ...configure,
104
+ test: {
105
+ test: true,
106
+ },
107
+ },
108
+ 'test.test',
109
+ );
110
+ });
111
+ });
112
+ });
113
+ });
114
+
115
+ describe('toggle', () => {
116
+ it('returns a toggle type object', () => {
117
+ const setting = toggle('Label');
118
+
119
+ expect(setting).toEqual({
120
+ label: 'Label',
121
+ type: 'toggle',
122
+ isConfigProperty: false,
123
+ disabled: false,
124
+ });
125
+ });
126
+ });
127
+
128
+ describe('radio', () => {
129
+ it('returns a radio type object', () => {
130
+ const setting = radio('Radio', ['one', 'two']);
131
+
132
+ expect(setting).toEqual({
133
+ label: 'Radio',
134
+ type: 'radio',
135
+ isConfigProperty: false,
136
+ choices: [
137
+ {
138
+ label: 'one',
139
+ value: 'one',
140
+ },
141
+ {
142
+ label: 'two',
143
+ value: 'two',
144
+ },
145
+ ],
146
+ });
147
+ });
148
+ });
149
+
150
+ describe('dropdown', () => {
151
+ it('returns a dropdown type object', () => {
152
+ const setting = dropdown('Dropdown', ['one', 'two']);
153
+
154
+ expect(setting).toEqual({
155
+ label: 'Dropdown',
156
+ type: 'dropdown',
157
+ isConfigProperty: false,
158
+ choices: ['one', 'two'],
159
+ });
160
+ });
161
+ });
162
+
163
+ describe('numberField', () => {
164
+ it('returns a numberField type object', () => {
165
+ const setting = numberField('Number Field', { max: 12 }, true);
166
+
167
+ expect(setting).toEqual({
168
+ label: 'Number Field',
169
+ type: 'numberField',
170
+ isConfigProperty: true,
171
+ max: 12,
172
+ });
173
+ });
174
+ });
175
+
176
+ describe('numberFields', () => {
177
+ it('returns a numberFields type object', () => {
178
+ const setting = numberFields('Number Fields', {
179
+ one: {
180
+ label: 'One',
181
+ },
182
+ two: {
183
+ label: 'Two',
184
+ },
185
+ });
186
+
187
+ expect(setting).toEqual({
188
+ label: 'Number Fields',
189
+ type: 'numberFields',
190
+ fields: {
191
+ one: {
192
+ type: 'numberField',
193
+ label: 'One',
194
+ isConfigProperty: false,
195
+ },
196
+ two: {
197
+ type: 'numberField',
198
+ label: 'Two',
199
+ isConfigProperty: false,
200
+ },
201
+ },
202
+ });
203
+ });
204
+ });
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import { NChoice } from '../two-choice';
4
+
5
+ describe('NChoice', () => {
6
+ it('renders n choice radio buttons vertical correctly', () => {
7
+ const tree = renderer
8
+ .create(
9
+ <NChoice
10
+ direction="vertical"
11
+ header="n-choice-vertical"
12
+ value={'left'}
13
+ onChange={jest.fn()}
14
+ opts={[
15
+ { label: 'left', value: 'left' },
16
+ { label: 'center', value: 'center' },
17
+ { label: 'right', value: 'right' },
18
+ ]}
19
+ />,
20
+ )
21
+ .toJSON();
22
+ expect(tree).toMatchSnapshot();
23
+ });
24
+ });
@@ -1,36 +1,56 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@material-ui/core';
4
+ import { withStyles } from '@material-ui/core/styles';
4
5
 
5
- const AlertDialog = ({ text, title, onClose, onConfirm, open }) => (
6
+ const AlertDialog = ({ text, title, onClose, onConfirm, open, onCloseText, onConfirmText, classes }) => (
6
7
  <Dialog open={open} onClose={onClose}>
7
- {title && <DialogTitle>{title}</DialogTitle>}
8
+ {title && <DialogTitle className={classes.heading}>{title}</DialogTitle>}
8
9
  {text && (
9
10
  <DialogContent>
10
- <DialogContentText>{text}</DialogContentText>
11
+ <DialogContentText className={classes.subheading}>{text}</DialogContentText>
11
12
  </DialogContent>
12
13
  )}
13
14
  <DialogActions>
14
15
  {onClose && (
15
16
  <Button onClick={onClose} color="primary">
16
- CANCEL
17
+ {onCloseText}
17
18
  </Button>
18
19
  )}
19
20
  {onConfirm && (
20
21
  <Button autoFocus onClick={onConfirm} color="primary">
21
- OK
22
+ {onConfirmText}
22
23
  </Button>
23
24
  )}
24
25
  </DialogActions>
25
26
  </Dialog>
26
27
  );
27
28
 
29
+ AlertDialog.defaultProps = {
30
+ onCloseText: 'CANCEL',
31
+ onConfirmText: 'OK',
32
+ };
33
+
28
34
  AlertDialog.propTypes = {
29
- text: PropTypes.string,
35
+ text: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
30
36
  title: PropTypes.string,
31
37
  onClose: PropTypes.func,
32
38
  onConfirm: PropTypes.func,
33
39
  open: PropTypes.bool,
40
+ onConfirmText: PropTypes.string,
41
+ onCloseText: PropTypes.string,
42
+ classes: PropTypes.object,
34
43
  };
35
44
 
36
- export default AlertDialog;
45
+ const styles = () => ({
46
+ heading: {
47
+ '& h2': {
48
+ fontSize: 'max(1.25rem, 18px)',
49
+ },
50
+ },
51
+ subheading: {
52
+ fontSize: 'max(1rem, 14px)',
53
+ },
54
+ });
55
+
56
+ export default withStyles(styles)(AlertDialog);
package/src/checkbox.jsx CHANGED
@@ -5,6 +5,7 @@ import React from 'react';
5
5
  import { withStyles } from '@material-ui/core/styles';
6
6
  import classNames from 'classnames';
7
7
  import grey from '@material-ui/core/colors/grey';
8
+ import { color } from '@pie-lib/render-ui';
8
9
 
9
10
  const Checkbox = ({ mini, checked, onChange, value, label, classes, error }) => (
10
11
  <FormControlLabel
@@ -17,7 +18,10 @@ const Checkbox = ({ mini, checked, onChange, value, label, classes, error }) =>
17
18
  checked={checked}
18
19
  onChange={onChange}
19
20
  value={value}
20
- className={classNames({ [classes.miniCheckbox]: mini, [classes.error]: error })}
21
+ className={classNames(classes.customColor, {
22
+ [classes.miniCheckbox]: mini,
23
+ [classes.error]: error,
24
+ })}
21
25
  />
22
26
  }
23
27
  label={label}
@@ -63,4 +67,7 @@ export default withStyles((theme) => ({
63
67
  error: {
64
68
  color: theme.palette.error.main,
65
69
  },
70
+ customColor: {
71
+ color: `${color.tertiary()} !important`,
72
+ },
66
73
  }))(Checkbox);
@@ -0,0 +1,51 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`feedback-menu renders correctly 1`] = `
4
+ <div>
5
+ <div
6
+ onClick={[Function]}
7
+ >
8
+ <button
9
+ aria-label="Feedback disabled"
10
+ className="MuiButtonBase-root-7 MuiIconButton-root-1"
11
+ disabled={false}
12
+ onBlur={[Function]}
13
+ onContextMenu={[Function]}
14
+ onFocus={[Function]}
15
+ onKeyDown={[Function]}
16
+ onKeyUp={[Function]}
17
+ onMouseDown={[Function]}
18
+ onMouseLeave={[Function]}
19
+ onMouseUp={[Function]}
20
+ onTouchEnd={[Function]}
21
+ onTouchMove={[Function]}
22
+ onTouchStart={[Function]}
23
+ tabIndex="0"
24
+ type="button"
25
+ >
26
+ <span
27
+ className="MuiIconButton-label-6"
28
+ >
29
+ <svg
30
+ aria-hidden="true"
31
+ className="MuiSvgIcon-root-10 MuiSvgIcon-colorDisabled-15"
32
+ focusable="false"
33
+ role="presentation"
34
+ viewBox="0 0 24 24"
35
+ >
36
+ <path
37
+ d="M0 0h24v24H0z"
38
+ fill="none"
39
+ />
40
+ <path
41
+ d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 12h-2v-2h2v2zm0-4h-2V6h2v4z"
42
+ />
43
+ </svg>
44
+ </span>
45
+ <span
46
+ className="MuiTouchRipple-root-23"
47
+ />
48
+ </button>
49
+ </div>
50
+ </div>
51
+ `;