awing-library 2.1.220-dev → 2.1.222-dev

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.
@@ -1,67 +1,96 @@
1
1
  "use strict";
2
- // import { fireEvent, render, screen } from '@testing-library/react';
3
- // import { RowTable } from './RowTable';
4
- // // Mock the MUI components
5
- // jest.mock('@mui/material', () => ({
6
- // ...jest.requireActual('@mui/material'),
7
- // TableRow: ({ children }: any) => <tr>{children}</tr>,
8
- // TableCell: ({ children }: any) => <td>{children}</td>,
9
- // Box: ({ children }: any) => <div>{children}</div>,
10
- // Link: ({ children, href }: any) => <a href={href}>{children}</a>,
11
- // Chip: ({ label }: any) => <span>{label}</span>,
12
- // FormControl: ({ children }: any) => <div>{children}</div>,
13
- // Select: ({ children, value, onChange }: any) => (
14
- // <select value={value} onChange={onChange}>
15
- // {children}
16
- // </select>
17
- // ),
18
- // MenuItem: ({ children, value }: any) => <option value={value}>{children}</option>,
19
- // TextField: ({ value, onChange }: any) => (
20
- // <input type="text" value={value} onChange={onChange} />
21
- // ),
22
- // }));
23
- // const mockRow = {
24
- // link: 'https://example.com',
25
- // subCampaigns: [
26
- // { id: '1', name: 'Campaign 1' },
27
- // { id: '2',name: 'Campaign 2' },
28
- // ],
29
- // ghichu: 'Initial note',
30
- // status: 0,
31
- // };
32
- // const renderUi = () => render(<RowTable row={mockRow} id='' updateRow={() => {}} />);
33
- // describe('RowTable', () => {
34
- // it('renders the link correctly', () => {
35
- // renderUi();
36
- // const link = screen.getByRole('link', { name: 'https://example.com' });
37
- // expect(link).toBeInTheDocument();
38
- // expect(link).toHaveAttribute('href', 'https://example.com');
39
- // });
40
- // it('renders sub-campaigns as chips', () => {
41
- // renderUi();
42
- // expect(screen.getByText('Campaign 1')).toBeInTheDocument();
43
- // expect(screen.getByText('Campaign 2')).toBeInTheDocument();
44
- // });
45
- // it('renders the select with correct initial value', () => {
46
- // renderUi()
47
- // const select = screen.getByRole('combobox');
48
- // expect(select).toHaveValue('Chờ duyệt');
49
- // });
50
- // it('changes the select value when a new option is chosen', () => {
51
- // renderUi()
52
- // const select = screen.getByRole('combobox');
53
- // fireEvent.change(select, { target: { value: 'Duyệt' } });
54
- // expect(select).toHaveValue('Duyệt');
55
- // });
56
- // it('renders the text field with the initial note', () => {
57
- // renderUi()
58
- // const textField = screen.getByRole('textbox');
59
- // expect(textField).toHaveValue('Initial note');
60
- // });
61
- // it('updates the text field value when typed into', () => {
62
- // renderUi()
63
- // const textField = screen.getByRole('textbox');
64
- // fireEvent.change(textField, { target: { value: 'New note' } });
65
- // expect(textField).toHaveValue('New note');
66
- // });
67
- // });
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var jsx_runtime_1 = require("react/jsx-runtime");
15
+ var react_1 = require("@testing-library/react");
16
+ var RowTable_1 = require("./RowTable");
17
+ jest.mock('react-i18next', function () { return ({
18
+ useTranslation: function () { return ({ t: function (key) { return key; } }); },
19
+ }); });
20
+ // Mock the MUI components
21
+ jest.mock('@mui/material', function () { return (__assign(__assign({}, jest.requireActual('@mui/material')), { TableRow: function (_a) {
22
+ var children = _a.children;
23
+ return (0, jsx_runtime_1.jsx)("tr", { children: children });
24
+ }, TableCell: function (_a) {
25
+ var children = _a.children;
26
+ return (0, jsx_runtime_1.jsx)("td", { children: children });
27
+ }, Box: function (_a) {
28
+ var children = _a.children;
29
+ return (0, jsx_runtime_1.jsx)("div", { children: children });
30
+ }, Link: function (_a) {
31
+ var children = _a.children, href = _a.href;
32
+ return (0, jsx_runtime_1.jsx)("a", { href: href, children: children });
33
+ }, Chip: function (_a) {
34
+ var label = _a.label;
35
+ return (0, jsx_runtime_1.jsx)("span", { children: label });
36
+ }, FormControl: function (_a) {
37
+ var children = _a.children;
38
+ return (0, jsx_runtime_1.jsx)("div", { children: children });
39
+ }, Select: function (_a) {
40
+ var children = _a.children, value = _a.value, onChange = _a.onChange;
41
+ return ((0, jsx_runtime_1.jsx)("select", { value: value, onChange: onChange, children: children }));
42
+ }, MenuItem: function (_a) {
43
+ var children = _a.children, value = _a.value;
44
+ return ((0, jsx_runtime_1.jsx)("option", { value: value, children: children }));
45
+ }, TextField: function (_a) {
46
+ var value = _a.value, onChange = _a.onChange;
47
+ return ((0, jsx_runtime_1.jsx)("input", { type: "text", value: value, onChange: onChange }));
48
+ } })); });
49
+ var mockRow = {
50
+ id: 1,
51
+ linkPreview: 'https://example.com',
52
+ subCampaigns: [
53
+ { id: '1', name: 'Campaign 1' },
54
+ { id: '2', name: 'Campaign 2' },
55
+ ],
56
+ description: 'Initial note',
57
+ status: 0,
58
+ };
59
+ var renderUi = function () {
60
+ return (0, react_1.render)((0, jsx_runtime_1.jsx)(RowTable_1.RowTable, { row: mockRow, id: 1, updateRow: function () { } }));
61
+ };
62
+ describe('RowTable', function () {
63
+ it('renders the link correctly', function () {
64
+ renderUi();
65
+ var link = react_1.screen.getByRole('link', { name: 'https://example.com' });
66
+ expect(link).toBeInTheDocument();
67
+ expect(link).toHaveAttribute('href', 'https://example.com');
68
+ });
69
+ it('renders sub-campaigns as chips', function () {
70
+ renderUi();
71
+ expect(react_1.screen.getByText('Campaign 1')).toBeInTheDocument();
72
+ expect(react_1.screen.getByText('Campaign 2')).toBeInTheDocument();
73
+ });
74
+ it('renders the select with correct initial value', function () {
75
+ renderUi();
76
+ var select = react_1.screen.getByRole('combobox');
77
+ expect(select).toHaveValue('0');
78
+ });
79
+ it('changes the select value when a new option is chosen', function () {
80
+ renderUi();
81
+ var select = react_1.screen.getByRole('combobox');
82
+ react_1.fireEvent.change(select, { target: { value: 0 } });
83
+ expect(select).toHaveValue('0');
84
+ });
85
+ it('renders the text field with the initial note', function () {
86
+ renderUi();
87
+ var textField = react_1.screen.getByRole('textbox');
88
+ expect(textField).toHaveValue('Initial note');
89
+ });
90
+ it('updates the text field value when typed into', function () {
91
+ renderUi();
92
+ var textField = react_1.screen.getByRole('textbox');
93
+ react_1.fireEvent.change(textField, { target: { value: 'New note' } });
94
+ expect(textField).toHaveValue('New note');
95
+ });
96
+ });
@@ -189,7 +189,6 @@ function TabApprove() {
189
189
  }),
