@capillarytech/creatives-library 9.0.6-beta.0.2 → 9.0.8
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.
package/package.json
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { IntlProvider } from 'react-intl';
|
|
4
2
|
import { mountWithIntl, shallowWithIntl } from '../../../../helpers/intl-enzym-test-helpers';
|
|
5
3
|
import MessageSection from './MessageSection';
|
|
6
4
|
import CapInput from '@capillarytech/cap-ui-library/CapInput';
|
|
@@ -232,31 +230,10 @@ describe('MessageSection', () => {
|
|
|
232
230
|
});
|
|
233
231
|
|
|
234
232
|
describe('TextArea Ref Handling', () => {
|
|
235
|
-
it('should
|
|
233
|
+
it('should call handleMessageTextAreaRef with setInputRef', () => {
|
|
236
234
|
const wrapper = mountWithIntl(<MessageSection {...defaultProps} />);
|
|
237
235
|
const textArea = wrapper.find(CapInput.TextArea);
|
|
238
|
-
expect(textArea.prop('setInputRef')).
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('should resolve the DOM textarea by id and feed it to handleMessageTextAreaRef on mount', () => {
|
|
242
|
-
// attachTo a real DOM node so document.getElementById can find the
|
|
243
|
-
// antd-rendered <textarea> (enzyme mount is detached from document otherwise).
|
|
244
|
-
const container = document.createElement('div');
|
|
245
|
-
document.body.appendChild(container);
|
|
246
|
-
const wrapper = mount(
|
|
247
|
-
<IntlProvider locale="en">
|
|
248
|
-
<MessageSection {...defaultProps} />
|
|
249
|
-
</IntlProvider>,
|
|
250
|
-
{ attachTo: container }
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
const textarea = document.getElementById('webpush-message-input');
|
|
254
|
-
expect(textarea).not.toBeNull();
|
|
255
|
-
expect(textarea.tagName).toBe('TEXTAREA');
|
|
256
|
-
expect(mockHandleMessageTextAreaRef).toHaveBeenCalledWith(textarea);
|
|
257
|
-
|
|
258
|
-
wrapper.unmount();
|
|
259
|
-
container.remove();
|
|
236
|
+
expect(textArea.prop('setInputRef')).toBe(mockHandleMessageTextAreaRef);
|
|
260
237
|
});
|
|
261
238
|
|
|
262
239
|
it('should pass messageTextAreaRef to CapEmojiPicker.Wrapper', () => {
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { configure, mount } from 'enzyme';
|
|
3
|
-
import Adapter from '@cfaester/enzyme-adapter-react-18';
|
|
4
|
-
import { IntlProvider } from 'react-intl';
|
|
5
|
-
import { act } from 'react-dom/test-utils';
|
|
6
|
-
|
|
7
|
-
// TagList is a redux-auth-wrapper-connected container that needs full app routing
|
|
8
|
-
// state to mount; CallTaskPreview is irrelevant to insertAtCursor. Stub both so we
|
|
9
|
-
// can mount the real NewCallTask and exercise its real insertAtCursor method.
|
|
10
|
-
jest.mock('../../../v2Containers/TagList', () => {
|
|
11
|
-
const Stub = () => null;
|
|
12
|
-
return { __esModule: true, default: Stub, TagList: Stub };
|
|
13
|
-
});
|
|
14
|
-
jest.mock('../../CallTaskPreview', () => {
|
|
15
|
-
const Stub = () => null;
|
|
16
|
-
return { __esModule: true, default: Stub };
|
|
17
|
-
});
|
|
18
|
-
// hasStore2DoorFeature() reads app/org config that isn't present in jsdom.
|
|
19
|
-
jest.mock('../../../utils/common', () => ({
|
|
20
|
-
...jest.requireActual('../../../utils/common'),
|
|
21
|
-
hasStore2DoorFeature: () => false,
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line import/first
|
|
25
|
-
import NewCallTask from '../index';
|
|
26
|
-
// eslint-disable-next-line import/first
|
|
27
|
-
import mockData from './mockData';
|
|
28
|
-
|
|
29
|
-
configure({ adapter: new Adapter() });
|
|
30
|
-
|
|
31
|
-
let container;
|
|
32
|
-
let wrapper;
|
|
33
|
-
|
|
34
|
-
afterEach(() => {
|
|
35
|
-
if (wrapper) wrapper.unmount();
|
|
36
|
-
if (container) container.remove();
|
|
37
|
-
wrapper = undefined;
|
|
38
|
-
container = undefined;
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// attachTo a real node in document.body so document.getElementById can find the
|
|
42
|
-
// antd-rendered <textarea> (enzyme `mount` is detached from `document` otherwise).
|
|
43
|
-
const mountNewCallTask = (extraProps = {}) => {
|
|
44
|
-
container = document.createElement('div');
|
|
45
|
-
document.body.appendChild(container);
|
|
46
|
-
wrapper = mount(
|
|
47
|
-
<IntlProvider locale="en">
|
|
48
|
-
<NewCallTask {...mockData} onCallTaskSubmit={jest.fn()} {...extraProps} />
|
|
49
|
-
</IntlProvider>,
|
|
50
|
-
{ attachTo: container },
|
|
51
|
-
);
|
|
52
|
-
return wrapper;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Regression coverage for the antd v3 -> v6 (cap-ui-library v6) migration: the lib
|
|
56
|
-
// dropped the `setInputRef` callback, so selecting a personalisation tag used to
|
|
57
|
-
// crash with "Cannot read properties of undefined (reading 'focus')". The fix
|
|
58
|
-
// resolves the DOM <textarea> via document.getElementById instead.
|
|
59
|
-
describe('NewCallTask insertAtCursor (antd v6 setInputRef removal)', () => {
|
|
60
|
-
it('forwards the id to a real DOM <textarea>', () => {
|
|
61
|
-
mountNewCallTask();
|
|
62
|
-
const textarea = document.getElementById('new-call-task-message-body');
|
|
63
|
-
expect(textarea).not.toBeNull();
|
|
64
|
-
expect(textarea.tagName).toBe('TEXTAREA');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('inserts a personalisation tag at the caret without throwing', () => {
|
|
68
|
-
const wrapper = mountNewCallTask();
|
|
69
|
-
const textarea = document.getElementById('new-call-task-message-body');
|
|
70
|
-
|
|
71
|
-
// user typed "Hello world" and put the caret right after "Hello "
|
|
72
|
-
textarea.value = 'Hello world';
|
|
73
|
-
textarea.setSelectionRange(6, 6);
|
|
74
|
-
|
|
75
|
-
const instance = wrapper.find('NewCallTask').instance();
|
|
76
|
-
expect(() => {
|
|
77
|
-
act(() => {
|
|
78
|
-
instance.onTagSelect('firstName');
|
|
79
|
-
});
|
|
80
|
-
}).not.toThrow();
|
|
81
|
-
|
|
82
|
-
// tag spliced in at the caret, not appended blindly
|
|
83
|
-
expect(instance.state.messageBody).toBe('Hello {{firstName}}world');
|
|
84
|
-
});
|
|
85
|
-
});
|