-
Notifications
You must be signed in to change notification settings - Fork 79
/
InsertEmbedModal-test.js
135 lines (110 loc) · 3.76 KB
/
InsertEmbedModal-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
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
127
128
129
130
131
132
133
134
135
/* global jest, jasmine, describe, it, expect, beforeEach */
// FormBuilderLoader mock was not mocking properly
// manually override with a stateless null component
jest.mock('components/FormBuilderModal/FormBuilderModal', () => () => null);
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import { Component as InsertEmbedModal } from '../InsertEmbedModal';
describe('InsertEmbedModal', () => {
let props = {};
beforeEach(() => {
props = {
onInsert: jest.fn(),
onCreate: jest.fn(),
onClosed: jest.fn(),
schemaUrl: 'test.com/schema',
actions: {
schema: {
setSchemaStateOverrides: jest.fn(),
},
},
};
});
describe('clearOverrides()', () => {
it('should call the action to state override and provide null', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
component.clearOverrides();
expect(props.actions.schema.setSchemaStateOverrides).toBeCalledWith('test.com/schema', null);
});
});
describe('setOverrides()', () => {
it('should clear override if url has changed', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const nextProps = {
schemaUrl: 'test2.com/schema',
fileAttributes: {
ID: 5,
Name: 'Bob',
},
};
component.clearOverrides = jest.fn();
component.setOverrides(nextProps);
expect(component.clearOverrides).toBeCalled();
});
it('should not call the state override action if no url is provided', () => {
props.schemaUrl = '';
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const nextProps = {
schemaUrl: '',
};
component.setOverrides(nextProps);
expect(props.actions.schema.setSchemaStateOverrides).not.toBeCalled();
});
it('should set the fields in the proper structure and exclude ID', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const nextProps = {
schemaUrl: 'test.com/schema',
fileAttributes: {
ID: 5,
Name: 'Bob',
},
};
component.setOverrides(nextProps);
expect(props.actions.schema.setSchemaStateOverrides).toBeCalledWith('test.com/schema', {
fields: [
{ name: 'Name', value: 'Bob' },
],
});
});
});
describe('handleSubmit()', () => {
it('should call create when addmedia is actioned', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const data = { Name: 'Bob' };
const mockSubmit = jest.fn();
component.handleSubmit(data, 'action_addmedia', mockSubmit);
expect(props.onCreate).toBeCalledWith(data);
expect(mockSubmit).not.toBeCalled();
});
it('should call insert when insertmedia is actioned', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const data = { Name: 'Bob' };
const mockSubmit = jest.fn();
component.handleSubmit(data, 'action_insertmedia', mockSubmit);
expect(props.onInsert).toBeCalledWith(data);
expect(mockSubmit).not.toBeCalled();
});
it('should call hide when cancel is actioned', () => {
const component = ReactTestUtils.renderIntoDocument(
<InsertEmbedModal {...props} />
);
const data = { Name: 'Bob' };
const mockSubmit = jest.fn();
component.handleSubmit(data, 'action_cancel', mockSubmit);
expect(props.onClosed).toBeCalled();
expect(mockSubmit).not.toBeCalled();
});
});
});