@controleonline/ui-crm 1.0.42
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/.github/actions/workers/manager/action.yml +147 -0
- package/.github/actions/workers/qa/action.yml +44 -0
- package/.github/actions/workers/security/action.yml +44 -0
- package/.github/actions/workers/technical-documenter/action.yml +51 -0
- package/.github/workflows/manager-worker.yml +167 -0
- package/.github/workflows/publish-npm.yml +40 -0
- package/.github/workflows/pull-request-checks.yml +29 -0
- package/.scrutinizer.yml +24 -0
- package/AGENTS.md +56 -0
- package/FUNDING.yml +1 -0
- package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
- package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
- package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
- package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
- package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
- package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
- package/docs/wiki.md +1 -0
- package/package.json +43 -0
- package/scripts/validate-wiki-pointer.cjs +13 -0
- package/src/react/components/AnimatedModal.js +149 -0
- package/src/react/components/AnimatedModal.styles.js +21 -0
- package/src/react/components/CreateContractModal.js +151 -0
- package/src/react/components/CreateContractModal.styles.js +43 -0
- package/src/react/hooks/useToastMessage.js +59 -0
- package/src/react/index.js +4 -0
- package/src/react/pages/ModelTemplatesPage.js +1461 -0
- package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
- package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
- package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
- package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
- package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
- package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
- package/src/react/pages/comissions/index.js +309 -0
- package/src/react/pages/comissions/index.styles.js +381 -0
- package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
- package/src/react/pages/crm/components/CrmHeader.js +117 -0
- package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
- package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
- package/src/react/pages/crm/components/OpportunityCard.js +138 -0
- package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
- package/src/react/pages/crm/components/OpportunityList.js +113 -0
- package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
- package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
- package/src/react/pages/crm/components/SelectModal.js +178 -0
- package/src/react/pages/crm/conversation.js +342 -0
- package/src/react/pages/crm/conversation.styles.js +206 -0
- package/src/react/pages/crm/hooks/useCrmData.js +494 -0
- package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
- package/src/react/pages/crm/index.js +262 -0
- package/src/react/pages/crm/index.styles.js +13 -0
- package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
- package/src/react/pages/crm/styles/card.styles.js +178 -0
- package/src/react/pages/crm/styles/layout.styles.js +184 -0
- package/src/react/pages/crm/styles/modal.styles.js +347 -0
- package/src/react/pages/home/index.js +559 -0
- package/src/react/pages/home/index.styles.js +268 -0
- package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
- package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
- package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
- package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
- package/src/react/pages/proposals/ProposalCard.js +112 -0
- package/src/react/pages/proposals/ProposalDetails.js +263 -0
- package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
- package/src/react/pages/proposals/index.js +488 -0
- package/src/react/pages/proposals/index.styles.js +248 -0
- package/src/react/pages/proposals/proposalListHelpers.js +216 -0
- package/src/react/pages/proposals/proposalNavigation.js +26 -0
- package/src/react/pages/royalties/ReceivablePage.js +233 -0
- package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
- package/src/react/pages/royalties/index.js +2 -0
- package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
- package/src/react/pages/settings/GeneralSettings.js +317 -0
- package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
- package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
- package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
- package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
- package/src/react/pages/settings/sections/CrmSection.js +281 -0
- package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
- package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
- package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
- package/src/react/pages/settings/sections/LogSection.js +322 -0
- package/src/react/pages/settings/sections/LoginSection.js +137 -0
- package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
- package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
- package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
- package/src/react/pages/settings/sections/MapsSection.js +629 -0
- package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
- package/src/react/pages/settings/sections/OperationsSection.js +303 -0
- package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
- package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
- package/src/react/pages/settings/sections/ShopSection.js +490 -0
- package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
- package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
- package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
- package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
- package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
- package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
- package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
- package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
- package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
- package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
- package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
- package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
- package/src/react/router/routes.js +135 -0
- package/src/react/utils/opportunityDate.js +82 -0
- package/src/react/utils/opportunityEditorReferences.js +76 -0
- package/src/react/utils/opportunityEmptyState.js +20 -0
- package/src/react/utils/opportunityPeople.js +111 -0
- package/src/react/utils/opportunityPhone.js +82 -0
- package/src/react/utils/opportunityStage.js +30 -0
- package/src/react/utils/opportunityStatusFilter.js +54 -0
- package/src/react/utils/proposalCreateHelpers.js +61 -0
- package/src/react/utils/proposalProductSelection.js +71 -0
- package/src/react/utils/royaltiesPayableParams.js +37 -0
- package/src/react/utils/translateWithFallback.js +42 -0
- package/src/store/crm/index.js +2 -0
- package/src/store/model/index.js +104 -0
- package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
- package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
- package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
- package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
- package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
- package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
- package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
- package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
- package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
- package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
- package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
- package/src/tests/react/pages/proposals/navigation.test.js +71 -0
- package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
- package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
- package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
- package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
- package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
- package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
- package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
- package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
- package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
- package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
- package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const {describe, it} = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
normalizeParentCategories,
|
|
6
|
+
buildMonthRows,
|
|
7
|
+
filterMonthRows,
|
|
8
|
+
buildIncomeStatementsParams,
|
|
9
|
+
formatCurrency,
|
|
10
|
+
} = require('../../../../react/pages/comissions/incomeStatementsHelpers.js');
|
|
11
|
+
|
|
12
|
+
describe('normalizeParentCategories', () => {
|
|
13
|
+
it('normalizes array payload with children', () => {
|
|
14
|
+
const raw = [
|
|
15
|
+
{
|
|
16
|
+
parent_id: 1,
|
|
17
|
+
parent_category_name: 'Comissões',
|
|
18
|
+
total_parent_category_price: '150.5',
|
|
19
|
+
categories_childs: [
|
|
20
|
+
{category_id: 10, category_name: 'comission', category_price: '100'},
|
|
21
|
+
{category_id: 11, category_name: 'royalties', category_price: '50.5'},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
const result = normalizeParentCategories(raw);
|
|
26
|
+
assert.equal(result.length, 1);
|
|
27
|
+
assert.equal(result[0].parentName, 'Comissões');
|
|
28
|
+
assert.equal(result[0].total, 150.5);
|
|
29
|
+
assert.equal(result[0].categories.length, 2);
|
|
30
|
+
assert.equal(result[0].categories[0].name, 'comission');
|
|
31
|
+
assert.equal(result[0].categories[1].total, 50.5);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('normalizes object map payload', () => {
|
|
35
|
+
const raw = {
|
|
36
|
+
a: {
|
|
37
|
+
parent_id: 'p1',
|
|
38
|
+
parent_category_name: 'Royalties',
|
|
39
|
+
total_parent_category_price: 20,
|
|
40
|
+
categories_childs: {
|
|
41
|
+
x: {category_id: 'c1', category_name: 'royalties', category_price: 20},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const result = normalizeParentCategories(raw);
|
|
46
|
+
assert.equal(result[0].parentId, 'p1');
|
|
47
|
+
assert.equal(result[0].categories[0].id, 'c1');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('handles empty input', () => {
|
|
51
|
+
assert.deepEqual(normalizeParentCategories(null), []);
|
|
52
|
+
assert.deepEqual(normalizeParentCategories(undefined), []);
|
|
53
|
+
assert.deepEqual(normalizeParentCategories({}), []);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('buildMonthRows', () => {
|
|
58
|
+
const statements = {
|
|
59
|
+
1: {
|
|
60
|
+
receive: {
|
|
61
|
+
total_month_price: 100,
|
|
62
|
+
parent_categories: [
|
|
63
|
+
{
|
|
64
|
+
parent_id: 1,
|
|
65
|
+
parent_category_name: 'Comissões',
|
|
66
|
+
total_parent_category_price: 100,
|
|
67
|
+
categories_childs: [],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
pay: {total_month_price: 40, parent_categories: []},
|
|
72
|
+
},
|
|
73
|
+
2: {
|
|
74
|
+
receive: {total_month_price: 0, parent_categories: []},
|
|
75
|
+
pay: {total_month_price: 0, parent_categories: []},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const labels = {1: 'jan', 2: 'feb'};
|
|
79
|
+
|
|
80
|
+
it('builds all non-zero months when selectedMonth is 0', () => {
|
|
81
|
+
const rows = buildMonthRows(statements, '0', labels);
|
|
82
|
+
assert.equal(rows.length, 1);
|
|
83
|
+
assert.equal(rows[0].month, 1);
|
|
84
|
+
assert.equal(rows[0].balance, 60);
|
|
85
|
+
assert.equal(rows[0].label, 'jan');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('builds only the selected month even if zero', () => {
|
|
89
|
+
const rows = buildMonthRows(statements, '2', labels);
|
|
90
|
+
assert.equal(rows.length, 1);
|
|
91
|
+
assert.equal(rows[0].month, 2);
|
|
92
|
+
assert.equal(rows[0].balance, 0);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('filterMonthRows', () => {
|
|
97
|
+
const rows = [
|
|
98
|
+
{
|
|
99
|
+
month: 1,
|
|
100
|
+
label: 'jan',
|
|
101
|
+
receiveTotal: 100,
|
|
102
|
+
payTotal: 40,
|
|
103
|
+
balance: 60,
|
|
104
|
+
receiveParents: [
|
|
105
|
+
{
|
|
106
|
+
parentId: '1',
|
|
107
|
+
parentName: 'Comissões',
|
|
108
|
+
total: 80,
|
|
109
|
+
categories: [
|
|
110
|
+
{id: '10', name: 'comission', total: 80},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
parentId: '2',
|
|
115
|
+
parentName: 'Outros',
|
|
116
|
+
total: 20,
|
|
117
|
+
categories: [{id: '20', name: 'service', total: 20}],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
payParents: [
|
|
121
|
+
{
|
|
122
|
+
parentId: '3',
|
|
123
|
+
parentName: 'Royalties',
|
|
124
|
+
total: 40,
|
|
125
|
+
categories: [{id: '30', name: 'royalties', total: 40}],
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
it('filters by nature receive', () => {
|
|
132
|
+
const filtered = filterMonthRows(rows, {nature: 'receive'});
|
|
133
|
+
assert.equal(filtered[0].payTotal, 0);
|
|
134
|
+
assert.equal(filtered[0].receiveTotal, 100);
|
|
135
|
+
assert.equal(filtered[0].payParents.length, 0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('filters by category query matching royalties', () => {
|
|
139
|
+
const filtered = filterMonthRows(rows, {categoryQuery: 'royalt'});
|
|
140
|
+
assert.equal(filtered.length, 1);
|
|
141
|
+
assert.equal(filtered[0].payParents.length, 1);
|
|
142
|
+
assert.equal(filtered[0].payParents[0].parentName, 'Royalties');
|
|
143
|
+
assert.equal(filtered[0].receiveParents.length, 0);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('filters by category query matching comission child', () => {
|
|
147
|
+
const filtered = filterMonthRows(rows, {categoryQuery: 'comission'});
|
|
148
|
+
assert.equal(filtered[0].receiveParents.length, 1);
|
|
149
|
+
assert.equal(filtered[0].receiveParents[0].categories[0].name, 'comission');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('buildIncomeStatementsParams', () => {
|
|
154
|
+
it('returns null without people or year', () => {
|
|
155
|
+
assert.equal(buildIncomeStatementsParams({}), null);
|
|
156
|
+
assert.equal(buildIncomeStatementsParams({peopleId: 1}), null);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('includes month only when 1-12', () => {
|
|
160
|
+
const withMonth = buildIncomeStatementsParams({
|
|
161
|
+
peopleId: 9,
|
|
162
|
+
year: '2026',
|
|
163
|
+
month: '3',
|
|
164
|
+
});
|
|
165
|
+
assert.deepEqual(withMonth, {people: 9, year: 2026, month: 3});
|
|
166
|
+
|
|
167
|
+
const allMonths = buildIncomeStatementsParams({
|
|
168
|
+
peopleId: 9,
|
|
169
|
+
year: 2026,
|
|
170
|
+
month: '0',
|
|
171
|
+
});
|
|
172
|
+
assert.deepEqual(allMonths, {people: 9, year: 2026});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe('formatCurrency', () => {
|
|
177
|
+
it('formats BRL', () => {
|
|
178
|
+
const text = formatCurrency(1234.5);
|
|
179
|
+
assert.match(text, /1\.234,50|R\$/);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const {describe, it} = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
buildComissionRequestParams,
|
|
6
|
+
buildMonthOptions,
|
|
7
|
+
collectClientsFromInvoices,
|
|
8
|
+
extractClientFromInvoice,
|
|
9
|
+
filterInvoicesByClient,
|
|
10
|
+
formatCurrency,
|
|
11
|
+
groupCommissionsByMonth,
|
|
12
|
+
normalizeComissionList,
|
|
13
|
+
resolveInvoiceDate,
|
|
14
|
+
} = require('../../../../react/pages/comissions/sellerCommissionsHelpers.js');
|
|
15
|
+
|
|
16
|
+
describe('sellerCommissionsHelpers', () => {
|
|
17
|
+
it('buildComissionRequestParams sets invoiceType comission and receiver', () => {
|
|
18
|
+
const params = buildComissionRequestParams({
|
|
19
|
+
year: '2026',
|
|
20
|
+
month: '3',
|
|
21
|
+
receiverId: 42,
|
|
22
|
+
clientId: 11,
|
|
23
|
+
});
|
|
24
|
+
assert.equal(params.invoiceType, 'comission');
|
|
25
|
+
assert.equal(params.receiver, 42);
|
|
26
|
+
assert.equal(params.year, 2026);
|
|
27
|
+
assert.equal(params.month, 3);
|
|
28
|
+
assert.equal(params.client, 11);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('buildComissionRequestParams omits invalid month and empty client', () => {
|
|
32
|
+
const params = buildComissionRequestParams({
|
|
33
|
+
year: '2026',
|
|
34
|
+
month: '0',
|
|
35
|
+
receiverId: 7,
|
|
36
|
+
clientId: '',
|
|
37
|
+
});
|
|
38
|
+
assert.equal(params.month, undefined);
|
|
39
|
+
assert.equal(params.client, undefined);
|
|
40
|
+
assert.equal(params.receiver, 7);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('normalizeComissionList accepts array, member and hydra shapes', () => {
|
|
44
|
+
assert.deepEqual(normalizeComissionList([{id: 1}]), [{id: 1}]);
|
|
45
|
+
assert.deepEqual(normalizeComissionList({member: [{id: 2}]}), [{id: 2}]);
|
|
46
|
+
assert.deepEqual(
|
|
47
|
+
normalizeComissionList({'hydra:member': [{id: 3}]}),
|
|
48
|
+
[{id: 3}],
|
|
49
|
+
);
|
|
50
|
+
assert.deepEqual(normalizeComissionList(null), []);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('extractClientFromInvoice reads nested order.client', () => {
|
|
54
|
+
const invoice = {
|
|
55
|
+
id: 1,
|
|
56
|
+
order: [{order: {client: {id: 99, name: 'Acme', alias: 'AC'}}}],
|
|
57
|
+
};
|
|
58
|
+
const client = extractClientFromInvoice(invoice);
|
|
59
|
+
assert.equal(client.id, 99);
|
|
60
|
+
assert.equal(client.name, 'Acme');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('filterInvoicesByClient keeps only matching client', () => {
|
|
64
|
+
const invoices = [
|
|
65
|
+
{id: 1, order: [{order: {client: {id: 10, name: 'A'}}}]},
|
|
66
|
+
{id: 2, order: [{order: {client: {id: 20, name: 'B'}}}]},
|
|
67
|
+
];
|
|
68
|
+
const filtered = filterInvoicesByClient(invoices, 10);
|
|
69
|
+
assert.equal(filtered.length, 1);
|
|
70
|
+
assert.equal(filtered[0].id, 1);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('groupCommissionsByMonth aggregates totals for seller receive', () => {
|
|
74
|
+
const invoices = [
|
|
75
|
+
{id: 1, price: 100, dueDate: '2026-03-10T12:00:00Z'},
|
|
76
|
+
{id: 2, price: 50, dueDate: '2026-03-20T12:00:00Z'},
|
|
77
|
+
{id: 3, price: 30, dueDate: '2026-04-05T12:00:00Z'},
|
|
78
|
+
];
|
|
79
|
+
const rows = groupCommissionsByMonth(invoices, {
|
|
80
|
+
selectedMonth: '0',
|
|
81
|
+
year: 2026,
|
|
82
|
+
monthLabelById: {3: 'Mar', 4: 'Abr'},
|
|
83
|
+
});
|
|
84
|
+
assert.equal(rows.length, 2);
|
|
85
|
+
assert.equal(rows[0].month, 3);
|
|
86
|
+
assert.equal(rows[0].total, 150);
|
|
87
|
+
assert.equal(rows[0].count, 2);
|
|
88
|
+
assert.equal(rows[1].month, 4);
|
|
89
|
+
assert.equal(rows[1].total, 30);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('groupCommissionsByMonth respects selectedMonth filter', () => {
|
|
93
|
+
const invoices = [
|
|
94
|
+
{id: 1, price: 100, dueDate: '2026-03-10T12:00:00Z'},
|
|
95
|
+
{id: 2, price: 50, dueDate: '2026-04-10T12:00:00Z'},
|
|
96
|
+
];
|
|
97
|
+
const rows = groupCommissionsByMonth(invoices, {
|
|
98
|
+
selectedMonth: '3',
|
|
99
|
+
year: 2026,
|
|
100
|
+
});
|
|
101
|
+
assert.equal(rows.length, 1);
|
|
102
|
+
assert.equal(rows[0].month, 3);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('collectClientsFromInvoices returns unique sorted clients', () => {
|
|
106
|
+
const invoices = [
|
|
107
|
+
{order: [{order: {client: {id: 2, name: 'Beta'}}}]},
|
|
108
|
+
{order: [{order: {client: {id: 1, name: 'Alpha'}}}]},
|
|
109
|
+
{order: [{order: {client: {id: 2, name: 'Beta'}}}]},
|
|
110
|
+
];
|
|
111
|
+
const clients = collectClientsFromInvoices(invoices);
|
|
112
|
+
assert.equal(clients.length, 2);
|
|
113
|
+
assert.equal(clients[0].name, 'Alpha');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('resolveInvoiceDate prefers dueDate', () => {
|
|
117
|
+
const date = resolveInvoiceDate({dueDate: '2026-08-01T00:00:00Z'});
|
|
118
|
+
assert.ok(date instanceof Date);
|
|
119
|
+
assert.equal(date.getUTCFullYear(), 2026);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('formatCurrency formats BRL', () => {
|
|
123
|
+
const text = formatCurrency(12.5);
|
|
124
|
+
assert.match(text, /12/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('buildMonthOptions returns 13 entries including all', () => {
|
|
128
|
+
const options = buildMonthOptions(() => 'x');
|
|
129
|
+
assert.equal(options.length, 13);
|
|
130
|
+
assert.equal(options[0].id, '0');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const vm = require('node:vm');
|
|
6
|
+
|
|
7
|
+
const sourcePath = path.join(
|
|
8
|
+
__dirname,
|
|
9
|
+
'../../../../react/pages/crm/marketingEventsHelpers.js',
|
|
10
|
+
);
|
|
11
|
+
const source = fs.readFileSync(sourcePath, 'utf8');
|
|
12
|
+
const transformed = source
|
|
13
|
+
.replace(/export const /g, 'const ')
|
|
14
|
+
.concat(
|
|
15
|
+
'\n;module.exports = { EVENT_LABELS, normalizePeopleIri, extractCollection, buildUtmSummary };',
|
|
16
|
+
);
|
|
17
|
+
const mod = {exports: {}};
|
|
18
|
+
vm.runInNewContext(transformed, {module: mod, exports: mod.exports});
|
|
19
|
+
const {
|
|
20
|
+
normalizePeopleIri,
|
|
21
|
+
extractCollection,
|
|
22
|
+
buildUtmSummary,
|
|
23
|
+
EVENT_LABELS,
|
|
24
|
+
} = mod.exports;
|
|
25
|
+
|
|
26
|
+
test('normalizePeopleIri accepts id, iri and object', () => {
|
|
27
|
+
assert.equal(normalizePeopleIri(42), '/people/42');
|
|
28
|
+
assert.equal(normalizePeopleIri('/people/7'), '/people/7');
|
|
29
|
+
assert.equal(normalizePeopleIri('/peoples/7'), '/people/7');
|
|
30
|
+
assert.equal(normalizePeopleIri({id: 9}), '/people/9');
|
|
31
|
+
assert.equal(normalizePeopleIri({'@id': '/people/3'}), '/people/3');
|
|
32
|
+
assert.equal(normalizePeopleIri(null), '');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('extractCollection supports hydra and plain arrays', () => {
|
|
36
|
+
assert.equal(extractCollection([{id: 1}])[0].id, 1);
|
|
37
|
+
assert.equal(extractCollection({'hydra:member': [{id: 2}]})[0].id, 2);
|
|
38
|
+
assert.equal(extractCollection({member: [{id: 3}]})[0].id, 3);
|
|
39
|
+
assert.equal(extractCollection(null).length, 0);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('buildUtmSummary joins present UTM fields', () => {
|
|
43
|
+
assert.equal(buildUtmSummary({}), null);
|
|
44
|
+
assert.equal(
|
|
45
|
+
buildUtmSummary({utmSource: 'google', utmCampaign: 'spring'}),
|
|
46
|
+
'src=google · cmp=spring',
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('EVENT_LABELS covers allowlist', () => {
|
|
51
|
+
assert.ok(EVENT_LABELS.page_view);
|
|
52
|
+
assert.ok(EVENT_LABELS.lead_created);
|
|
53
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression: OPORTUNIDADES "buscar cliente" must filter by client name,
|
|
3
|
+
* not by opportunity id (app-community#14).
|
|
4
|
+
*/
|
|
5
|
+
const { describe, it } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
|
|
8
|
+
function buildClientSearchParams({ searchQuery, companyId, page = 1 }) {
|
|
9
|
+
if (!companyId) return null;
|
|
10
|
+
const query = String(searchQuery ?? '').trim();
|
|
11
|
+
const params = {
|
|
12
|
+
type: 'relationship',
|
|
13
|
+
provider: companyId,
|
|
14
|
+
page,
|
|
15
|
+
};
|
|
16
|
+
if (query) {
|
|
17
|
+
params['peoples.people.name'] = query;
|
|
18
|
+
}
|
|
19
|
+
return params;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('opportunity client search params (app-community#14)', () => {
|
|
23
|
+
it('uses peoples.people.name and never sends id as the search key', () => {
|
|
24
|
+
const params = buildClientSearchParams({
|
|
25
|
+
searchQuery: ' Acme Corp ',
|
|
26
|
+
companyId: 42,
|
|
27
|
+
});
|
|
28
|
+
assert.equal(params['peoples.people.name'], 'Acme Corp');
|
|
29
|
+
assert.equal(params.id, undefined);
|
|
30
|
+
assert.equal(params.search, undefined);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('empty search does not add peoples.people.name', () => {
|
|
34
|
+
const params = buildClientSearchParams({
|
|
35
|
+
searchQuery: ' ',
|
|
36
|
+
companyId: 42,
|
|
37
|
+
});
|
|
38
|
+
assert.equal(params['peoples.people.name'], undefined);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('returns null without company', () => {
|
|
42
|
+
assert.equal(buildClientSearchParams({ searchQuery: 'x', companyId: null }), null);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
buildProposalProductsParams,
|
|
8
|
+
buildProposalDetailsParams,
|
|
9
|
+
getProposalInitialTabIndex,
|
|
10
|
+
} = require('../../../../react/pages/proposals/proposalNavigation');
|
|
11
|
+
|
|
12
|
+
const proposalsPageSource = fs.readFileSync(
|
|
13
|
+
path.resolve(__dirname, '../../../../react/pages/proposals/index.js'),
|
|
14
|
+
'utf8',
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const proposalDetailsSource = fs.readFileSync(
|
|
18
|
+
path.resolve(__dirname, '../../../../react/pages/proposals/ProposalDetails.js'),
|
|
19
|
+
'utf8',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const proposalCardSource = fs.readFileSync(
|
|
23
|
+
path.resolve(__dirname, '../../../../react/pages/proposals/ProposalCard.js'),
|
|
24
|
+
'utf8',
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
test('buildProposalProductsParams includes initialTab products', () => {
|
|
28
|
+
assert.deepEqual(buildProposalProductsParams(42), {
|
|
29
|
+
contractId: 42,
|
|
30
|
+
initialTab: 'products',
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('buildProposalDetailsParams omits initialTab by default', () => {
|
|
35
|
+
assert.deepEqual(buildProposalDetailsParams(7), { contractId: 7 });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('getProposalInitialTabIndex maps products to tab 1', () => {
|
|
39
|
+
assert.equal(getProposalInitialTabIndex('products'), 1);
|
|
40
|
+
assert.equal(getProposalInitialTabIndex('PRODUCTS'), 1);
|
|
41
|
+
assert.equal(getProposalInitialTabIndex(''), 0);
|
|
42
|
+
assert.equal(getProposalInitialTabIndex(undefined), 0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('proposal list products shortcut opens ProposalDetails with the products tab selected', () => {
|
|
46
|
+
const compact = proposalCardSource.replace(/\s+/g, ' ');
|
|
47
|
+
assert.match(compact, /buildProposalProductsParams\(contract\.id\)/);
|
|
48
|
+
assert.match(compact, /navigation\.navigate\(\s*'ProposalDetails'/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('proposal details normalize the products tab request before selecting the products tab', () => {
|
|
52
|
+
assert.match(
|
|
53
|
+
proposalDetailsSource.replace(/\s+/g, ' '),
|
|
54
|
+
/getProposalInitialTabIndex\(initialTab\)/,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('proposal details switch the active tab to Produtos when the route asks for it', () => {
|
|
59
|
+
assert.match(
|
|
60
|
+
proposalDetailsSource.replace(/\s+/g, ' '),
|
|
61
|
+
/setActiveTab\(targetTabIndex\)/,
|
|
62
|
+
);
|
|
63
|
+
assert.match(
|
|
64
|
+
proposalDetailsSource.replace(/\s+/g, ' '),
|
|
65
|
+
/scrollRef\.current\?\.scrollTo\(\{\s*x:\s*targetTabIndex \* width,\s*animated:\s*false\s*\}\)/,
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('proposals index still wires ProposalCard for list items', () => {
|
|
70
|
+
assert.match(proposalsPageSource, /<ProposalCard/);
|
|
71
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
normalizeStatusKey,
|
|
6
|
+
getStatusColor,
|
|
7
|
+
getContractPartyCandidates,
|
|
8
|
+
isIgnoredContractPartyId,
|
|
9
|
+
} = require('../../../../react/pages/proposals/proposalListHelpers');
|
|
10
|
+
|
|
11
|
+
test('normalizeStatusKey lowercases and collapses separators', () => {
|
|
12
|
+
assert.equal(normalizeStatusKey('Waiting_Signature'), 'waiting signature');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('getStatusColor returns green for signed/active', () => {
|
|
16
|
+
assert.equal(getStatusColor('signed'), '#10B981');
|
|
17
|
+
assert.equal(getStatusColor('open'), '#3B82F6');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('getContractPartyCandidates prefers provider then contractor order', () => {
|
|
21
|
+
const contract = {
|
|
22
|
+
peoples: [
|
|
23
|
+
{ peopleType: 'witness', people: { id: 3, name: 'W' } },
|
|
24
|
+
{ peopleType: 'provider', people: { id: 1, name: 'P' } },
|
|
25
|
+
{ peopleType: 'contractor', people: { id: 2, name: 'C' } },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
const candidates = getContractPartyCandidates(contract);
|
|
29
|
+
assert.equal(candidates[0].name, 'P');
|
|
30
|
+
assert.equal(candidates[1].name, 'C');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('isIgnoredContractPartyId ignores current company', () => {
|
|
34
|
+
assert.equal(
|
|
35
|
+
isIgnoredContractPartyId({ contractModel: {} }, '10', { id: 10 }),
|
|
36
|
+
true,
|
|
37
|
+
);
|
|
38
|
+
assert.equal(
|
|
39
|
+
isIgnoredContractPartyId({ contractModel: {} }, '99', { id: 10 }),
|
|
40
|
+
false,
|
|
41
|
+
);
|
|
42
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { describe, it } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const {
|
|
4
|
+
ROYALTIES_INVOICE_TYPE,
|
|
5
|
+
resolveRoyaltiesReceivableRequestParams,
|
|
6
|
+
resolveRoyaltiesReceivablePreferenceKey,
|
|
7
|
+
resolveRoyaltiesReceivableTitle,
|
|
8
|
+
ROYALTIES_FLOW_NOTE,
|
|
9
|
+
DEFAULT_ROYALTIES_RECEIVABLE_DATE_FILTER,
|
|
10
|
+
} = require('../../../../react/pages/royalties/royaltiesReceivableHelpers.js');
|
|
11
|
+
|
|
12
|
+
describe('royaltiesReceivableHelpers', () => {
|
|
13
|
+
it('exports royalties invoice type constant', () => {
|
|
14
|
+
assert.equal(ROYALTIES_INVOICE_TYPE, 'royalties');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('builds request params without company (type only)', () => {
|
|
18
|
+
const params = resolveRoyaltiesReceivableRequestParams({});
|
|
19
|
+
assert.deepEqual(params, { invoiceType: 'royalties' });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('builds franchisor receivables params with receiver + exclude own transfers', () => {
|
|
23
|
+
const params = resolveRoyaltiesReceivableRequestParams({ companyId: 42 });
|
|
24
|
+
assert.deepEqual(params, {
|
|
25
|
+
invoiceType: 'royalties',
|
|
26
|
+
receiver: 42,
|
|
27
|
+
excludeOwnTransfers: 1,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('adds franchisee (payer) filter when provided', () => {
|
|
32
|
+
const params = resolveRoyaltiesReceivableRequestParams({
|
|
33
|
+
companyId: 10,
|
|
34
|
+
franchiseeId: '/people/77',
|
|
35
|
+
});
|
|
36
|
+
assert.equal(params.receiver, 10);
|
|
37
|
+
assert.equal(params.payer, '77');
|
|
38
|
+
assert.equal(params.invoiceType, 'royalties');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('uses a dedicated visible-columns preference key', () => {
|
|
42
|
+
assert.equal(
|
|
43
|
+
resolveRoyaltiesReceivablePreferenceKey(),
|
|
44
|
+
'financialEntries:royaltiesReceivable',
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('defaults date filter to this_month for franchisor view', () => {
|
|
49
|
+
assert.equal(DEFAULT_ROYALTIES_RECEIVABLE_DATE_FILTER.shortcut, 'this_month');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('title falls back to Royalties a receber', () => {
|
|
53
|
+
assert.equal(resolveRoyaltiesReceivableTitle(null), 'Royalties a receber');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('documents franchise flow direction', () => {
|
|
57
|
+
assert.match(ROYALTIES_FLOW_NOTE, /franqueada paga/i);
|
|
58
|
+
assert.match(ROYALTIES_FLOW_NOTE, /franqueadora recebe/i);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const { afterEach, beforeEach, describe, it } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY,
|
|
6
|
+
readGeneralSettingsActiveTab,
|
|
7
|
+
resolveGeneralSettingsActiveTab,
|
|
8
|
+
writeGeneralSettingsActiveTab,
|
|
9
|
+
} = require('../../../../react/pages/settings/generalSettingsActiveTab');
|
|
10
|
+
|
|
11
|
+
describe('generalSettings shared helpers', () => {
|
|
12
|
+
const originalLocalStorage = global.localStorage;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
const store = {};
|
|
16
|
+
Object.defineProperty(global, 'localStorage', {
|
|
17
|
+
configurable: true,
|
|
18
|
+
value: {
|
|
19
|
+
getItem: key =>
|
|
20
|
+
Object.prototype.hasOwnProperty.call(store, key) ? store[key] : null,
|
|
21
|
+
setItem: (key, value) => {
|
|
22
|
+
store[key] = String(value);
|
|
23
|
+
},
|
|
24
|
+
removeItem: key => {
|
|
25
|
+
delete store[key];
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
writable: true,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
if (originalLocalStorage === undefined) {
|
|
34
|
+
delete global.localStorage;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(global, 'localStorage', {
|
|
39
|
+
configurable: true,
|
|
40
|
+
value: originalLocalStorage,
|
|
41
|
+
writable: true,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('prefers the stored tab when it is still available', () => {
|
|
46
|
+
assert.equal(
|
|
47
|
+
resolveGeneralSettingsActiveTab({
|
|
48
|
+
activeTab: 'devices',
|
|
49
|
+
availableTabs: [{key: 'devices'}, {key: 'shop'}],
|
|
50
|
+
storedTab: 'shop',
|
|
51
|
+
fallbackTab: 'devices',
|
|
52
|
+
}),
|
|
53
|
+
'shop',
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('falls back to the active tab when the stored tab is not available', () => {
|
|
58
|
+
assert.equal(
|
|
59
|
+
resolveGeneralSettingsActiveTab({
|
|
60
|
+
activeTab: 'shop',
|
|
61
|
+
availableTabs: [{key: 'devices'}, {key: 'shop'}],
|
|
62
|
+
storedTab: 'logs',
|
|
63
|
+
fallbackTab: 'devices',
|
|
64
|
+
}),
|
|
65
|
+
'shop',
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('falls back to the first available tab when neither stored nor active tab is valid', () => {
|
|
70
|
+
assert.equal(
|
|
71
|
+
resolveGeneralSettingsActiveTab({
|
|
72
|
+
activeTab: 'logs',
|
|
73
|
+
availableTabs: [{key: 'devices'}, {key: 'shop'}],
|
|
74
|
+
storedTab: 'integrations',
|
|
75
|
+
fallbackTab: '',
|
|
76
|
+
}),
|
|
77
|
+
'devices',
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('stores and reads the active tab from localStorage', () => {
|
|
82
|
+
assert.equal(writeGeneralSettingsActiveTab('shop'), true);
|
|
83
|
+
assert.equal(
|
|
84
|
+
global.localStorage.getItem(GENERAL_SETTINGS_ACTIVE_TAB_STORAGE_KEY),
|
|
85
|
+
'shop',
|
|
86
|
+
);
|
|
87
|
+
assert.equal(readGeneralSettingsActiveTab(), 'shop');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('escapes script closing markers in Leaflet popup labels', async () => {
|
|
91
|
+
const {buildLeafletMapHtml} = await import(
|
|
92
|
+
'../../../../react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js'
|
|
93
|
+
);
|
|
94
|
+
const html = buildLeafletMapHtml(
|
|
95
|
+
[{lat: -23.56, lng: -46.65, companyLabel: '</script><script>alert(1)</script>'}],
|
|
96
|
+
{width: 884, height: 360},
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
assert.ok(html.includes('\\u003c/script>'));
|
|
100
|
+
assert.equal(html.includes('</script><script>alert(1)</script>'), false);
|
|
101
|
+
});
|
|
102
|
+
});
|