awing-library 2.1.116-beta → 2.1.117-beta

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 (37) hide show
  1. package/lib/ACM-AXN/PlaceGroup/Context.d.ts +0 -5
  2. package/lib/ACM-AXN/PlaceGroup/Context.js +0 -5
  3. package/lib/ACM-AXN/Wizard/Constant.d.ts +4 -0
  4. package/lib/ACM-AXN/Wizard/Constant.js +7 -0
  5. package/lib/ACM-AXN/Wizard/Container.d.ts +2 -0
  6. package/lib/ACM-AXN/Wizard/Container.js +46 -0
  7. package/lib/ACM-AXN/Wizard/Container.test.d.ts +1 -0
  8. package/lib/ACM-AXN/Wizard/Container.test.js +162 -0
  9. package/lib/ACM-AXN/Wizard/Context.d.ts +3 -0
  10. package/lib/ACM-AXN/Wizard/Context.js +5 -0
  11. package/lib/ACM-AXN/Wizard/CreateOrEdit/FormInformationBasic.d.ts +11 -0
  12. package/lib/ACM-AXN/Wizard/CreateOrEdit/FormInformationBasic.js +90 -0
  13. package/lib/ACM-AXN/Wizard/CreateOrEdit/FormInformationBasic.test.d.ts +1 -0
  14. package/lib/ACM-AXN/Wizard/CreateOrEdit/FormInformationBasic.test.js +113 -0
  15. package/lib/ACM-AXN/Wizard/CreateOrEdit/PageTemplate.d.ts +12 -0
  16. package/lib/ACM-AXN/Wizard/CreateOrEdit/PageTemplate.js +63 -0
  17. package/lib/ACM-AXN/Wizard/CreateOrEdit/PageTemplate.test.d.ts +1 -0
  18. package/lib/ACM-AXN/Wizard/CreateOrEdit/PageTemplate.test.js +50 -0
  19. package/lib/ACM-AXN/Wizard/CreateOrEdit/RowTemplate.d.ts +12 -0
  20. package/lib/ACM-AXN/Wizard/CreateOrEdit/RowTemplate.js +174 -0
  21. package/lib/ACM-AXN/Wizard/CreateOrEdit/RowTemplate.test.d.ts +1 -0
  22. package/lib/ACM-AXN/Wizard/CreateOrEdit/RowTemplate.test.js +259 -0
  23. package/lib/ACM-AXN/Wizard/CreateOrEdit/index.d.ts +2 -0
  24. package/lib/ACM-AXN/Wizard/CreateOrEdit/index.js +134 -0
  25. package/lib/ACM-AXN/Wizard/CreateOrEdit/index.test.d.ts +1 -0
  26. package/lib/ACM-AXN/Wizard/CreateOrEdit/index.test.js +223 -0
  27. package/lib/ACM-AXN/Wizard/Hooks.d.ts +2 -0
  28. package/lib/ACM-AXN/Wizard/Hooks.js +12 -0
  29. package/lib/ACM-AXN/Wizard/Types.d.ts +217 -0
  30. package/lib/ACM-AXN/Wizard/Types.js +22 -0
  31. package/lib/ACM-AXN/Wizard/Utils.d.ts +23 -0
  32. package/lib/ACM-AXN/Wizard/Utils.js +27 -0
  33. package/lib/ACM-AXN/Wizard/index.d.ts +3 -0
  34. package/lib/ACM-AXN/Wizard/index.js +40 -0
  35. package/lib/translate/en/translation.json +25 -0
  36. package/lib/translate/vi/translation.json +25 -0
  37. package/package.json +1 -1
@@ -1,8 +1,3 @@
1
- /**
2
- *
3
- * @author dauquan1108@gmail.com on 19/02/2024.
4
- *
5
- **/
6
1
  /// <reference types="react" />
7
2
  import { PlaceGroupPropsContext } from './Types';
8
3
  export declare const placeGroupPropsContext: import("react").Context<PlaceGroupPropsContext>;
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
- /**
3
- *
4
- * @author dauquan1108@gmail.com on 19/02/2024.
5
- *
6
- **/
7
2
  Object.defineProperty(exports, "__esModule", { value: true });
