@capillarytech/creatives-library 7.15.6 → 7.15.7

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.
Files changed (29) hide show
  1. package/containers/Cap/tests/__snapshots__/index.test.js.snap +4 -193
  2. package/containers/LanguageProvider/index.js +0 -2
  3. package/containers/LanguageProvider/tests/index.test.js +0 -1
  4. package/i18n.js +2 -7
  5. package/package.json +1 -1
  6. package/services/api.js +9 -1
  7. package/translations/en.json +4 -192
  8. package/translations/zh.json +3 -191
  9. package/v2Components/FormBuilder/index.js +28 -4
  10. package/v2Containers/Cap/tests/__snapshots__/index.test.js.snap +4 -193
  11. package/v2Containers/CreativesContainer/constants.js +2 -0
  12. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +8 -0
  13. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/content.test.js.snap +15 -579
  14. package/v2Containers/Line/Container/ImageCarousel/tests/__snapshots__/index.test.js.snap +8 -386
  15. package/v2Containers/Line/Container/Wrapper/tests/__snapshots__/index.test.js.snap +68 -3281
  16. package/v2Containers/Line/Container/tests/__snapshots__/index.test.js.snap +72 -3474
  17. package/v2Containers/Rcs/messages.js +1 -1
  18. package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +259 -9136
  19. package/v2Containers/Sms/Create/actions.js +9 -0
  20. package/v2Containers/Sms/Create/constants.js +2 -0
  21. package/v2Containers/Sms/Create/index.js +12 -0
  22. package/v2Containers/Sms/Create/sagas.js +19 -3
  23. package/v2Containers/Sms/Create/tests/sagas.test.js +82 -0
  24. package/v2Containers/SmsTrai/Create/tests/__snapshots__/index.test.js.snap +16 -772
  25. package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +32 -1544
  26. package/v2Containers/Templates/messages.js +2 -2
  27. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +16 -0
  28. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +336 -13703
  29. package/translations/ja-JP.json +0 -2013
@@ -25,3 +25,12 @@ export function defaultAction() {
25
25
  type: types.DEFAULT_ACTION,
26
26
  };
27
27
  }
28
+
29
+ export function getAiSuggestions(prompt, successCallback, failureCallback) {
30
+ return {
31
+ type: types.GET_AI_SUGGESTIONS,
32
+ prompt,
33
+ successCallback,
34
+ failureCallback,
35
+ };
36
+ }
@@ -14,3 +14,5 @@ export const CREATE_TEMPLATE_FAILURE = 'app/v2Containers/Sms/Create/CREATE_TEMPL
14
14
  export const CLEAR_CREATE_RESPONSE_REQUEST = 'app/v2Containers/Sms/Create/CLEAR_CREATE_RESPONSE_REQUEST';
15
15
  export const CLEAR_CREATE_RESPONSE_SUCCESS = 'app/v2Containers/Sms/Create/CLEAR_CREATE_RESPONSE_SUCCESS';
16
16
  export const CLEAR_CREATE_RESPONSE_FAILURE = 'app/v2Containers/Sms/Create/CLEAR_CREATE_RESPONSE_FAILURE';
17
+
18
+ export const GET_AI_SUGGESTIONS = 'app/v2Containers/Sms/Create/GET_AI_SUGGESTIONS';
@@ -900,6 +900,17 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
900
900
  stopValidation = () => {
901
901
  this.setState({startValidation: false});
902
902
  }
