-
Notifications
You must be signed in to change notification settings - Fork 27
/
select.test.js
57 lines (48 loc) · 1.97 KB
/
select.test.js
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
import * as lib from './select';
import * as components from '../core-data/components';
import * as els from '../utils/component-elements';
import { refProp } from '../utils/references';
describe('select', () => {
describe('getParentField', () => {
const fn = lib.getParentField;
let sandbox;
beforeEach(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(components);
sandbox.stub(els);
});
afterEach(() => {
sandbox.restore();
});
it('returns empty obj if path not found in data', () => {
components.getData.returns({});
components.getSchema.returns({});
expect(fn('foo', 'bar')).to.eql({});
});
it('returns empty obj if data props are not arrays or objects', () => {
// todo: this might mean that this won't grab child components of page areas,
// so test this before enabling editing of those page areas
components.getData.returns({ fooProp: 'foo' });
components.getSchema.returns({});
expect(fn('foo', 'bar')).to.eql({});
});
it('warns if path not found in schema', () => {
components.getData.returns({ fooProp: { [refProp]: '/components/foo' } });
components.getSchema.returns({});
fn('/components/foo', '/components/bar');
expect(loggerStub.warn.called).to.equal(true);
});
it('returns path for component in list', () => {
components.getData.returns({ fooProp: [{ [refProp]: 'foo' }] });
components.getSchema.returns({ fooProp: { _componentList: true } });
els.getFieldEl.returns(null);
expect(fn('foo', 'bar')).to.eql({ path: 'fooProp', type: 'list', isEditable: false });
});
it('returns path for component in prop', () => {
components.getData.returns({ fooProp: { [refProp]: 'foo' } });
components.getSchema.returns({ fooProp: { _component: true } });
els.getFieldEl.returns(null);
expect(fn('foo', 'bar')).to.eql({ path: 'fooProp', type: 'prop', isEditable: false });
});
});
});