8
3
  exports.placeGroupPropsContext = void 0;
9
4
  var react_1 = require("react");
@@ -0,0 +1,4 @@
1
+ export declare const Constants: {
2
+ EDIT_PATH: string;
3
+ CREATE_PATH: string;
4
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Constants = void 0;
4
+ exports.Constants = {
5
+ EDIT_PATH: 'Edit',
6
+ CREATE_PATH: 'Create',
7
+ };
@@ -0,0 +1,2 @@
1
+ declare function Container(): import("react/jsx-runtime").JSX.Element;
2
+ export default Container;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
+ var react_1 = require("react");
8
+ var react_i18next_1 = require("react-i18next");
9
+ var Hooks_1 = __importDefault(require("./Hooks"));
10
+ var Constant_1 = require("./Constant");
11
+ var Context_1 = require("../../Context");
12
+ var Router_1 = require("../../AWING/Router");
13
+ var AWING_1 = require("../../AWING");
14
+ function Container() {
15
+ var _a;
16
+ var navigate = (0, Router_1.useNavigate)();
17
+ var t = (0, react_i18next_1.useTranslation)().t;
18
+ var service = (0, Hooks_1.default)().service;
19
+ var confirm = (0, Context_1.useAwing)().appHelper.confirm;
20
+ var _b = (0, react_1.useState)(false), loading = _b[0], setLoading = _b[1];
21
+ var _c = (0, react_1.useState)(), wizards = _c[0], setWizards = _c[1];
22
+ var queryData = (0, react_1.useCallback)(function (queryInput) {
23
+ var _a;
24
+ setLoading(true);
25
+ service
26
+ .wizardsPaging(undefined, (_a = queryInput === null || queryInput === void 0 ? void 0 : queryInput.searchString) === null || _a === void 0 ? void 0 : _a.trim(), queryInput.pageIndex, queryInput.pageSize)
27
+ .then(setWizards)
28
+ .finally(function () {
29
+ setLoading(false);
30
+ });
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, []);
33
+ return ((0, jsx_runtime_1.jsx)(AWING_1.PageManagement, { title: t('Wizard.Title'), onChangeQueryInput: queryData, inputSearchPlaceholder: t('Wizard.SearchPlaceholder'), columns: [
34
+ {
35
+ field: 'id',
36
+ headerName: '#',
37
+ valueGetter: function (row, idx, stt) { return stt; },
38
+ width: 60,
39
+ },
40
+ {
41
+ field: 'name',
42
+ headerName: t('Common.Name'),
43
+ },
44
+ ], loading: loading, confirmDelete: confirm, getRowId: function (row) { return row.id; }, rows: (wizards === null || wizards === void 0 ? void 0 : wizards.items) || [], onDelete: (_a = service.wizardsDelete) === null || _a === void 0 ? void 0 : _a.bind(service), totalOfRows: (wizards === null || wizards === void 0 ? void 0 : wizards.totalItemCount) || 0, onRowClick: function (id) { return navigate("".concat(Constant_1.Constants.EDIT_PATH, "/").concat(id)); }, onCreateButtonClick: function () { return navigate("".concat(Constant_1.Constants.CREATE_PATH)); } }));
45
+ }
46
+ exports.default = Container;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var jsx_runtime_1 = require("react/jsx-runtime");
54
+ var react_1 = require("@testing-library/react");
55
+ var Router_1 = require("../../AWING/Router");
56
+ var Container_1 = __importDefault(require("./Container"));
57
+ var Constant_1 = require("./Constant");
58
+ var items = [
59
+ {
60
+ campaignPriority: 0,
61
+ campaignTimeInDays: 1,
62
+ campaignType: 4,
63
+ directoryId: '5168908508924386000',
64
+ directoryPath: '.0.90.4913100144472996590.5168908508924386000.5099244903339020944.',
65
+ id: '5099244903339020944',
66
+ name: 'Data Collect 2',
67
+ },
68
+ {
69
+ campaignPriority: 0,
70
+ campaignTimeInDays: 1111,
71
+ campaignType: 6,
72
+ directoryId: '5168908508924386000',
73
+ directoryPath: '.0.90.4913100144472996590.5168908508924386000.5526032303356207617.',
74
+ id: '5526032303356207617',
75
+ name: 'Video',
76
+ },
77
+ ];
78
+ var clientMethod = {
79
+ wizardsDelete: function () { return function (_id) { }; },
80
+ wizardsPaging: function () {
81
+ return Promise.resolve({ items: items, totalItemCount: items.length });
82
+ },
83
+ };
84
+ // Mock service
85
+ jest.mock('./Hooks', function () { return ({
86
+ __esModule: true,
87
+ default: function () { return ({
88
+ service: {
89
+ wizardsDelete: jest.fn(function (_id) {
90
+ return Promise.resolve(clientMethod.wizardsDelete());
91
+ }),
92
+ wizardsPaging: jest.fn(function (_param) {
93
+ return Promise.resolve(clientMethod.wizardsPaging());
94
+ }),
95
+ },
96
+ }); },
97
+ }); });
98
+ // Mock đa ngữ
99
+ jest.mock('react-i18next', function () { return (__assign(__assign({}, jest.requireActual('react-i18next')), { useTranslation: function () { return ({ t: jest.fn(function (key) { return key; }) }); } })); });
100
+ // Mock PageManagement
101
+ jest.mock('../../AWING', function () { return ({
102
+ PageManagement: function (props) {
103
+ props.onChangeQueryInput({
104
+ searchString: '',
105
+ pageIndex: 0,
106
+ pageSize: 10,
107
+ });
108
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("span", { "data-testid": "title", children: "t('AuthenticationProfile.Title')" }), props.columns
109
+ .filter(function (item) { return item.valueGetter; })
110
+ .map(function (getter, idx) { return ((0, jsx_runtime_1.jsx)("span", { children: getter.valueGetter(items[0], idx) }, idx)); }), (0, jsx_runtime_1.jsx)("span", { "data-testid": "rowid", children: props.getRowId(items[0]) }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "Rowclick", onClick: function () {
111
+ props.onRowClick(items[0].id);
112
+ }, children: "Rowclick" }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "CreateBtn", onClick: props.onCreateButtonClick, children: "CreateBtn" }), (0, jsx_runtime_1.jsx)("button", { onClick: function () {
113
+ props.onChangeQueryInput({
114
+ pageIndex: 1,
115
+ pageSize: 10,
116
+ });
117
+ }, children: "ChangeInput" }), (0, jsx_runtime_1.jsx)("button", { "data-testid": "onDelete", onClick: function () {
118
+ props.onDelete('onDelete');
119
+ }, children: "Remove Btn" }), (0, jsx_runtime_1.jsx)("p", { children: JSON.stringify(props.rows) }), (0, jsx_runtime_1.jsxs)("span", { children: ["totalItemCount:", props.totalOfRows] })] }));
120
+ },
121
+ }); });
122
+ var renderUi = function () {
123
+ return (0, react_1.render)((0, jsx_runtime_1.jsx)(Router_1.BrowserRouter, { children: (0, jsx_runtime_1.jsx)(Container_1.default, {}) }));
124
+ };
125
+ describe('AccessPoint container component', function () {
126
+ it('Check renders component(Container).', function () {
127
+ renderUi();
128
+ expect(react_1.screen.getByTestId('title')).toBeInTheDocument();
129
+ expect(react_1.screen.getByTestId('CreateBtn')).toBeInTheDocument();
130
+ });
131
+ it('Chuyển đến trang thêm mới.', function () { return __awaiter(void 0, void 0, void 0, function () {
132
+ return __generator(this, function (_a) {
133
+ switch (_a.label) {
134
+ case 0:
135
+ renderUi();
136
+ expect(react_1.screen.getByTestId('CreateBtn')).toBeInTheDocument();
137
+ react_1.fireEvent.click(react_1.screen.getByTestId('CreateBtn'));
138
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
139
+ return expect(window.location.href).toContain(['http://localhost', Constant_1.Constants.CREATE_PATH].join('/'));
140
+ })];
141
+ case 1:
142
+ _a.sent();
143
+ return [2 /*return*/];
144
+ }
145
+ });
146
+ }); });
147
+ it('Chuyến đến trang Edit.', function () { return __awaiter(void 0, void 0, void 0, function () {
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0:
151
+ renderUi();
152
+ react_1.fireEvent.click(react_1.screen.getByTestId('Rowclick'));
153
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
154
+ return expect(window.location.href).toContain(['http://localhost', Constant_1.Constants.EDIT_PATH, items[0].id].join('/'));
155
+ })];
156
+ case 1:
157
+ _a.sent();
158
+ return [2 /*return*/];
159
+ }
160
+ });
161
+ }); });
162
+ });
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { WizardFeatureProps } from './Types';
3
+ export declare const wizardPropsContext: import("react").Context<WizardFeatureProps>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wizardPropsContext = void 0;
4
+ var react_1 = require("react");
5
+ exports.wizardPropsContext = (0, react_1.createContext)({});
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { IWizard, WizardGroup } from '../Types';
3
+ interface PropsFormBasic {
4
+ wizardData: IWizard;
5
+ wizardGroup: WizardGroup[];
6
+ onConfirmExit: () => void;
7
+ onChange: (wizardNew: object) => void;
8
+ }
9
+ declare function FormInformationBasic(props: PropsFormBasic): import("react/jsx-runtime").JSX.Element;
10
+ declare const _default: import("react").MemoExoticComponent<typeof FormInformationBasic>;
11
+ export default _default;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var jsx_runtime_1 = require("react/jsx-runtime");
4
+ var react_1 = require("react");
5
+ var react_i18next_1 = require("react-i18next");
6
+ var Utils_1 = require("../Utils");
7
+ var AWING_1 = require("../../../AWING");
8
+ function FormInformationBasic(props) {
9
+ var _a;
10
+ var onChange = props.onChange, onConfirmExit = props.onConfirmExit, wizardData = props.wizardData, wizardGroup = props.wizardGroup;
11
+ var t = (0, react_i18next_1.useTranslation)().t;
12
+ var campaignPriority = (0, react_1.useCallback)(function () {
13
+ var _a;
14
+ var priorityList = (_a = {},
15
+ _a[Utils_1.CAMPAIGN_PRIORITY.CLASS_A] = t('Wizard.PriorityA'),
16
+ _a[Utils_1.CAMPAIGN_PRIORITY.CLASS_B] = t('Wizard.PriorityB'),
17
+ _a[Utils_1.CAMPAIGN_PRIORITY.CLASS_C] = t('Wizard.PriorityC'),
18
+ _a);
19
+ return Object.values(Utils_1.CAMPAIGN_PRIORITY).map(function (item) { return ({
20
+ value: item,
21
+ text: priorityList[item],
22
+ }); });
23
+ }, [t]);
24
+ var campaignType = (0, react_1.useCallback)(function () {
25
+ var _a;
26
+ var typeList = (_a = {},
27
+ _a[Utils_1.CAMPAIGN_TYPE.BANNER_STATIC] = t('Wizard.BANNER_STATIC'),
28
+ _a[Utils_1.CAMPAIGN_TYPE.BANNER_EFFECT] = t('Wizard.BANNER_EFFECT'),
29
+ _a[Utils_1.CAMPAIGN_TYPE.BANNER_SLIDE] = t('Wizard.BANNER_SLIDE'),
30
+ _a[Utils_1.CAMPAIGN_TYPE.CPA] = t('Wizard.CPA'),
31
+ _a[Utils_1.CAMPAIGN_TYPE.SURVEY] = t('Wizard.SURVEY'),
32
+ _a[Utils_1.CAMPAIGN_TYPE.VIDEO] = t('Wizard.VIDEO'),
33
+ _a[Utils_1.CAMPAIGN_TYPE.GAME] = t('Wizard.GAME'),
34
+ _a[Utils_1.CAMPAIGN_TYPE.TEXT_MATCHING] = t('Wizard.TEXT_MATCHING'),
35
+ _a[Utils_1.CAMPAIGN_TYPE.OTHER] = t('Wizard.OTHER'),
36
+ _a);
37
+ return Object.values(Utils_1.CAMPAIGN_TYPE).map(function (item) { return ({
38
+ value: item,
39
+ text: typeList[item],
40
+ }); });
41
+ }, [t]);
42
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !(wizardGroup === null || wizardGroup === void 0 ? void 0 : wizardGroup.length) ? ((0, jsx_runtime_1.jsx)(AWING_1.CircularProgress, {})) : ((0, jsx_runtime_1.jsx)(AWING_1.BasicDataForm, { fields: [
43
+ {
44
+ fieldName: 'name',
45
+ type: 'text',
46
+ label: t('Common.Name'),
47
+ required: true,
48
+ value: (wizardData === null || wizardData === void 0 ? void 0 : wizardData.name) || '',
49
+ },
50
+ {
51
+ fieldName: 'wizardGroup',
52
+ type: 'autocomplete',
53
+ label: t('Wizard.WizardGroup'),
54
+ required: true,
55
+ options: wizardGroup.map(function (item) { return ({
56
+ text: (item === null || item === void 0 ? void 0 : item.name) || '',
57
+ value: (item === null || item === void 0 ? void 0 : item.id) || '',
58
+ }); }),
59
+ value: ((_a = wizardData === null || wizardData === void 0 ? void 0 : wizardData.wizardGroup) === null || _a === void 0 ? void 0 : _a.id) ||
60
+ (wizardData === null || wizardData === void 0 ? void 0 : wizardData.wizardGroup),
61
+ },
62
+ {
63
+ fieldName: 'campaignPriority',
64
+ type: 'autocomplete',
65
+ label: t('Wizard.Priority'),
66
+ required: true,
67
+ value: wizardData === null || wizardData === void 0 ? void 0 : wizardData.campaignPriority,
68
+ options: campaignPriority(),
69
+ },
70
+ {
71
+ fieldName: 'campaignType',
72
+ type: 'autocomplete',
73
+ label: t('Wizard.Type'),
74
+ required: true,
75
+ value: wizardData === null || wizardData === void 0 ? void 0 : wizardData.campaignType,
76
+ options: campaignType(),
77
+ },
78
+ {
79
+ fieldName: 'campaignTimeInDays',
80
+ type: 'number',
81
+ label: t('Wizard.CampaignTimeInDays'),
82
+ required: true,
83
+ value: wizardData === null || wizardData === void 0 ? void 0 : wizardData.campaignTimeInDays,
84
+ },
85
+ ], onUpdate: function (validState, valueForm) {
86
+ onConfirmExit();
87
+ onChange(valueForm);
88
+ } })) }));
89
+ }
90
+ exports.default = (0, react_1.memo)(FormInformationBasic);
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var jsx_runtime_1 = require("react/jsx-runtime");
54
+ /* eslint-disable testing-library/no-wait-for-side-effects */
55
+ var react_1 = require("@testing-library/react");
56
+ var FormInformationBasic_1 = __importDefault(require("./FormInformationBasic"));
57
+ var wizardGroup = [
58
+ { id: 1, code: 'Banner', name: 'Banner' },
59
+ { id: 2, code: 'Slide_banner', name: 'Slide banner' },
60
+ { id: 3, code: 'Collect_data', name: 'Collect data' },
61
+ ];
62
+ // Mock đa ngữ
63
+ jest.mock('react-i18next', function () { return (__assign(__assign({}, jest.requireActual('react-i18next')), { useTranslation: function () { return ({ t: jest.fn(function (key) { return key; }) }); } })); });
64
+ // mock BasicDataForm
65
+ jest.mock('../../../AWING', function () { return ({
66
+ BasicDataForm: function (props) {
67
+ return ((0, jsx_runtime_1.jsx)("div", { "data-testid": "BasicDataForm", children: (0, jsx_runtime_1.jsx)("button", { "data-testid": "onUpdate", onClick: function () {
68
+ props.onUpdate(true, {
69
+ name: 'QuanDX',
70
+ wizardGroup: 2,
71
+ campaignPriority: 0,
72
+ campaignType: 2,
73
+ campaignTimeInDays: 10,
74
+ });
75
+ } }) }));
76
+ },
77
+ }); });
78
+ var onChangeMock = jest.fn();
79
+ var onConfirmExitMock = jest.fn();
80
+ var renderUi = function () {
81
+ return (0, react_1.render)((0, jsx_runtime_1.jsx)(FormInformationBasic_1.default, { onConfirmExit: onConfirmExitMock, onChange: onChangeMock, wizardData: {}, wizardGroup: wizardGroup }));
82
+ };
83
+ describe('FromBasic component', function () {
84
+ it('Render component', function () {
85
+ renderUi();
86
+ expect(react_1.screen.getByTestId('onUpdate')).toBeInTheDocument();
87
+ });
88
+ it('Update data', function () { return __awaiter(void 0, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0:
92
+ renderUi();
93
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
94
+ react_1.fireEvent.click(react_1.screen.getByTestId('onUpdate'));
95
+ expect(onConfirmExitMock).toHaveBeenCalledTimes(1);
96
+ // eslint-disable-next-line testing-library/no-wait-for-multiple-assertions
97
+ expect(onChangeMock).toHaveBeenCalledTimes(1);
98
+ // eslint-disable-next-line testing-library/no-wait-for-multiple-assertions
99
+ expect(onChangeMock).toHaveBeenCalledWith({
100
+ name: 'QuanDX',
101
+ wizardGroup: 2,
102
+ campaignPriority: 0,
103
+ campaignType: 2,
104
+ campaignTimeInDays: 10,
105
+ });
106
+ })];
107
+ case 1:
108
+ _a.sent();
109
+ return [2 /*return*/];
110
+ }
111
+ });
112
+ }); });
113
+ });
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { IWizardTemplate } from '../Types';
3
+ interface PropsPageTemplate {
4
+ pageCodeValue: number;
5
+ wizardTemplates: IWizardTemplate[];
6
+ onConfirmExit: () => void;
7
+ onChange: (wizardNew: object) => void;
8
+ onUpdateWizardLogin?: (type: string, sortOrder?: number) => void;
9
+ }
10
+ declare function PageTemplate(props: PropsPageTemplate): import("react/jsx-runtime").JSX.Element;
11
+ declare const _default: import("react").MemoExoticComponent<typeof PageTemplate>;
12
+ export default _default;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var react_1 = require("react");
19
+ var react_i18next_1 = require("react-i18next");
20
+ var Add_1 = __importDefault(require("@mui/icons-material/Add"));
21
+ var material_1 = require("@mui/material");
22
+ var RowTemplate_1 = __importDefault(require("./RowTemplate"));
23
+ var Utils_1 = require("../Utils");
24
+ var enums_1 = require("../../../ACM-AXN/Page/enums");
25
+ function PageTemplate(props) {
26
+ var pageCodeValue = props.pageCodeValue, wizardTemplates = props.wizardTemplates, onChange = props.onChange, onConfirmExit = props.onConfirmExit, _a = props.onUpdateWizardLogin, onUpdateWizardLogin = _a === void 0 ? function () { return null; } : _a;
27
+ var t = (0, react_i18next_1.useTranslation)().t;
28
+ var isPageCodeLogin = pageCodeValue === enums_1.PageCode.Lgn;
29
+ var handleChangeRowTemplate = function (fieldValue, sortOrder) {
30
+ var _a;
31
+ onConfirmExit();
32
+ var pageName = isPageCodeLogin
33
+ ? 'wizardLoginTemplates'
34
+ : 'wizardWelcomeTemplates';
35
+ // Update data 'wizardLoginTemplates' || 'wizardWelcomeTemplates'
36
+ onChange((_a = {},
37
+ _a[pageName] = wizardTemplates.map(function (item) {
38
+ return item.sortOrder === sortOrder ? __assign(__assign({}, item), fieldValue) : item;
39
+ }),
40
+ _a));
41
+ };
42
+ var getKeyPageCode = (0, react_1.useCallback)(function () {
43
+ var text = Object.fromEntries(Object.entries(enums_1.PageCode).filter(function (_a) {
44
+ var key = _a[0];
45
+ return !isNaN(Number(key));
46
+ }))[pageCodeValue];
47
+ return text ? text.toLocaleLowerCase() : '';
48
+ }, [pageCodeValue]);
49
+ return ((0, jsx_runtime_1.jsxs)(material_1.Grid, { component: material_1.Paper, sx: {
50
+ p: 3,
51
+ ml: 3,
52
+ mr: 3,
53
+ mb: 3,
54
+ overflowX: 'auto',
55
+ }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: { display: 'flex', justifyContent: 'space-between' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: {
56
+ fontWeight: '600',
57
+ }, "data-testid": "title", children: isPageCodeLogin
58
+ ? t('Wizard.LoginTemplate')
59
+ : t('Wizard.WelcomeTemplate') }), isPageCodeLogin && ((0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", "aria-label": "button-add", title: t('Common.Add'), "data-testid": "button-add", onClick: function () {
60
+ return onUpdateWizardLogin(Utils_1.TYPE_LOGIN_TEMPLATE.ADD);
61
+ }, children: (0, jsx_runtime_1.jsx)(Add_1.default, {}) }))] }), wizardTemplates.map(function (template, idx) { return ((0, jsx_runtime_1.jsx)(RowTemplate_1.default, { template: template, pageCode: getKeyPageCode(), onChangeRow: handleChangeRowTemplate, onUpdateWizardLogin: onUpdateWizardLogin, disabledIconDelete: wizardTemplates.length === 1 }, idx)); })] }));
62
+ }
63
+ exports.default = (0, react_1.memo)(PageTemplate);
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ /* eslint-disable testing-library/no-wait-for-side-effects */
19
+ var react_1 = require("@testing-library/react");
20
+ var PageTemplate_1 = __importDefault(require("./PageTemplate"));
21
+ var Utils_1 = require("../Utils");
22
+ jest.mock('../Utils', function () { return ({
23
+ TYPE_LOGIN_TEMPLATE: { ADD: 'add', REMOVE: 'remove' },
24
+ }); });
25
+ // Mock đa ngữ
26
+ jest.mock('react-i18next', function () { return (__assign(__assign({}, jest.requireActual('react-i18next')), { useTranslation: function () { return ({ t: jest.fn(function (key) { return key; }) }); } })); });
27
+ jest.mock('./RowTemplate', function () { return function (props) { return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { "data-testid": "row-template-change", onClick: props.onChangeRow }) })); }; });
28
+ describe('PageTemplate component', function () {
29
+ var mockData = {
30
+ pageCodeValue: 1,
31
+ wizardTemplates: [],
32
+ onConfirmExit: jest.fn(),
33
+ onChange: jest.fn(),
34
+ onUpdateWizardLogin: jest.fn(),
35
+ };
36
+ it('Render component', function () {
37
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(PageTemplate_1.default, __assign({}, mockData)));
38
+ expect(react_1.screen.getByTestId('title')).toBeInTheDocument();
39
+ expect(react_1.screen.getByLabelText('button-add')).toBeInTheDocument();
40
+ var addButton = react_1.screen.getByTestId('button-add');
41
+ expect(addButton).toBeInTheDocument();
42
+ react_1.fireEvent.click(addButton);
43
+ expect(mockData.onUpdateWizardLogin).toHaveBeenCalledWith(Utils_1.TYPE_LOGIN_TEMPLATE.ADD);
44
+ });
45
+ it('should handle row template change', function () {
46
+ (0, react_1.render)((0, jsx_runtime_1.jsx)(PageTemplate_1.default, __assign({}, mockData, { wizardTemplates: [{ sortOrder: 0, name: 'Template1' }] })));
47
+ var rowTemplateButton = react_1.screen.getByTestId('row-template-change');
48
+ react_1.fireEvent.click(rowTemplateButton);
49
+ });
50
+ });
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { IWizardTemplate } from '../Types';
3
+ interface PropsRowTemplate {
4
+ pageCode: string;
5
+ template: IWizardTemplate;
6
+ disabledIconDelete: boolean;
7
+ onChangeRow: (fieldValue: any, sortOrder: number) => void;
8
+ onUpdateWizardLogin?: (type: string, sortOrder?: number) => void;
9
+ }
10
+ declare function RowTemplate(props: PropsRowTemplate): import("react/jsx-runtime").JSX.Element;
11
+ declare const _default: import("react").MemoExoticComponent<typeof RowTemplate>;
12
+ export default _default;