@capillarytech/creatives-library 7.17.38 → 7.17.39-alpha.1

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.
@@ -8,23 +8,29 @@ import {
8
8
  } from "./constants";
9
9
 
10
10
  export function* getTemplateInfoById({ payload }) {
11
+ const { preview = "", actionCallback } = payload;
11
12
  try {
12
13
  const res = yield call(Api.getTemplateInfoById, payload);
13
14
  if (res?.success) {
14
15
  yield put({
15
- type: payload?.preview
16
- ? ZALO_TEMPLATE_PREVIEW_INFO
17
- : ZALO_TEMPLATE_INFO_SUCCESS,
16
+ type: preview ? ZALO_TEMPLATE_PREVIEW_INFO : ZALO_TEMPLATE_INFO_SUCCESS,
18
17
  result: res?.response || {},
19
18
  });
20
19
  } else {
20
+ const errorMsg = res?.message || res?.status?.message;
21
21
  yield put({
22
22
  type: ZALO_TEMPLATE_INFO_ERROR,
23
- error: res?.error || res?.message,
23
+ error: errorMsg,
24
24
  });
25
+ if (actionCallback) {
26
+ actionCallback(errorMsg);
27
+ }
25
28
  }
26
29
  } catch (error) {
27
30
  yield put({ type: ZALO_TEMPLATE_INFO_ERROR, error });
31
+ if (actionCallback) {
32
+ actionCallback(error);
33
+ }
28
34
  }
29
35
  }
30
36
 
@@ -1,14 +1,12 @@
1
1
  import { createSelector } from "reselect";
2
- import { fromJS } from "immutable";
3
2
 
4
- const selectZaloDomain = (state = fromJS({})) => state.get("zalo");
3
+ const selectZaloDomain = () => (state) => state.get('zalo');
4
+ const selectAccountDomain = () => (state) => state.get('templates');
5
5
 
6
6
  const makeSelectZalo = () =>
7
- createSelector(selectZaloDomain, (substate = fromJS({})) => ({
8
- zaloTemplateInfoStatus: substate.get("zaloTemplateInfoStatus"),
9
- zaloTemplateInfoValue: substate.get("zaloTemplateInfoValue"),
10
- zaloTemplateInfoError: substate.get("zaloTemplateInfoError"),
11
- zaloTemplatePreviewData: substate.get("zaloTemplatePreviewData"),
12
- }));
13
-
14
- export { makeSelectZalo, selectZaloDomain };
7
+ createSelector(selectZaloDomain(), (substate) => substate && substate.toJS());
8
+
9
+ const makeSelectAccount = () =>
10
+ createSelector(selectAccountDomain(), (substate) => substate && substate.toJS());
11
+
12
+ export { makeSelectZalo, makeSelectAccount };
@@ -1,27 +1,25 @@
1
- import React from "react";
2
- import { injectIntl } from "react-intl";
3
- import { browserHistory } from "react-router";
4
- import "@testing-library/jest-dom";
5
- import { Provider } from "react-redux";
6
- import configureStore from "../../../store";
7
- import { Zalo } from "..";
1
+ import React from 'react';
2
+ import { injectIntl } from 'react-intl';
3
+ import { browserHistory } from 'react-router';
4
+ import '@testing-library/jest-dom';
5
+ import { Provider } from 'react-redux';
6
+ import configureStore from '../../../store';
7
+ import { Zalo } from '..';
8
8
  import {
9
9
  metaEntities,
10
- zaloTemplateInfoData,
10
+ editData,
11
11
  location,
12
12
  getDefaultTags,
13
13
  injectedTags,
14
- template,
14
+ accountData,
15
15
  templateData,
16
- } from "./mockData";
17
- import {
18
- render,
19
- screen,
20
- fireEvent,
21
- } from "../../../utils/test-utils";
16
+ } from './mockData';
17
+ import { render, screen, fireEvent } from '../../../utils/test-utils';
22
18
 
23
19
  const mockActions = {
24
20
  getTemplateInfoById: jest.fn(),
21
+ };
22
+ const mockGlobalActions = {
25
23
  fetchSchemaForEntity: jest.fn(),
26
24
  };
27
25
 
@@ -31,97 +29,146 @@ beforeAll(() => {
31
29
  });
32
30
 
33
31
  const ComponentToRender = injectIntl(Zalo);