190
190
  });
191
191
  });
192
- setCampaignApproval(transformedData(data));
193
192
  return data;
194
193
  }
195
194
  data = domains.map(function (domain) {
@@ -202,7 +201,6 @@ function TabApprove() {
202
201
  detail: renderDataDetail(domain.domainId),
203
202
  };
204
203
  });
205
- setCampaignApproval(transformedData(data));
206
204
  return data;
207
205
  }, [domains]);
208
206
  var handleSelectAll = (0, react_1.useCallback)(function () {
@@ -218,6 +216,11 @@ function TabApprove() {
218
216
  service.domainsGetByIds(domainIds).then(setDomains);
219
217
  }
220
218
  }, [domainIds]);
219
+ (0, react_1.useEffect)(function () {
220
+ if (dataTable.length > 0) {
221
+ setCampaignApproval(transformedData(dataTable));
222
+ }
223
+ }, [dataTable]);
221
224
  return ((0, jsx_runtime_1.jsxs)(material_1.TableContainer, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", sx: {
222
225
  margin: '1rem',
223
226
  }, children: t('Campaign.Approval.GetApprovalInformation') }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", color: "primary", disabled: !rowSelected.length, children: t('Campaign.Approval.SendEmail') }), (0, jsx_runtime_1.jsxs)(material_1.Table, { sx: {
