-
-
Notifications
You must be signed in to change notification settings - Fork 356
/
metafields.spec.js
70 lines (58 loc) · 1.96 KB
/
metafields.spec.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
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import { mount } from 'enzyme';
import { MetaFields } from '../MetaFields';
import MetaField from '../../components/metadata/MetaField';
import { content } from './fixtures';
const defaultProps = {
fields: content,
metadata: content,
key_prefix: ''
};
function setup(props=defaultProps) {
const actions = {
storeContentFields: jest.fn(),
addField: jest.fn(),
removeField: jest.fn(),
updateFieldKey: jest.fn(),
updateFieldValue: jest.fn(),
moveArrayItem: jest.fn(),
convertField: jest.fn()
};
const component = mount(
<MetaFields {...props} {...actions} />
);
return {
component,
addFieldButton: component.find('.meta-new a'),
addDataFieldButton: component.find('.data-new a'),
metafields: component.find(MetaField),
actions: actions
};
}
describe('Containers::MetaFields', () => {
it('should render MetaFields correctly', () => {
let { component, metafields, addFieldButton, addDataFieldButton } = setup();
expect(component.find('div').first().hasClass('metafields')).toEqual(true);
expect(addFieldButton.node).toBeTruthy();
expect(addDataFieldButton.node).not.toBeTruthy();
const updatedSetup = setup(Object.assign({}, defaultProps, {
dataview: true
}));
expect(
updatedSetup.component.find('div').first().hasClass('datafields')
).toEqual(true);
expect(updatedSetup.addFieldButton.node).not.toBeTruthy();
expect(updatedSetup.addDataFieldButton.node).toBeTruthy();
expect(component.prop('key_prefix')).toBe('');
expect(component.prop('metadata')).toEqual(content);
});
it('should call storeContentFields before mount', () => {
const { actions } = setup();
expect(actions.storeContentFields).toHaveBeenCalled();
});
it('should call addField when the button is clicked', () => {
const { actions, addFieldButton } = setup();
addFieldButton.simulate('click');
expect(actions.addField).toHaveBeenCalled();
});
});