@capillarytech/creatives-library 9.1.8-alpha.sprint-cap-214249.38 → 9.2.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.
- package/constants/unified.js +4 -0
- package/index.js +13 -0
- package/package.json +1 -1
- package/services/getSchema.js +4 -1
- package/services/tests/getSchema.test.js +2 -2
- package/translations/en.json +1 -0
- package/translations/ja-JP.json +1 -0
- package/translations/zh.json +1 -0
- package/utils/common.js +6 -0
- package/utils/createMobilePushPayload.js +33 -47
- package/utils/tagValidations.js +35 -4
- package/utils/templateVarUtils.js +49 -0
- package/utils/tests/createMobilePushPayload.test.js +8 -102
- package/utils/tests/tagValidations.test.js +48 -0
- package/utils/tests/templateVarUtils.test.js +89 -0
- package/v2Components/CapMpushCTA/index.js +9 -10
- package/v2Components/CapMpushCTA/index.scss +3 -29
- package/v2Components/CapTagList/TagFallbackPanel.js +124 -0
- package/v2Components/CapTagList/constants.js +5 -0
- package/v2Components/CapTagList/index.js +46 -7
- package/v2Components/CapTagList/messages.js +44 -0
- package/v2Components/CapTagList/style.scss +113 -1
- package/v2Components/CapTagList/tests/TagFallback.test.js +222 -0
- package/v2Components/CapTagList/utils.js +17 -0
- package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +13 -26
- package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +1 -13
- package/v2Components/CommonTestAndPreview/constants.js +3 -2
- package/v2Components/CommonTestAndPreview/index.js +62 -62
- package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +5 -79
- package/v2Components/CommonTestAndPreview/tests/index.test.js +0 -86
- package/v2Components/CommonTestAndPreview/tests/utils.test.js +102 -0
- package/v2Components/CommonTestAndPreview/utils.js +42 -3
- package/v2Components/FormBuilder/Classic.js +24 -14
- package/v2Components/FormBuilder/Functional/channels/mobilepush/config.js +1 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/getEditorErrorDescriptor.js +1 -1
- package/v2Components/FormBuilder/Functional/channels/mobilepush/tests/validate.test.js +57 -0
- package/v2Components/FormBuilder/Functional/channels/mobilepush/validate.js +4 -4
- package/v2Components/FormBuilder/Functional/channels/sms/getEditorErrorDescriptor.js +3 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/getEditorErrorDescriptor.test.js +5 -0
- package/v2Components/FormBuilder/Functional/channels/sms/tests/validate.test.js +6 -0
- package/v2Components/FormBuilder/Functional/channels/sms/validate.js +3 -1
- package/v2Components/FormBuilder/Functional/renderers/mpushRenderers.js +3 -0
- package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +135 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +320 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +148 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +152 -0
- package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
- package/v2Components/FormBuilder/Functional/tests/mpushRenderers.test.js +22 -0
- package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
- package/v2Components/TemplatePreview/_templatePreview.scss +2 -12
- package/v2Components/TemplatePreview/index.js +17 -30
- package/v2Components/TemplatePreview/tests/index.test.js +0 -61
- package/v2Containers/Cap/index.js +3 -0
- package/v2Containers/Cap/messages.js +4 -0
- package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +1 -0
- package/v2Containers/CreativesContainer/SlideBoxContent.js +151 -70
- package/v2Containers/CreativesContainer/index.js +6 -3
- package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +0 -29
- package/v2Containers/InApp/index.js +4 -1
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +3 -0
- package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +2 -0
- package/v2Containers/Line/Container/Text/index.js +3 -1
- package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +16 -0
- package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +18 -0
- package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +70 -0
- package/v2Containers/MobilePush/Create/actions.js +52 -0
- package/v2Containers/MobilePush/Create/constants.js +26 -0
- package/v2Containers/MobilePush/Create/index.js +2149 -0
- package/v2Containers/MobilePush/Create/messages.js +349 -0
- package/v2Containers/MobilePush/Create/reducer.js +72 -0
- package/v2Containers/MobilePush/Create/sagas.js +79 -0
- package/v2Containers/MobilePush/Create/selectors.js +29 -0
- package/v2Containers/MobilePush/Create/test/contentValidity.test.js +154 -0
- package/v2Containers/MobilePush/Create/test/saga.test.js +19 -0
- package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +80 -0
- package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +65 -0
- package/v2Containers/MobilePush/Edit/actions.js +94 -0
- package/v2Containers/MobilePush/Edit/constants.js +37 -0
- package/v2Containers/MobilePush/Edit/index.js +2407 -0
- package/v2Containers/MobilePush/Edit/messages.js +341 -0
- package/v2Containers/MobilePush/Edit/reducer.js +113 -0
- package/v2Containers/MobilePush/Edit/sagas.js +113 -0
- package/v2Containers/MobilePush/Edit/selectors.js +33 -0
- package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +149 -0
- package/v2Containers/MobilePush/Edit/test/saga.test.js +255 -0
- package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +60 -0
- package/v2Containers/MobilePush/commonMethods.js +333 -0
- package/v2Containers/MobilePush/eventsMap.js +130 -0
- package/v2Containers/MobilePush/tests/commonMethods.test.js +401 -0
- package/v2Containers/MobilePushNew/components/CtaButtons.js +47 -52
- package/v2Containers/MobilePushNew/components/MediaUploaders.js +192 -207
- package/v2Containers/MobilePushNew/components/PlatformContentFields.js +121 -116
- package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +208 -30
- package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +72 -316
- package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +16 -45
- package/v2Containers/MobilePushNew/constants.js +0 -5
- package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +1 -63
- package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +0 -52
- package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +1 -38
- package/v2Containers/MobilePushNew/hooks/useUpload.js +39 -29
- package/v2Containers/MobilePushNew/index.js +192 -454
- package/v2Containers/MobilePushNew/index.scss +4 -188
- package/v2Containers/MobilePushNew/messages.js +6 -86
- package/v2Containers/MobilePushNew/tests/index.test.js +1 -450
- package/v2Containers/MobilePushNew/tests/utils.test.js +0 -25
- package/v2Containers/MobilePushNew/utils.js +0 -8
- package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +22 -0
- package/v2Containers/MobilepushWrapper/index.js +178 -0
- package/v2Containers/MobilepushWrapper/messages.js +29 -0
- package/v2Containers/Rcs/index.js +8 -1
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +59 -0
- package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +4 -0
- package/v2Containers/SmsTrai/Edit/index.js +17 -7
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +42 -0
- package/v2Containers/Templates/_templates.scss +2 -10
- package/v2Containers/Templates/index.js +90 -84
- package/v2Containers/Templates/tests/index.test.js +0 -68
- package/v2Containers/Viber/index.js +3 -1
- package/v2Containers/WebPush/Create/utils/validation.js +6 -0
- package/v2Containers/WebPush/Create/utils/validation.test.js +50 -0
- package/v2Containers/Whatsapp/index.js +9 -5
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
- package/v2Containers/Zalo/index.js +4 -1
- package/v2Components/CapMpushCTA/tests/index.test.js +0 -89
- /package/{v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js → v2Containers/MobilePush/initialSchema.js} +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import { cloneDeep } from 'lodash';
|
|
4
|
+
import { Edit } from '../index';
|
|
5
|
+
import { response as mpushSchemaResponse } from '../../initialSchema';
|
|
6
|
+
|
|
7
|
+
// Shallow-render the plain class (bypassing the withCreatives/Redux/saga HOC) so this test
|
|
8
|
+
// only exercises the componentDidUpdate → onContentValidityChange wiring in isolation.
|
|
9
|
+
// Mirrors app/v2Containers/Sms/Edit/tests/index.test.js.
|
|
10
|
+
|
|
11
|
+
const baseProps = () => ({
|
|
12
|
+
actions: {
|
|
13
|
+
getWeCrmAccounts: jest.fn(),
|
|
14
|
+
getTemplateDetails: jest.fn(),
|
|
15
|
+
setTemplateDetails: jest.fn(),
|
|
16
|
+
},
|
|
17
|
+
globalActions: {
|
|
18
|
+
fetchSchemaForEntity: jest.fn(),
|
|
19
|
+
},
|
|
20
|
+
Templates: { selectedWeChatAccount: { id: 'acc-1' } },
|
|
21
|
+
Edit: {},
|
|
22
|
+
Create: {},
|
|
23
|
+
params: {},
|
|
24
|
+
location: { query: { type: 'library', module: 'default' } },
|
|
25
|
+
router: { push: jest.fn() },
|
|
26
|
+
metaEntities: {},
|
|
27
|
+
templateData: {},
|
|
28
|
+
intl: { formatMessage: (m) => (m && (m.defaultMessage || m.id)) || '' },
|
|
29
|
+
isFullMode: false,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('MobilePush/Edit — onContentValidityChange reporting', () => {
|
|
33
|
+
it('reports isContentEmpty: true on mount when both Android title and message are empty', () => {
|
|
34
|
+
const onContentValidityChange = jest.fn();
|
|
35
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
36
|
+
wrapper.setState({
|
|
37
|
+
formData: { 0: { 'message-title': '', 'message-editor': '' } },
|
|
38
|
+
tabCount: 1,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(onContentValidityChange).toHaveBeenCalledWith(
|
|
42
|
+
expect.objectContaining({ isContentEmpty: true }),
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('reports isContentEmpty: false once the Android message has content', () => {
|
|
47
|
+
const onContentValidityChange = jest.fn();
|
|
48
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
49
|
+
wrapper.setState({
|
|
50
|
+
formData: { 0: { 'message-title': '', 'message-editor': '' } },
|
|
51
|
+
tabCount: 1,
|
|
52
|
+
});
|
|
53
|
+
onContentValidityChange.mockClear();
|
|
54
|
+
|
|
55
|
+
wrapper.setState({
|
|
56
|
+
formData: { 0: { 'message-title': 'Hello', 'message-editor': 'World' } },
|
|
57
|
+
tabCount: 1,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(onContentValidityChange).toHaveBeenCalledWith(
|
|
61
|
+
expect.objectContaining({ isContentEmpty: false }),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('re-reports empty when an existing (edit-loaded) message is cleared out', () => {
|
|
66
|
+
const onContentValidityChange = jest.fn();
|
|
67
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
68
|
+
wrapper.setState({
|
|
69
|
+
formData: { 0: { 'message-title': 'Existing', 'message-editor': 'content' } },
|
|
70
|
+
tabCount: 1,
|
|
71
|
+
});
|
|
72
|
+
onContentValidityChange.mockClear();
|
|
73
|
+
|
|
74
|
+
wrapper.setState({
|
|
75
|
+
formData: { 0: { 'message-title': '', 'message-editor': '' } },
|
|
76
|
+
tabCount: 1,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(onContentValidityChange).toHaveBeenCalledWith(
|
|
80
|
+
expect.objectContaining({ isContentEmpty: true }),
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('treats content as present when the iOS tab (tabCount 2) is cleared but Android has content (single-device template allowed)', () => {
|
|
85
|
+
const onContentValidityChange = jest.fn();
|
|
86
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
87
|
+
wrapper.setState({
|
|
88
|
+
formData: {
|
|
89
|
+
0: { 'message-title': 'Android title', 'message-editor': 'Android body' },
|
|
90
|
+
1: { 'message-title2': '', 'message-editor2': '' },
|
|
91
|
+
},
|
|
92
|
+
tabCount: 2,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(onContentValidityChange).toHaveBeenCalledWith(
|
|
96
|
+
expect.objectContaining({ isContentEmpty: false }),
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('treats content as empty when both Android and iOS tabs (tabCount 2) are cleared', () => {
|
|
101
|
+
const onContentValidityChange = jest.fn();
|
|
102
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
103
|
+
wrapper.setState({
|
|
104
|
+
formData: {
|
|
105
|
+
0: { 'message-title': '', 'message-editor': '' },
|
|
106
|
+
1: { 'message-title2': '', 'message-editor2': '' },
|
|
107
|
+
},
|
|
108
|
+
tabCount: 2,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(onContentValidityChange).toHaveBeenCalledWith(
|
|
112
|
+
expect.objectContaining({ isContentEmpty: true }),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('does not throw and does not report when onContentValidityChange is not provided', () => {
|
|
117
|
+
const wrapper = shallow(<Edit {...baseProps()} />);
|
|
118
|
+
expect(() => {
|
|
119
|
+
wrapper.setState({ formData: { 0: { 'message-title': '', 'message-editor': '' } }, tabCount: 1 });
|
|
120
|
+
}).not.toThrow();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('does not dispatch again on a re-render that does not change validity (dedup guard)', () => {
|
|
124
|
+
const onContentValidityChange = jest.fn();
|
|
125
|
+
const wrapper = shallow(<Edit {...baseProps()} onContentValidityChange={onContentValidityChange} />);
|
|
126
|
+
wrapper.setState({ formData: { 0: { 'message-title': '', 'message-editor': '' } }, tabCount: 1 });
|
|
127
|
+
onContentValidityChange.mockClear();
|
|
128
|
+
|
|
129
|
+
// Unrelated state change — content emptiness is unchanged.
|
|
130
|
+
wrapper.setState({ currentTab: 1 });
|
|
131
|
+
|
|
132
|
+
expect(onContentValidityChange).not.toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('MobilePush/Edit — shared layout schema', () => {
|
|
137
|
+
it('keeps its own copy of the layout definition, leaving the store layout untouched', () => {
|
|
138
|
+
const storeDefinition = cloneDeep(mpushSchemaResponse.metaEntities[0].definition);
|
|
139
|
+
const wrapper = shallow(<Edit {...baseProps()} />);
|
|
140
|
+
wrapper.instance().handleEditSchemaOnPropsChange = jest.fn();
|
|
141
|
+
wrapper.setProps({ metaEntities: { layouts: [{ definition: storeDefinition }], tags: {} } });
|
|
142
|
+
|
|
143
|
+
const ownDefinition = wrapper.state('fullSchema');
|
|
144
|
+
expect(ownDefinition).not.toBe(storeDefinition);
|
|
145
|
+
expect(ownDefinition).toEqual(storeDefinition);
|
|
146
|
+
ownDefinition.textSchema.containers[0].panes[0].isSupported = false;
|
|
147
|
+
expect(storeDefinition.textSchema.containers[0].panes[0].isSupported).not.toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { expectSaga } from 'redux-saga-test-plan';
|
|
2
|
+
import { call, put } from 'redux-saga/effects';
|
|
3
|
+
import { throwError } from 'redux-saga-test-plan/providers';
|
|
4
|
+
import * as Api from '../../../../services/api';
|
|
5
|
+
import {v2MobilePushEditSagas} from '../sagas';
|
|
6
|
+
import * as types from '../constants';
|
|
7
|
+
import * as sagas from '../sagas';
|
|
8
|
+
|
|
9
|
+
describe('Mobile Push Template Sagas', () => {
|
|
10
|
+
describe('editTemplate Saga', () => {
|
|
11
|
+
const template = { message: "Retuen",id: 1, name: 'Updated Template' };
|
|
12
|
+
|
|
13
|
+
it.concurrent('handles successful template edit', () => {
|
|
14
|
+
const fakeResponse = {
|
|
15
|
+
response: template,
|
|
16
|
+
status: { code: 200 }
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return expectSaga(sagas.editTemplate, template)
|
|
20
|
+
.provide([
|
|
21
|
+
[call(Api.createMobilePushTemplate, template), fakeResponse]
|
|
22
|
+
])
|
|
23
|
+
.put({
|
|
24
|
+
type: types.EDIT_TEMPLATE_SUCCESS,
|
|
25
|
+
data: fakeResponse.response,
|
|
26
|
+
statusCode: 200,
|
|
27
|
+
errorMsg: undefined
|
|
28
|
+
})
|
|
29
|
+
.run();
|
|
30
|
+
});
|
|
31
|
+
it.concurrent('handles successful template edit', () => {
|
|
32
|
+
const fakeResponse = {
|
|
33
|
+
response: template,
|
|
34
|
+
status: { code: 500 }
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return expectSaga(sagas.editTemplate, template)
|
|
38
|
+
.provide([
|
|
39
|
+
[call(Api.createMobilePushTemplate, template), fakeResponse]
|
|
40
|
+
])
|
|
41
|
+
.put({
|
|
42
|
+
type: types.EDIT_TEMPLATE_SUCCESS,
|
|
43
|
+
data: fakeResponse.response,
|
|
44
|
+
statusCode: 500,
|
|
45
|
+
errorMsg: undefined
|
|
46
|
+
})
|
|
47
|
+
.run();
|
|
48
|
+
});
|
|
49
|
+
it.concurrent('handles failure in editing a template', () => {
|
|
50
|
+
const error = new Error('Edit failed');
|
|
51
|
+
|
|
52
|
+
return expectSaga(sagas.editTemplate, template)
|
|
53
|
+
.provide([
|
|
54
|
+
[call(Api.createMobilePushTemplate, template), throwError(error)]
|
|
55
|
+
])
|
|
56
|
+
.put({
|
|
57
|
+
type: types.EDIT_TEMPLATE_FAILURE,
|
|
58
|
+
error,
|
|
59
|
+
errorMsg: undefined
|
|
60
|
+
})
|
|
61
|
+
.run();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('getTemplateDetails Saga', () => {
|
|
66
|
+
const id = '123';
|
|
67
|
+
|
|
68
|
+
it.concurrent('handles fetching template details successfully', () => {
|
|
69
|
+
const fakeResponse = {
|
|
70
|
+
response: { id: 123, name: 'Detailed Template' }
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return expectSaga(sagas.getTemplateDetails, id)
|
|
74
|
+
.provide([
|
|
75
|
+
[call(Api.getTemplateDetails, id), fakeResponse]
|
|
76
|
+
])
|
|
77
|
+
.put({
|
|
78
|
+
type: types.GET_TEMPLATE_DETAILS_SUCCESS,
|
|
79
|
+
data: fakeResponse.response
|
|
80
|
+
})
|
|
81
|
+
.run();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it.concurrent('handles failure in fetching template details', () => {
|
|
85
|
+
const error = new Error('Fetch failed');
|
|
86
|
+
|
|
87
|
+
return expectSaga(sagas.getTemplateDetails, id)
|
|
88
|
+
.provide([
|
|
89
|
+
[call(Api.getTemplateDetails, id), throwError(error)]
|
|
90
|
+
])
|
|
91
|
+
.put({
|
|
92
|
+
type: types.GET_TEMPLATE_DETAILS_FAILURE,
|
|
93
|
+
error
|
|
94
|
+
})
|
|
95
|
+
.run();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('uploadAsset Saga', () => {
|
|
100
|
+
const file = new Blob();
|
|
101
|
+
const assetType = 'image';
|
|
102
|
+
const fileParams = { param1: 'value1' };
|
|
103
|
+
const mode = 'strict';
|
|
104
|
+
|
|
105
|
+
it.concurrent('handles successful asset upload', () => {
|
|
106
|
+
const fakeResponse = {
|
|
107
|
+
response: { asset: { id: 1, url: 'http://example.com/asset.jpg' } },
|
|
108
|
+
status: { code: 200 }
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return expectSaga(sagas.uploadAsset, file, assetType, fileParams, mode)
|
|
112
|
+
.provide([
|
|
113
|
+
[call(Api.uploadFile, file, assetType, fileParams, mode), fakeResponse]
|
|
114
|
+
])
|
|
115
|
+
.put({
|
|
116
|
+
type: types.UPLOAD_ASSET_SUCCESS,
|
|
117
|
+
data: fakeResponse.response.asset,
|
|
118
|
+
statusCode: 200
|
|
119
|
+
})
|
|
120
|
+
.run();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it.concurrent('handles failure in asset upload', () => {
|
|
124
|
+
const error = new Error('Failed to upload asset');
|
|
125
|
+
|
|
126
|
+
return expectSaga(sagas.uploadAsset, file, assetType, fileParams, mode)
|
|
127
|
+
.provide([
|
|
128
|
+
[call(Api.uploadFile, file, assetType, fileParams, mode), throwError(error)]
|
|
129
|
+
])
|
|
130
|
+
.put({
|
|
131
|
+
type: types.UPLOAD_ASSET_FAILURE,
|
|
132
|
+
error
|
|
133
|
+
})
|
|
134
|
+
.run();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('getIosCtas Saga', () => {
|
|
139
|
+
const licenseCode = 'ABC123';
|
|
140
|
+
|
|
141
|
+
it.concurrent('handles fetching iOS CTAs successfully', () => {
|
|
142
|
+
const fakeResponse = {
|
|
143
|
+
response: { metaEntities: { data: [{ id: 1, name: 'CTA One' }] } },
|
|
144
|
+
status: { code: 200 }
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return expectSaga(sagas.getIosCtas, licenseCode)
|
|
148
|
+
.provide([
|
|
149
|
+
[call(Api.getIosCtas, licenseCode), fakeResponse]
|
|
150
|
+
])
|
|
151
|
+
.put({
|
|
152
|
+
type: types.GET_IOS_CTAS_SUCCESS,
|
|
153
|
+
data: fakeResponse.response.metaEntities.data,
|
|
154
|
+
statusCode: 200
|
|
155
|
+
})
|
|
156
|
+
.run();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it.concurrent('handles failure in fetching iOS CTAs', () => {
|
|
160
|
+
const error = new Error('Fetch failed');
|
|
161
|
+
|
|
162
|
+
return expectSaga(sagas.getIosCtas, licenseCode)
|
|
163
|
+
.provide([
|
|
164
|
+
[call(Api.getIosCtas, licenseCode), throwError(error)]
|
|
165
|
+
])
|
|
166
|
+
.put({
|
|
167
|
+
type: types.GET_IOS_CTAS_FAILURE,
|
|
168
|
+
error
|
|
169
|
+
})
|
|
170
|
+
.run();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('getMobilepushTemplatesList Saga', () => {
|
|
175
|
+
const params = { channel: 'mobilepush', queryParams: { sort: 'asc' } };
|
|
176
|
+
|
|
177
|
+
it.concurrent('handles fetching mobile push templates list successfully', () => {
|
|
178
|
+
const fakeResponse = {
|
|
179
|
+
response: {
|
|
180
|
+
templates: [{ id: 1, name: 'Template One' }],
|
|
181
|
+
mapped: { id: 2, name: 'Mapped Template' }
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return expectSaga(sagas.getMobilepushTemplatesList, params)
|
|
186
|
+
.provide([
|
|
187
|
+
[call(Api.getAllTemplates, { channel: params.channel, queryParams: params.queryParams }), fakeResponse]
|
|
188
|
+
])
|
|
189
|
+
.put({
|
|
190
|
+
type: types.GET_MOBILEPUSH_TEMPLATES_LIST_SUCCESS,
|
|
191
|
+
data: fakeResponse.response.templates,
|
|
192
|
+
templateData: fakeResponse.response.mapped
|
|
193
|
+
})
|
|
194
|
+
.run();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it.concurrent('handles failure in fetching mobile push templates list', () => {
|
|
198
|
+
const error = new Error('Fetch failed');
|
|
199
|
+
|
|
200
|
+
return expectSaga(sagas.getMobilepushTemplatesList, params)
|
|
201
|
+
.provide([
|
|
202
|
+
[call(Api.getAllTemplates, { channel: params.channel, queryParams: params.queryParams }), throwError(error)]
|
|
203
|
+
])
|
|
204
|
+
.put({
|
|
205
|
+
type: types.GET_MOBILEPUSH_TEMPLATES_LIST_FAILURE,
|
|
206
|
+
error
|
|
207
|
+
})
|
|
208
|
+
.run();
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('fetchWeCrmAccounts Saga', () => {
|
|
213
|
+
const action = { source: 'CRM' };
|
|
214
|
+
|
|
215
|
+
it.concurrent('handles successful fetching of WeCRM accounts', () => {
|
|
216
|
+
const fakeResponse = {
|
|
217
|
+
response: [{ id: 1, name: 'Account One' }]
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
return expectSaga(sagas.fetchWeCrmAccounts, action)
|
|
221
|
+
.provide([
|
|
222
|
+
[call(Api.fetchWeCrmAccounts, action.source), fakeResponse]
|
|
223
|
+
])
|
|
224
|
+
.put({
|
|
225
|
+
type: types.GET_WECRM_ACCOUNTS_SUCCESS,
|
|
226
|
+
data: fakeResponse.response
|
|
227
|
+
})
|
|
228
|
+
.run();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it.concurrent('handles failure in fetching WeCRM accounts', () => {
|
|
232
|
+
const error = new Error('Fetch failed');
|
|
233
|
+
|
|
234
|
+
return expectSaga(sagas.fetchWeCrmAccounts, action)
|
|
235
|
+
.provide([
|
|
236
|
+
[call(Api.fetchWeCrmAccounts, action.source), throwError(error)]
|
|
237
|
+
])
|
|
238
|
+
.put({
|
|
239
|
+
type: types.GET_WECRM_ACCOUNTS_FAILURE,
|
|
240
|
+
data: error
|
|
241
|
+
})
|
|
242
|
+
.run();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
// Test combined saga
|
|
249
|
+
describe('Combined editMPushSaga', () => {
|
|
250
|
+
it.concurrent('should initialize all mobile push-related watcher sagas without error', () => {
|
|
251
|
+
return expectSaga(v2MobilePushEditSagas)
|
|
252
|
+
.run();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import { Edit } from '../index';
|
|
4
|
+
|
|
5
|
+
jest.mock('@capillarytech/cap-ui-library', () => ({
|
|
6
|
+
...jest.requireActual('@capillarytech/cap-ui-library'),
|
|
7
|
+
CapNotification: { success: jest.fn(), error: jest.fn() },
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const baseProps = (overrides = {}) => ({
|
|
11
|
+
actions: {
|
|
12
|
+
getWeCrmAccounts: jest.fn(),
|
|
13
|
+
setTemplateDetails: jest.fn(),
|
|
14
|
+
getTemplateDetails: jest.fn(),
|
|
15
|
+
clearEditResponse: jest.fn(),
|
|
16
|
+
clearData: jest.fn(),
|
|
17
|
+
editTemplate: jest.fn(),
|
|
18
|
+
},
|
|
19
|
+
globalActions: { fetchSchemaForEntity: jest.fn(), addMessageToQueue: jest.fn() },
|
|
20
|
+
Templates: { selectedWeChatAccount: { id: 'acc-1' } },
|
|
21
|
+
Edit: {},
|
|
22
|
+
Create: {},
|
|
23
|
+
params: {},
|
|
24
|
+
templateData: {},
|
|
25
|
+
location: { query: { type: 'library', module: 'default' }, pathname: '/mobilepush/edit/' },
|
|
26
|
+
route: { name: 'mobilepush' },
|
|
27
|
+
router: { push: jest.fn() },
|
|
28
|
+
metaEntities: {},
|
|
29
|
+
intl: { formatMessage: (m) => (m && (m.defaultMessage || m.id)) || '' },
|
|
30
|
+
isFullMode: true,
|
|
31
|
+
getFormLibraryData: jest.fn(),
|
|
32
|
+
onValidationFail: jest.fn(),
|
|
33
|
+
...overrides,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('MobilePush/Edit — full mode keeps the slidebox open after saving', () => {
|
|
37
|
+
it('keeps the form (and its _id) and asks the host to stay open', () => {
|
|
38
|
+
const props = baseProps();
|
|
39
|
+
const wrapper = shallow(<Edit {...props} />);
|
|
40
|
+
const instance = wrapper.instance();
|
|
41
|
+
instance.getTransformedData = () => ({ _id: 'mp-9', name: 'Push', definition: { mode: 'text' } });
|
|
42
|
+
const formData = { 0: { 'message-title': 'Hi' } };
|
|
43
|
+
wrapper.setState({ formData, editData: { _id: 'mp-9' } });
|
|
44
|
+
|
|
45
|
+
instance.onUpdateTemplateComplete({ templateId: 'mp-9' });
|
|
46
|
+
|
|
47
|
+
expect(wrapper.state('formData')).toEqual(formData);
|
|
48
|
+
expect(wrapper.state('editData')).toEqual({ _id: 'mp-9' });
|
|
49
|
+
expect(props.getFormLibraryData).toHaveBeenCalledWith({ validity: true, keepSlideBoxOpen: true });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('resets the host Save trigger when the update fails so the user can retry', () => {
|
|
53
|
+
const props = baseProps({ Edit: { editTemplateError: false } });
|
|
54
|
+
const wrapper = shallow(<Edit {...props} />);
|
|
55
|
+
|
|
56
|
+
wrapper.setProps({ Edit: { editTemplateError: true, editTemplateErrorMessage: 'boom' } });
|
|
57
|
+
|
|
58
|
+
expect(props.onValidationFail).toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
});
|