903
+
904
+ getAiSuggestions = (prompt) => {
905
+ return new Promise((resolve, reject) => {
906
+ this.props.actions.getAiSuggestions(prompt, (result) => {
907
+ resolve(result);
908
+ }, (error) => {
909
+ reject(error);
910
+ })
911
+ })
912
+ }
913
+
903
914
  saveFormData() {
904
915
  //Logic to save in db etc
905
916
  const formData = _.cloneDeep(this.state.formData);
@@ -989,6 +1000,7 @@ export class Create extends React.Component { // eslint-disable-line react/prefe
989
1000
  selectedOfferDetails={this.props.selectedOfferDetails}
990
1001
  onTestContentClicked={this.props.onTestContentClicked}
991
1002
  onPreviewContentClicked={this.props.onPreviewContentClicked}
1003
+ fetchAiSuggestions={this.getAiSuggestions}
992
1004
  />
993
1005
  </CapColumn>
994
1006
  </CapRow>
@@ -29,7 +29,23 @@ function* watchCreateTemplate() {
29
29
  yield cancel(watcher);
30
30
  }
31
31
 
32
+ export function* getAiSuggestions({ prompt, successCallback, failureCallback }) {
33
+ try {
34
+ const result = yield call(Api.getAiSuggestions, {prompt});
35
+ yield successCallback(result);
36
+ } catch (error) {
37
+ yield failureCallback(error);
38
+ }
39
+ }
40
+
41
+ export function* watchAiSuggestions() {
42
+ const watcher = yield takeLatest(
43
+ types.GET_AI_SUGGESTIONS,
44
+ getAiSuggestions
45
+ );
46
+ yield take(LOCATION_CHANGE);
47
+ yield cancel(watcher);
48
+ }
49
+
32
50
  // All sagas to be loaded
33
- export default [
34
- watchCreateTemplate,
35
- ];
51
+ export default [watchCreateTemplate, watchAiSuggestions];
@@ -0,0 +1,82 @@
1
+ import { expectSaga } from "redux-saga-test-plan";
2
+ import { take, cancel, takeLatest } from "redux-saga/effects";
3
+ import * as matchers from "redux-saga-test-plan/matchers";
4
+ import { LOCATION_CHANGE } from "react-router-redux";
5
+ import { throwError } from "redux-saga-test-plan/providers";
6
+ import { createMockTask } from "redux-saga/utils";
7
+ import * as types from "../constants";
8
+ import { watchAiSuggestions, getAiSuggestions } from "../sagas";
9
+ import * as Api from "../../../../services/api";
10
+
11
+ describe("getAiSuggestions saga", () => {
12
+ it("Should handle valid response from api", () => {
13
+ const successCallback = () => {};
14
+ const failureCallback = () => {};
15
+ const action = {
16
+ type: types.GET_AI_SUGGESTIONS,
17
+ prompt: {},
18
+ successCallback,
19
+ failureCallback,
20
+ };
21
+ expectSaga(getAiSuggestions, action)
22
+ .provide([
23
+ [
24
+ matchers.call.fn(Api.getAiSuggestions),
25
+ {
26
+ success: true,
27
+ status: {
28
+ isError: false,
29
+ code: 200,
30
+ message: "success",
31
+ },
32
+ message: "Meta data fetched successfully",
33
+ response: {
34
+ "https://response.com": 1400,
35
+ },
36
+ },
37
+ ],
38
+ [matchers.call.fn(successCallback)],
39
+ ])
40
+ .run();
41
+ });
42
+
43
+ it("Should handles error thrown from api", () => {
44
+ const successCallback = () => {};
45
+ const failureCallback = () => {};
46
+ const action = {
47
+ type: types.GET_AI_SUGGESTIONS,
48
+ prompt: {},
49
+ successCallback,
50
+ failureCallback,
51
+ };
52
+ expectSaga(getAiSuggestions, action)
53
+ .provide([[matchers.call.fn(Api.getAiSuggestions), throwError()]])
54
+ .run();
55
+ });
56
+ });
57
+
58
+ describe("watchAiSuggestions saga", () => {
59
+ let generator = null;
60
+ beforeEach(() => {
61
+ generator = watchAiSuggestions();
62
+ });
63
+ it("Should handle valid response from api", () => {
64
+ const progress1 = generator.next();
65
+ const mockTask = takeLatest(types.GET_AI_SUGGESTIONS, getAiSuggestions);
66
+ expect(progress1.value).toEqual(mockTask);
67
+ const progress2 = generator.next();
68
+ expect(progress2.value).toEqual(take(LOCATION_CHANGE));
69
+ });
70
+
71
+ it("Should handle LOCATION_CHANGE action and cancel the watcher", () => {
72
+ generator = watchAiSuggestions();
73
+ const mockTask = createMockTask();
74
+
75
+ expect(generator.next().value).toEqual(
76
+ takeLatest(types.GET_AI_SUGGESTIONS, getAiSuggestions)
77
+ );
78
+ expect(generator.next(mockTask).value).toEqual(take(LOCATION_CHANGE));
79
+ expect(generator.next().value).toEqual(cancel(mockTask));
80
+ expect(generator.next().done).toEqual(true);
81
+ });
82
+ });