@@ -61,6 +61,12 @@ jest.mock('ACM-AXN/Campaign/Hooks');
61
61
  jest.mock('react-i18next', function () { return ({
62
62
  useTranslation: function () { return ({ t: function (key) { return key; } }); },
63
63
  }); });
64
+ // Mock PageManagement
65
+ jest.mock('./RowTable', function () { return ({
66
+ RowTable: function (props) {
67
+ return ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("button", { "data-testid": "update-row", onClick: props.updateRow }) }));
68
+ },
69
+ }); });
64
70
  // Mock các component MUI
65
71
  jest.mock('@mui/material', function () { return (__assign(__assign({}, jest.requireActual('@mui/material')), { TableContainer: function (_a) {
66
72
  var children = _a.children;
@@ -99,11 +105,6 @@ var domainByIds = [
99
105
  shareType: 0,
100
106
  },
101
107
  ];
102
- var clientMethod = {
103
- domainsGetByIds: function () { return function (_id) {
104
- Promise.resolve(domainByIds);
105
- }; },
106
- };
107
108
  // Mock Hooks
108
109
  jest.mock('ACM-AXN/Campaign/Hooks', function () { return ({
109
110
  __esModule: true,
@@ -2649,10 +2650,141 @@ var initCampaignData = {
2649
2650
  },
2650
2651
  ],
2651
2652
  };
2652
- var renderUi = function () {
2653
+ var initCampaignDataFetch = {
2654
+ campaign: {
2655
+ id: '4992385398844444137',
2656
+ directoryId: '5',
2657
+ directoryPath: '.0.5.4992385398844444137.',
2658
+ name: 'Long Test k ',
2659
+ createdDate: {
2660
+ seconds: '1727683388',
2661
+ nanos: 0,
2662
+ },
2663
+ },
2664
+ campaignGroups: [
2665
+ {
2666
+ campaignGroup: {
2667
+ numberHasRun: 0,
2668
+ id: 1,
2669
+ campaignId: '4992385398844444137',
2670
+ name: 'Sub-Campaign 1',
2671
+ ticket: 1,
2672
+ priority: 1,
2673
+ bookingAmount: 10,
2674
+ bonusAmount: 0,
2675
+ isReserved: false,
2676
+ billingUnit: 1,
2677
+ },
2678
+ ads: [
2679
+ {
2680
+ loginPage: {
2681
+ pageId: '5710972432387459630',
2682
+ directoryId: '12',
2683
+ pageCode: 'lgn',
2684
+ title: 'Sacombank_Sacombank Pay_T7/24_Banner Mall',
2685
+ layoutId: '0',
2686
+ transitionId: 0,
2687
+ commonHtml: '',
2688
+ directoryPath: '.0.6.12.5710972432387459630.',
2689
+ createdDate: {
2690
+ seconds: '1720943408',
2691
+ nanos: 0,
2692
+ },
2693
+ },
2694
+ welcomePage: {
2695
+ pageId: '5112329371092484686',
2696
+ directoryId: '11',
2697
+ pageCode: 'wlc',
2698
+ title: 'Sacombank_Sacombank Pay_T7/24',
2699
+ layoutId: '0',
2700
+ transitionId: 0,
2701
+ commonHtml: '',
2702
+ directoryPath: '.0.6.11.5112329371092484686.',
2703
+ createdDate: {
2704
+ seconds: '1720760590',
2705
+ nanos: 0,
2706
+ },
2707
+ },
2708
+ places: [
2709
+ {
2710
+ placeId: '5476424383102671899',
2711
+ domainId: '5462480518993333800',
2712
+ name: 'WMP_F209_FWMP Hào Nam',
2713
+ address: 'số 40 Hào Nam, Phường Ô Chợ Dừa, Q. Đống Đa, Thành phố Hà Nội',
2714
+ description: null,
2715
+ longitude: 105.8269428,
2716
+ latitude: 21.0230709,
2717
+ communeCode: '00190',
2718
+ districtCode: '006',
2719
+ provinceCode: '01',
2720
+ status: 0,
2721
+ joinedDate: {
2722
+ seconds: '1709885253',
2723
+ nanos: 0,
2724
+ },
2725
+ },
2726
+ ],
2727
+ deletedPlaces: null,
2728
+ id: 1,
2729
+ campaignId: '4992385398844444137',
2730
+ campaignGroupId: 1,
2731
+ name: 'Ad 1',
2732
+ status: true,
2733
+ type: 1,
2734
+ loginId: '5710972432387459630',
2735
+ welcomeId: '5112329371092484686',
2736
+ startDate: {
2737
+ seconds: '1727629200',
2738
+ nanos: 0,
2739
+ },
2740
+ endDate: {
2741
+ seconds: '1727629200',
2742
+ nanos: 0,
2743
+ },
2744
+ placeFilter: {
2745
+ operandGroups: [
2746
+ {
2747
+ operands: [
2748
+ {
2749
+ type: 0,
2750
+ operator: 7,
2751
+ value: '["5476424383102671899"]',
2752
+ },
2753
+ ],
2754
+ },
2755
+ ],
2756
+ },
2757
+ weights: [],
2758
+ advanced: null,
2759
+ },
2760
+ ],
2761
+ },
2762
+ ],
2763
+ campaignAttributes: [
2764
+ {
2765
+ campaignId: '4992385398844444137',
2766
+ attributeId: 9,
2767
+ },
2768
+ ],
2769
+ campaignPartner: null,
2770
+ campaignWizard: null,
2771
+ campaignApprovals: [
2772
+ {
2773
+ id: 5,
2774
+ campaignId: '4992385398844444137',
2775
+ domainId: '5462480518993333800',
2776
+ subCampaignId: '1',
2777
+ linkPreview: 'http://connect.awifi.com.vn/Preview/Page?loginId=5710972432387459630&isNetworkCampaign=true&welcomeId=5112329371092484686&domainId=5462480518993333800',
2778
+ status: 'Approval',
2779
+ description: 'ANhLong',
2780
+ },
2781
+ ],
2782
+ };
2783
+ var renderUi = function (initData) {
2784
+ if (initData === void 0) { initData = true; }
2653
2785
  var initializeState = function (_a) {
2654
2786
  var set = _a.set;
2655
- set(Recoils_1.campaignModelState, initCampaignData);
2787
+ set(Recoils_1.campaignModelState, initData ? initCampaignData : initCampaignDataFetch);
2656
2788
  };
2657
2789
  return (0, react_1.render)((0, jsx_runtime_1.jsx)(recoil_1.RecoilRoot, { initializeState: initializeState, children: (0, jsx_runtime_1.jsx)(Router_1.BrowserRouter, { children: (0, jsx_runtime_1.jsx)(_1.default, {}) }) }));
2658
2790
  };
@@ -2666,7 +2798,23 @@ describe('TabApprove', function () {
2666
2798
  return [2 /*return*/];
2667
2799
  });
2668
2800
  }); });
2669
- it('handles select all checkbox', function () { return __awaiter(void 0, void 0, void 0, function () {
2801
+ it('handles row selection correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
2802
+ return __generator(this, function (_a) {
2803
+ switch (_a.label) {
2804
+ case 0:
2805
+ renderUi();
2806
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
2807
+ var checkboxes = react_1.screen.getAllByRole('checkbox');
2808
+ react_1.fireEvent.click(checkboxes[1]); // Selecting the first domain
2809
+ expect(checkboxes[1]).toBeChecked();
2810
+ })];
2811
+ case 1:
2812
+ _a.sent();
2813
+ return [2 /*return*/];
2814
+ }
2815
+ });
2816
+ }); });
2817
+ it('handles "Select All" correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
2670
2818
  return __generator(this, function (_a) {
2671
2819
  switch (_a.label) {
2672
2820
  case 0:
@@ -2674,7 +2822,10 @@ describe('TabApprove', function () {
2674
2822
  return [4 /*yield*/, (0, react_1.waitFor)(function () {
2675
2823
  var selectAllCheckbox = react_1.screen.getAllByRole('checkbox')[0];
2676
2824
  react_1.fireEvent.click(selectAllCheckbox);
2677
- expect(react_1.screen.getByText('Campaign.Approval.SendEmail')).toBeInTheDocument();
2825
+ var checkboxes = react_1.screen.getAllByRole('checkbox');
2826
+ checkboxes.slice(1).forEach(function (checkbox) {
2827
+ expect(checkbox).toBeChecked();
2828
+ });
2678
2829
  })];
2679
2830
  case 1:
2680
2831
  _a.sent();
@@ -2682,17 +2833,43 @@ describe('TabApprove', function () {
2682
2833
  }
2683
2834
  });
2684
2835
  }); });
2685
- it('handles individual row selection', function () { return __awaiter(void 0, void 0, void 0, function () {
2836
+ it('disables "Send Email" button when no rows are selected', function () { return __awaiter(void 0, void 0, void 0, function () {
2686
2837
  return __generator(this, function (_a) {
2687
2838
  switch (_a.label) {
2688
2839
  case 0:
2689
2840
  renderUi();
2690
2841
  return [4 /*yield*/, (0, react_1.waitFor)(function () {
2691
- var firstRowCheckbox = react_1.screen.getAllByRole('checkbox')[1];
2692
- react_1.fireEvent.click(firstRowCheckbox);
2693
2842
  expect(react_1.screen.getByText('Campaign.Approval.SendEmail')).toBeInTheDocument();
2694
- react_1.fireEvent.click(firstRowCheckbox);
2695
- expect(react_1.screen.queryByText('Campaign.Approval.SendEmail')).not.toBeInTheDocument();
2843
+ })];
2844
+ case 1:
2845
+ _a.sent();
2846
+ return [2 /*return*/];
2847
+ }
2848
+ });
2849
+ }); });
2850
+ it('update row', function () { return __awaiter(void 0, void 0, void 0, function () {
2851
+ return __generator(this, function (_a) {
2852
+ switch (_a.label) {
2853
+ case 0:
2854
+ renderUi();
2855
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
2856
+ var buttonUpdateRow = react_1.screen.getByTestId('update-row');
2857
+ buttonUpdateRow.click();
2858
+ })];
2859
+ case 1:
2860
+ _a.sent();
2861
+ return [2 /*return*/];
2862
+ }
2863
+ });
2864
+ }); });
2865
+ it('fetch api data', function () { return __awaiter(void 0, void 0, void 0, function () {
2866
+ return __generator(this, function (_a) {
2867
+ switch (_a.label) {
2868
+ case 0:
2869
+ renderUi(false);
2870
+ return [4 /*yield*/, (0, react_1.waitFor)(function () {
2871
+ var buttonUpdateRow = react_1.screen.getByTestId('update-row');
2872
+ buttonUpdateRow.click();
2696
2873
  })];
2697
2874
  case 1:
2698
2875
  _a.sent();
@@ -128,13 +128,11 @@ function DataInput(props) {
128
128
  }, [type, value]);
129
129
  var handleParamValueChange = function () {
130
130
  var newValue = Number(numberValue);
131
- onChange(newValue, checkValidationValue(fieldDefinition, newValue));
131
+ setNumberValue(newValue);
132
+ if (type === 'number' && Number(value) !== newValue) {
133
+ onChange(newValue, checkValidationValue(fieldDefinition, newValue));
134
+ }
132
135
  };
133
- (0, react_2.useEffect)(function () {
134
- if (type === 'number' && Number(value) !== Number(numberValue))
135
- handleParamValueChange();
136
- // eslint-disable-next-line react-hooks/exhaustive-deps
137
- }, [numberValue, type]);
138
136
  switch (type) {
139
137
  case 'logic-expression': {
140
138
  return ((0, jsx_runtime_1.jsx)(LogicExpression_1.default, __assign({ cf: function (newValue, valid) {
@@ -216,7 +214,8 @@ function DataInput(props) {
216
214
  return ((0, jsx_runtime_1.jsx)(AWING_1.NumberFormat, __assign({ id: fieldName.toString(), name: fieldName.toString(), fullWidth: true, variant: "standard" }, other, { value: numberValue !== null && numberValue !== void 0 ? numberValue : '', onChange: function (event) {
217
215
  var newValue = event.target.value;
218
216
  setNumberValue(newValue);
219
- }, error: error, helperText: !disableHelperText && error
217
+ onChange(Number(newValue), checkValidationValue(fieldDefinition, Number(newValue)));
218
+ }, onBlur: handleParamValueChange, error: error, helperText: !disableHelperText && error
220
219
  ? (_h = fieldDefinition.helperText) !== null && _h !== void 0 ? _h : t('Common.InvalidData')
221
220
  : '' })));
222
221
  }
@@ -68,7 +68,6 @@ export interface NumberFieldDefinition<T extends DataObject> extends BaseFieldDe
68
68
  onValidate?(value?: number): boolean;
69
69
  defaultValue?: number;
70
70
  autoFormula?: string;
71
- isFloat?: boolean;
72
71
  min?: number;
73
72
  max?: number;
74
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.220-dev",
3
+ "version": "2.1.222-dev",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",