34
- const renderComponent = (props) => render(
35
- <Provider store={store}>
36
- <ComponentToRender {...props} />
37
- </Provider>
32
+ const renderComponent = (props) =>
33
+ render(
34
+ <Provider store={store}>
35
+ <ComponentToRender {...props} />
36
+ </Provider>,
38
37
  );
39
38
 
40
-
41
- describe("Test activity zalo container", () => {
42
- it("test case for zalo template", async () => {
39
+ describe('Test activity zalo container', () => {
40
+ it('test case for zalo template', async () => {
43
41
  renderComponent({
44
42
  actions: mockActions,
45
- zaloTemplateInfoData,
43
+ globalActions: mockGlobalActions,
44
+ editData,
46
45
  metaEntities,
47
46
  location,
48
47
  getDefaultTags,
49
48
  injectedTags,
50
- template,
49
+ accountData,
51
50
  templateData,
51
+ isFullMode: true,
52
52
  });
53
- const inputBox = await screen.findAllByPlaceholderText('Add labels or text or combination of both');
54
- fireEvent.change(inputBox[0], { target: { value: "Hello, welcome" } });
53
+ const inputBox = await screen.findAllByPlaceholderText(
54
+ 'Add labels or text or combination of both',
55
+ );
56
+ fireEvent.change(inputBox[0], { target: { value: 'Hello, welcome' } });
55
57
  inputBox[0].focus();
56
- const previewButton = screen.getByTestId("preview-link-button");
58
+ const previewButton = screen.getByTestId('preview-link-button');
57
59
  previewButton.click();
58
60
  expect(
59
- screen.getByText("This template has been enabled")
61
+ screen.getByText('This template has been enabled'),
62
+ ).toBeInTheDocument();
63
+ });
64
+
65
+ it('test case for text field curly braces error', async () => {
66
+ renderComponent({
67
+ actions: mockActions,
68
+ globalActions: mockGlobalActions,
69
+ editData,
70
+ metaEntities,
71
+ location,
72
+ getDefaultTags,
73
+ injectedTags,
74
+ accountData,
75
+ templateData,
76
+ isFullMode: true,
77
+ });
78
+ const inputBox = await screen.findAllByPlaceholderText(
79
+ 'Add labels or text or combination of both',
80
+ );
81
+ fireEvent.change(inputBox[0], { target: { value: 'Hello, welcome {{' } });
82
+ inputBox[0].focus();
83
+ expect(
84
+ screen.getByText('Invalid label, please close all curly braces'),
60
85
  ).toBeInTheDocument();
61
86
  });
62
87
 
63
- it("test case for text field curly braces error", async () => {
88
+ it('test case for unsupported tag', async () => {
64
89
  renderComponent({
65
90
  actions: mockActions,
66
- zaloTemplateInfoData,
91
+ globalActions: mockGlobalActions,
92
+ editData,
67
93
  metaEntities,
68
94
  location,
69
95
  getDefaultTags,
70
96
  injectedTags,
71
- template,
97
+ accountData,
72
98
  templateData,
99
+ isFullMode: true,
100
+ });
101
+ const inputBox = await screen.findAllByPlaceholderText(
102
+ 'Add labels or text or combination of both',
103
+ );
104
+ fireEvent.change(inputBox[0], {
105
+ target: { value: 'Hello, welcome {{fsdaf}}' },
73
106
  });
74
- const inputBox = await screen.findAllByPlaceholderText('Add labels or text or combination of both');
75
- fireEvent.change(inputBox[0], { target: { value: "Hello, welcome {{" } });
76
107
  inputBox[0].focus();
77
108
  expect(
78
- screen.getByText("Invalid label, please close all curly braces")
109
+ screen.getByText(
110
+ 'Unsupported tags: fsdaf. Please remove them from this message.',
111
+ ),
79
112
  ).toBeInTheDocument();
80
113
  });
81
114
 
82
- it("test case for unsupported tag", async () => {
115
+ it('test case for length check', async () => {
83
116
  renderComponent({
84
117
  actions: mockActions,
85
- zaloTemplateInfoData,
118
+ globalActions: mockGlobalActions,
119
+ editData,
86
120
  metaEntities,
87
121
  location,
88
122
  getDefaultTags,
89
123
  injectedTags,
90
- template,
124
+ accountData,
91
125
  templateData,
126
+ isFullMode: false,
92
127
  });
93
- const inputBox = await screen.findAllByPlaceholderText('Add labels or text or combination of both');
128
+ const inputBox = await screen.findAllByPlaceholderText(
129
+ 'Add labels or text or combination of both',
130
+ );
94
131
  fireEvent.change(inputBox[0], {
95
- target: { value: "Hello, welcome {{fsdaf}}" },
132
+ target: {
133
+ value:
134
+ 'Hello, welcome user. Habata itara modoranai to ittta Mezashita no wa aoi aoi ano sora',
135
+ },
96
136
  });
97
137
  inputBox[0].focus();
98
138
  expect(
99
139
  screen.getByText(
100
- "Unsupported tags: fsdaf. Please remove them from this message."
101
- )
140
+ 'Character count for this variable should be in between 0 to 30',
141
+ ),
102
142
  ).toBeInTheDocument();
103
143
  });
104
144
 
105
- it("test case for length check", async () => {
145
+ it('test case for length check', async () => {
106
146
  renderComponent({
107
147
  actions: mockActions,
108
- zaloTemplateInfoData,
148
+ globalActions: mockGlobalActions,
149
+ editData,
109
150
  metaEntities,
110
151
  location,
111
152
  getDefaultTags,
112
153
  injectedTags,
113
- template,
154
+ accountData,
114
155
  templateData,
156
+ isFullMode: true,
115
157
  });
116
- const inputBox = await screen.findAllByPlaceholderText('Add labels or text or combination of both');
158
+ const inputBox = await screen.findAllByPlaceholderText(
159
+ 'Add labels or text or combination of both',
160
+ );
117
161
  fireEvent.change(inputBox[0], {
118
162
  target: {
119
- value: "Hello, welcome user. Habata itara modoranai to ittta Mezashita no wa aoi aoi ano sora",
163
+ value:
164
+ 'Hello, welcome user. Habata itara modoranai to ittta Mezashita no wa aoi aoi ano sora',
120
165
  },
121
166
  });
122
167
  inputBox[0].focus();
123
168
  expect(
124
- screen.getByText("Character count for this variable should be in between 0 to 30")
169
+ screen.getByText(
170
+ 'Character count for this variable should be in between 0 to 30',
171
+ ),
125
172
  ).toBeInTheDocument();
126
173
  });
127
174
  });