@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.
Files changed (141) hide show
  1. package/.github/actions/workers/manager/action.yml +147 -0
  2. package/.github/actions/workers/qa/action.yml +44 -0
  3. package/.github/actions/workers/security/action.yml +44 -0
  4. package/.github/actions/workers/technical-documenter/action.yml +51 -0
  5. package/.github/workflows/manager-worker.yml +167 -0
  6. package/.github/workflows/publish-npm.yml +40 -0
  7. package/.github/workflows/pull-request-checks.yml +29 -0
  8. package/.scrutinizer.yml +24 -0
  9. package/AGENTS.md +56 -0
  10. package/FUNDING.yml +1 -0
  11. package/docs/technical/Cliente-Vendedor-Vinculo-e-Permissoes.md +121 -0
  12. package/docs/technical/Income-Statements-Demonstrativo.md +38 -0
  13. package/docs/technical/Oportunidades-Ordenacao-por-Data-de-Retorno.md +134 -0
  14. package/docs/technical/Propostas-Filtro-de-Status.md +147 -0
  15. package/docs/technical/Royalties-a-pagar-Franqueado.md +51 -0
  16. package/docs/technical/Visao-Vendedor-Comissoes.md +58 -0
  17. package/docs/wiki.md +1 -0
  18. package/package.json +43 -0
  19. package/scripts/validate-wiki-pointer.cjs +13 -0
  20. package/src/react/components/AnimatedModal.js +149 -0
  21. package/src/react/components/AnimatedModal.styles.js +21 -0
  22. package/src/react/components/CreateContractModal.js +151 -0
  23. package/src/react/components/CreateContractModal.styles.js +43 -0
  24. package/src/react/hooks/useToastMessage.js +59 -0
  25. package/src/react/index.js +4 -0
  26. package/src/react/pages/ModelTemplatesPage.js +1461 -0
  27. package/src/react/pages/ModelTemplatesPage.styles.js +441 -0
  28. package/src/react/pages/comissions/IncomeStatementDetailsModal.js +102 -0
  29. package/src/react/pages/comissions/IncomeStatementsFilters.js +120 -0
  30. package/src/react/pages/comissions/SellerCommissionsPage.js +368 -0
  31. package/src/react/pages/comissions/SellerCommissionsPage.styles.js +219 -0
  32. package/src/react/pages/comissions/incomeStatementsHelpers.js +233 -0
  33. package/src/react/pages/comissions/index.js +309 -0
  34. package/src/react/pages/comissions/index.styles.js +381 -0
  35. package/src/react/pages/comissions/sellerCommissionsHelpers.js +222 -0
  36. package/src/react/pages/crm/components/CrmHeader.js +117 -0
  37. package/src/react/pages/crm/components/MarketingEventsSection.js +142 -0
  38. package/src/react/pages/crm/components/MarketingEventsSection.styles.js +105 -0
  39. package/src/react/pages/crm/components/OpportunityCard.js +138 -0
  40. package/src/react/pages/crm/components/OpportunityFormModal.js +279 -0
  41. package/src/react/pages/crm/components/OpportunityList.js +113 -0
  42. package/src/react/pages/crm/components/OpportunitySkeletons.js +53 -0
  43. package/src/react/pages/crm/components/ProviderSelectModal.js +166 -0
  44. package/src/react/pages/crm/components/SelectModal.js +178 -0
  45. package/src/react/pages/crm/conversation.js +342 -0
  46. package/src/react/pages/crm/conversation.styles.js +206 -0
  47. package/src/react/pages/crm/hooks/useCrmData.js +494 -0
  48. package/src/react/pages/crm/hooks/useOpportunityForms.js +306 -0
  49. package/src/react/pages/crm/index.js +262 -0
  50. package/src/react/pages/crm/index.styles.js +13 -0
  51. package/src/react/pages/crm/marketingEventsHelpers.js +41 -0
  52. package/src/react/pages/crm/styles/card.styles.js +178 -0
  53. package/src/react/pages/crm/styles/layout.styles.js +184 -0
  54. package/src/react/pages/crm/styles/modal.styles.js +347 -0
  55. package/src/react/pages/home/index.js +559 -0
  56. package/src/react/pages/home/index.styles.js +268 -0
  57. package/src/react/pages/proposals/CreateProposalsModal.js +466 -0
  58. package/src/react/pages/proposals/CreateProposalsModal.styles.js +344 -0
  59. package/src/react/pages/proposals/CreateProposalsPickers.js +187 -0
  60. package/src/react/pages/proposals/CreateProposalsProductSection.js +117 -0
  61. package/src/react/pages/proposals/ProposalCard.js +112 -0
  62. package/src/react/pages/proposals/ProposalDetails.js +263 -0
  63. package/src/react/pages/proposals/ProposalDetails.styles.js +195 -0
  64. package/src/react/pages/proposals/index.js +488 -0
  65. package/src/react/pages/proposals/index.styles.js +248 -0
  66. package/src/react/pages/proposals/proposalListHelpers.js +216 -0
  67. package/src/react/pages/proposals/proposalNavigation.js +26 -0
  68. package/src/react/pages/royalties/ReceivablePage.js +233 -0
  69. package/src/react/pages/royalties/RoyaltiesPayablePage.js +260 -0
  70. package/src/react/pages/royalties/index.js +2 -0
  71. package/src/react/pages/royalties/royaltiesReceivableHelpers.js +68 -0
  72. package/src/react/pages/settings/GeneralSettings.js +317 -0
  73. package/src/react/pages/settings/GeneralSettings.shared.js +490 -0
  74. package/src/react/pages/settings/GeneralSettings.styles.js +746 -0
  75. package/src/react/pages/settings/GeneralSettingsSection.js +57 -0
  76. package/src/react/pages/settings/generalSettingsActiveTab.js +85 -0
  77. package/src/react/pages/settings/sections/CrmSection.js +281 -0
  78. package/src/react/pages/settings/sections/DeviceRuntimeFooterSection.js +128 -0
  79. package/src/react/pages/settings/sections/DisplayPreparationSection.js +155 -0
  80. package/src/react/pages/settings/sections/IntegrationsSection.js +392 -0
  81. package/src/react/pages/settings/sections/LogSection.js +322 -0
  82. package/src/react/pages/settings/sections/LoginSection.js +137 -0
  83. package/src/react/pages/settings/sections/LoyaltyProductPicker.js +230 -0
  84. package/src/react/pages/settings/sections/LoyaltySection.js +451 -0
  85. package/src/react/pages/settings/sections/MaintenanceSection.js +205 -0
  86. package/src/react/pages/settings/sections/MapsSection.js +629 -0
  87. package/src/react/pages/settings/sections/MenuCatalogSection.js +405 -0
  88. package/src/react/pages/settings/sections/OperationsSection.js +303 -0
  89. package/src/react/pages/settings/sections/OrderPaymentSection.js +379 -0
  90. package/src/react/pages/settings/sections/OrderPrintSection.js +308 -0
  91. package/src/react/pages/settings/sections/ShopSection.js +490 -0
  92. package/src/react/pages/settings/sections/shop/FranchiseMapPreview.js +124 -0
  93. package/src/react/pages/settings/sections/shop/ShopDomainCreateForm.js +57 -0
  94. package/src/react/pages/settings/sections/shop/ShopDomainPanel.js +184 -0
  95. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.js +237 -0
  96. package/src/react/pages/settings/sections/shop/ShopDomainShowcasesSection.styles.js +256 -0
  97. package/src/react/pages/settings/sections/shop/ShopDomainTabs.js +61 -0
  98. package/src/react/pages/settings/sections/shop/ShopFranchiseLocatorSection.js +526 -0
  99. package/src/react/pages/settings/sections/shop/ShopLoyaltySection.js +426 -0
  100. package/src/react/pages/settings/sections/shop/ShopSettingsSection.js +10 -0
  101. package/src/react/pages/settings/sections/shop/mapsFranchiseMapHelpers.js +163 -0
  102. package/src/react/pages/settings/sections/shop/shopDomainShowcasesUtils.js +68 -0
  103. package/src/react/pages/settings/sections/shop/shopFranchiseVisibility.js +158 -0
  104. package/src/react/pages/settings/sections/shop/shopSettingsShared.js +427 -0
  105. package/src/react/router/routes.js +135 -0
  106. package/src/react/utils/opportunityDate.js +82 -0
  107. package/src/react/utils/opportunityEditorReferences.js +76 -0
  108. package/src/react/utils/opportunityEmptyState.js +20 -0
  109. package/src/react/utils/opportunityPeople.js +111 -0
  110. package/src/react/utils/opportunityPhone.js +82 -0
  111. package/src/react/utils/opportunityStage.js +30 -0
  112. package/src/react/utils/opportunityStatusFilter.js +54 -0
  113. package/src/react/utils/proposalCreateHelpers.js +61 -0
  114. package/src/react/utils/proposalProductSelection.js +71 -0
  115. package/src/react/utils/royaltiesPayableParams.js +37 -0
  116. package/src/react/utils/translateWithFallback.js +42 -0
  117. package/src/store/crm/index.js +2 -0
  118. package/src/store/model/index.js +104 -0
  119. package/src/tests/browser/crm/create-proposal-product-category-filter.spec.js +149 -0
  120. package/src/tests/browser/crm/crm-index-status-filter.spec.js +263 -0
  121. package/src/tests/browser/crm/crm-opportunity-category-editor.spec.js +269 -0
  122. package/src/tests/browser/crm/royalties-payable.spec.js +122 -0
  123. package/src/tests/browser/crm/royalties-receivable.spec.js +121 -0
  124. package/src/tests/browser/crm/seller-commissions.spec.js +214 -0
  125. package/src/tests/browser/manager/general-settings-maps.spec.js +400 -0
  126. package/src/tests/react/pages/comissions/incomeStatementsHelpers.test.js +181 -0
  127. package/src/tests/react/pages/comissions/sellerCommissionsHelpers.test.js +132 -0
  128. package/src/tests/react/pages/crm/marketingEventsHelpers.test.cjs +53 -0
  129. package/src/tests/react/pages/crm/opportunitySearchParams.test.cjs +44 -0
  130. package/src/tests/react/pages/proposals/navigation.test.js +71 -0
  131. package/src/tests/react/pages/proposals/proposalListHelpers.test.js +42 -0
  132. package/src/tests/react/pages/royalties/royaltiesReceivableHelpers.test.js +60 -0
  133. package/src/tests/react/pages/settings/generalSettings.shared.test.js +102 -0
  134. package/src/tests/react/pages/settings/sections/shop/shopDomainShowcasesUtils.test.js +60 -0
  135. package/src/tests/react/pages/settings/sections/shop/shopFranchiseVisibility.test.js +80 -0
  136. package/src/tests/react/utils/opportunityEditorReferences.test.js +70 -0
  137. package/src/tests/react/utils/opportunityEmptyState.test.js +39 -0
  138. package/src/tests/react/utils/opportunityStatusFilter.test.cjs +81 -0
  139. package/src/tests/react/utils/proposalCreateHelpers.test.js +25 -0
  140. package/src/tests/react/utils/proposalProductSelection.test.js +76 -0
  141. package/src/tests/react/utils/royaltiesPayableParams.test.js +44 -0
@@ -0,0 +1,60 @@
1
+ const {describe, it} = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ buildDomainRows,
6
+ isShopDomain,
7
+ normalizeDomainType,
8
+ SHOP_DOMAIN_TYPE,
9
+ } = require('../../../../../../react/pages/settings/sections/shop/shopDomainShowcasesUtils.js');
10
+
11
+ describe('shopDomainShowcasesUtils', () => {
12
+ it('normalizeDomainType uppercases and trims', () => {
13
+ assert.equal(normalizeDomainType(' shop '), 'SHOP');
14
+ assert.equal(normalizeDomainType('ERP'), 'ERP');
15
+ assert.equal(normalizeDomainType(null), '');
16
+ });
17
+
18
+ it('isShopDomain accepts only SHOP (case-insensitive)', () => {
19
+ assert.equal(isShopDomain({domainType: 'SHOP'}), true);
20
+ assert.equal(isShopDomain({domainType: 'shop'}), true);
21
+ assert.equal(isShopDomain({domain_type: 'SHOP'}), true);
22
+ assert.equal(isShopDomain({domainType: 'ERP'}), false);
23
+ assert.equal(isShopDomain({domainType: 'API'}), false);
24
+ assert.equal(isShopDomain({domainType: 'APP'}), false);
25
+ assert.equal(isShopDomain({}), false);
26
+ });
27
+
28
+ it('buildDomainRows keeps only SHOP domains', () => {
29
+ const domains = [
30
+ {id: 1, domain: 'erp.example.com', domainType: 'ERP'},
31
+ {id: 2, domain: 'shop.example.com', domainType: 'SHOP'},
32
+ {id: 3, domain: 'api.example.com', domainType: 'API'},
33
+ {id: 4, domain: 'loja2.example.com', domainType: 'shop'},
34
+ {id: 5, domain: 'app.example.com', domainType: 'APP'},
35
+ ];
36
+ const showcases = [
37
+ {id: 10, peopleDomain: '/people_domains/2', name: 'Vitrine shop'},
38
+ {id: 11, peopleDomain: '/people_domains/1', name: 'Ignore ERP'},
39
+ ];
40
+
41
+ const rows = buildDomainRows({domains, showcases});
42
+
43
+ assert.equal(rows.length, 2);
44
+ const ids = rows.map(r => r.domainId).sort();
45
+ assert.deepEqual(ids, ['2', '4']);
46
+ const byId = Object.fromEntries(rows.map(r => [r.domainId, r]));
47
+ assert.equal(byId['2'].showcase?.id, 10);
48
+ assert.equal(byId['4'].showcase, null);
49
+ assert.ok(rows.every(r => isShopDomain(r.domain)));
50
+ });
51
+
52
+ it('buildDomainRows handles empty/missing collections', () => {
53
+ assert.deepEqual(buildDomainRows({domains: null, showcases: null}), []);
54
+ assert.deepEqual(buildDomainRows({domains: [], showcases: []}), []);
55
+ });
56
+
57
+ it('SHOP_DOMAIN_TYPE constant is SHOP', () => {
58
+ assert.equal(SHOP_DOMAIN_TYPE, 'SHOP');
59
+ });
60
+ });
@@ -0,0 +1,80 @@
1
+ const {describe, it} = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ parseConfigListValue,
6
+ normalizeVisibleFranchiseIds,
7
+ pruneFranchiseAddressIds,
8
+ resolveSelectedFranchiseCompanies,
9
+ buildFranchiseAddressesById,
10
+ buildFranchiseCompaniesById,
11
+ resolveFranchiseMapAddress,
12
+ } = require('../../../../../../react/pages/settings/sections/shop/shopFranchiseVisibility');
13
+
14
+ describe('shopFranchiseVisibility helpers', () => {
15
+ it('parses single-encoded JSON array config values', () => {
16
+ assert.deepEqual(parseConfigListValue('["10","20"]'), ['10', '20']);
17
+ });
18
+
19
+ it('parses double-encoded JSON array config values (legacy save path)', () => {
20
+ const doubleEncoded = JSON.stringify(JSON.stringify(['10', '20']));
21
+ assert.deepEqual(parseConfigListValue(doubleEncoded), ['10', '20']);
22
+ });
23
+
24
+ it('normalizes entity ids from encoded configs', () => {
25
+ const doubleEncoded = JSON.stringify(JSON.stringify(['/people/15', '22']));
26
+ assert.deepEqual(normalizeVisibleFranchiseIds(doubleEncoded), ['15', '22']);
27
+ });
28
+
29
+ it('prunes address ids that are missing from the loaded directory', () => {
30
+ const pruned = pruneFranchiseAddressIds({
31
+ addressIds: ['1', '2', '3'],
32
+ companyIds: ['9'],
33
+ addressesById: {
34
+ '1': {id: 1, linkedCompany: {id: 9}},
35
+ '3': {id: 3, linkedCompany: {id: 8}},
36
+ },
37
+ });
38
+ assert.deepEqual(pruned, ['1']);
39
+ });
40
+
41
+ it('keeps orphan company ids visible after refresh when directory is incomplete', () => {
42
+ const selected = resolveSelectedFranchiseCompanies({
43
+ companyIds: ['5', '9'],
44
+ companiesById: {
45
+ '5': {id: 5, alias: 'Unidade Centro', shopAddresses: []},
46
+ },
47
+ });
48
+ assert.equal(selected.length, 2);
49
+ assert.equal(selected[0].alias, 'Unidade Centro');
50
+ assert.equal(selected[1].id, '9');
51
+ assert.equal(selected[1].__orphan, true);
52
+ });
53
+
54
+ it('builds address and company maps from directory items', () => {
55
+ const directory = [
56
+ {
57
+ id: 7,
58
+ alias: 'A',
59
+ shopAddresses: [{id: 100}, {id: 101}],
60
+ },
61
+ ];
62
+ const companies = buildFranchiseCompaniesById(directory);
63
+ const addresses = buildFranchiseAddressesById(directory);
64
+ assert.ok(companies['7']);
65
+ assert.equal(addresses['100'].linkedCompany.id, 7);
66
+ assert.equal(addresses['101'].linkedCompany.id, 7);
67
+ });
68
+
69
+ it('uses the first address with coordinates for the map card', () => {
70
+ const addresses = [
71
+ {id: 100, latitude: null, longitude: null},
72
+ {id: 101, latitude: -23.561, longitude: -46.656},
73
+ ];
74
+ const selected = resolveFranchiseMapAddress(
75
+ addresses,
76
+ address => ({latitude: address.latitude, longitude: address.longitude}),
77
+ );
78
+ assert.equal(selected.id, 101);
79
+ });
80
+ });
@@ -0,0 +1,70 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ getOpportunityEditorReferenceValue,
6
+ normalizeOpportunityEditorDraft,
7
+ resolveOpportunityEditorOption,
8
+ } = require('../../../react/utils/opportunityEditorReferences');
9
+
10
+ test('getOpportunityEditorReferenceValue reads object references and raw values', () => {
11
+ assert.equal(
12
+ getOpportunityEditorReferenceValue({ '@id': '/categories/4', id: 9 }),
13
+ '/categories/4',
14
+ );
15
+ assert.equal(getOpportunityEditorReferenceValue({ id: 7 }), '7');
16
+ assert.equal(getOpportunityEditorReferenceValue('/statuses/2'), '/statuses/2');
17
+ });
18
+
19
+ test('resolveOpportunityEditorOption returns the loaded option that matches the reference', () => {
20
+ const options = [
21
+ { '@id': '/categories/4', name: 'Inbound' },
22
+ { '@id': '/categories/8', name: 'Referral' },
23
+ ];
24
+
25
+ assert.deepEqual(
26
+ resolveOpportunityEditorOption('/categories/8', options),
27
+ options[1],
28
+ );
29
+ assert.deepEqual(
30
+ resolveOpportunityEditorOption({ id: 4 }, options),
31
+ options[0],
32
+ );
33
+ });
34
+
35
+ test('resolveOpportunityEditorOption preserves the original value when no expanded option is available', () => {
36
+ assert.equal(
37
+ resolveOpportunityEditorOption('/categories/99', [{ '@id': '/categories/4' }]),
38
+ '/categories/99',
39
+ );
40
+ });
41
+
42
+ test('normalizeOpportunityEditorDraft resolves all relationship references against loaded options', () => {
43
+ const statusOptions = [{ '@id': '/statuses/3', status: 'Open' }];
44
+ const categoryOptions = [{ '@id': '/categories/8', name: 'Referral' }];
45
+ const criticalityOptions = [{ '@id': '/categories/5', name: 'Hot' }];
46
+ const reasonOptions = [{ '@id': '/categories/11', name: 'WhatsApp' }];
47
+
48
+ assert.deepEqual(
49
+ normalizeOpportunityEditorDraft({
50
+ opportunity: {
51
+ id: 13,
52
+ taskStatus: 3,
53
+ category: '/categories/8',
54
+ criticality: { id: 5 },
55
+ reason: '/categories/11',
56
+ },
57
+ statusOptions,
58
+ categoryOptions,
59
+ criticalityOptions,
60
+ reasonOptions,
61
+ }),
62
+ {
63
+ id: 13,
64
+ taskStatus: statusOptions[0],
65
+ category: categoryOptions[0],
66
+ criticality: criticalityOptions[0],
67
+ reason: reasonOptions[0],
68
+ },
69
+ );
70
+ });
@@ -0,0 +1,39 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ getOpportunityEmptyStateMode,
6
+ hasActiveOpportunityFilters,
7
+ } = require('../../../react/utils/opportunityEmptyState');
8
+
9
+ test('returns empty mode when there is no search term or status filter', () => {
10
+ assert.equal(getOpportunityEmptyStateMode({}), 'empty');
11
+ assert.equal(
12
+ hasActiveOpportunityFilters({ searchQuery: ' ', selectedStatusFilterKey: '' }),
13
+ false,
14
+ );
15
+ });
16
+
17
+ test('returns filtered mode when there is a search term', () => {
18
+ assert.equal(
19
+ getOpportunityEmptyStateMode({ searchQuery: ' acme ' }),
20
+ 'filtered',
21
+ );
22
+ });
23
+
24
+ test('returns filtered mode when there is a selected status filter', () => {
25
+ assert.equal(
26
+ getOpportunityEmptyStateMode({ selectedStatusFilterKey: '/statuses/3' }),
27
+ 'filtered',
28
+ );
29
+ });
30
+
31
+ test('treats either filter source as enough to show the filtered empty state', () => {
32
+ assert.equal(
33
+ hasActiveOpportunityFilters({
34
+ searchQuery: 'cliente',
35
+ selectedStatusFilterKey: 'realStatus:closed',
36
+ }),
37
+ true,
38
+ );
39
+ });
@@ -0,0 +1,81 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ getOpportunityStatusFilterKey,
6
+ normalizeOpportunityStatus,
7
+ resolveDefaultOpportunityStatusFilterKey,
8
+ } = require('../../../react/utils/opportunityStatusFilter');
9
+
10
+ test('getOpportunityStatusFilterKey prefers @id when available', () => {
11
+ assert.equal(
12
+ getOpportunityStatusFilterKey({
13
+ '@id': '/statuses/9',
14
+ id: 2,
15
+ realStatus: 'pending',
16
+ }),
17
+ '/statuses/9',
18
+ );
19
+ });
20
+
21
+ test('getOpportunityStatusFilterKey falls back to id and real status', () => {
22
+ assert.equal(getOpportunityStatusFilterKey({ id: 3 }), '/statuses/3');
23
+ assert.equal(
24
+ getOpportunityStatusFilterKey({ realStatus: ' Open ' }),
25
+ 'realStatus:open',
26
+ );
27
+ });
28
+
29
+ test('normalizeOpportunityStatus trims and lowercases known status values', () => {
30
+ assert.equal(normalizeOpportunityStatus({ status: ' Pending ' }), 'pending');
31
+ assert.equal(normalizeOpportunityStatus({ realStatus: 'OPEN' }), 'open');
32
+ });
33
+
34
+ test('resolveDefaultOpportunityStatusFilterKey selects the open status by default', () => {
35
+ assert.equal(
36
+ resolveDefaultOpportunityStatusFilterKey([
37
+ { id: 1, realStatus: 'pending' },
38
+ { id: 2, realStatus: 'Open' },
39
+ { id: 3, realStatus: 'closed' },
40
+ ]),
41
+ '/statuses/2',
42
+ );
43
+ });
44
+
45
+ test('resolveDefaultOpportunityStatusFilterKey preserves the empty state when open is unavailable', () => {
46
+ assert.equal(
47
+ resolveDefaultOpportunityStatusFilterKey([
48
+ { id: 1, realStatus: 'pending' },
49
+ { id: 3, realStatus: 'closed' },
50
+ ]),
51
+ '',
52
+ );
53
+ });
54
+
55
+ const {
56
+ shouldApplyDefaultOpportunityStatusFilter,
57
+ } = require('../../../react/utils/opportunityStatusFilter');
58
+
59
+ test('shouldApplyDefaultOpportunityStatusFilter is true only before first apply when statuses exist', () => {
60
+ assert.equal(
61
+ shouldApplyDefaultOpportunityStatusFilter({
62
+ hasAppliedDefault: false,
63
+ statusItemsLength: 3,
64
+ }),
65
+ true,
66
+ );
67
+ assert.equal(
68
+ shouldApplyDefaultOpportunityStatusFilter({
69
+ hasAppliedDefault: true,
70
+ statusItemsLength: 3,
71
+ }),
72
+ false,
73
+ );
74
+ assert.equal(
75
+ shouldApplyDefaultOpportunityStatusFilter({
76
+ hasAppliedDefault: false,
77
+ statusItemsLength: 0,
78
+ }),
79
+ false,
80
+ );
81
+ });
@@ -0,0 +1,25 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ formatApiError,
6
+ formatProposalStartDate,
7
+ MONTHS,
8
+ } = require('../../../react/utils/proposalCreateHelpers');
9
+
10
+ test('formatApiError handles string, array and object shapes', () => {
11
+ assert.equal(formatApiError('falhou'), 'falhou');
12
+ assert.equal(formatApiError({ message: [{ message: 'a' }, { title: 'b' }] }), 'a\nb');
13
+ assert.equal(formatApiError({ description: 'x' }), 'x');
14
+ assert.equal(formatApiError(null), 'Nao foi possivel criar a proposta.');
15
+ });
16
+
17
+ test('formatProposalStartDate validates calendar dates', () => {
18
+ assert.equal(formatProposalStartDate('2026', '8', '19'), '2026-08-19');
19
+ assert.equal(formatProposalStartDate('2026', '2', '30'), null);
20
+ assert.equal(formatProposalStartDate('26', '8', '19'), null);
21
+ });
22
+
23
+ test('MONTHS has 12 entries', () => {
24
+ assert.equal(MONTHS.length, 12);
25
+ });
@@ -0,0 +1,76 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ filterProductsByModelCategory,
6
+ getProposalModelCategoryId,
7
+ getProposalModelCategoryName,
8
+ keepCompatibleSelectedProducts,
9
+ normalizeCategoryId,
10
+ } = require('../../../react/utils/proposalProductSelection');
11
+
12
+ test('normalizeCategoryId resolves nested category references', () => {
13
+ assert.equal(normalizeCategoryId({ category: { '@id': '/categories/7' } }), '7');
14
+ assert.equal(normalizeCategoryId({ parent: '/categories/9' }), '9');
15
+ assert.equal(normalizeCategoryId('/categories/3'), '3');
16
+ });
17
+
18
+ test('getProposalModelCategoryId reads the selected model category', () => {
19
+ assert.equal(
20
+ getProposalModelCategoryId({ category: { '@id': '/categories/12' } }),
21
+ '12',
22
+ );
23
+ assert.equal(getProposalModelCategoryId({}), null);
24
+ assert.equal(getProposalModelCategoryId(null), null);
25
+ });
26
+
27
+ test('getProposalModelCategoryName returns human label when present', () => {
28
+ assert.equal(
29
+ getProposalModelCategoryName({ category: { name: 'SERVICOS' } }),
30
+ 'SERVICOS',
31
+ );
32
+ assert.equal(getProposalModelCategoryName({ category: {} }), '');
33
+ });
34
+
35
+ test('filterProductsByModelCategory keeps only matching products when a category is selected', () => {
36
+ const products = [
37
+ { '@id': '/products/1', category: { '@id': '/categories/4' } },
38
+ { '@id': '/products/2', category: { '@id': '/categories/7' } },
39
+ { '@id': '/products/3', category: { parent: '/categories/4' } },
40
+ ];
41
+
42
+ assert.deepEqual(
43
+ filterProductsByModelCategory({
44
+ products,
45
+ selectedModelCategoryId: '4',
46
+ }),
47
+ [products[0], products[2]],
48
+ );
49
+ });
50
+
51
+ test('filterProductsByModelCategory preserves the original list when the model has no category', () => {
52
+ const products = [{ '@id': '/products/1' }, { '@id': '/products/2' }];
53
+
54
+ assert.deepEqual(
55
+ filterProductsByModelCategory({
56
+ products,
57
+ selectedModelCategoryId: '',
58
+ }),
59
+ products,
60
+ );
61
+ });
62
+
63
+ test('keepCompatibleSelectedProducts drops selections outside the model category', () => {
64
+ const selectedProducts = [
65
+ { '@id': '/products/1', category: { '@id': '/categories/4' } },
66
+ { '@id': '/products/2', category: { '@id': '/categories/9' } },
67
+ ];
68
+
69
+ assert.deepEqual(
70
+ keepCompatibleSelectedProducts({
71
+ selectedProducts,
72
+ selectedModelCategoryId: '4',
73
+ }),
74
+ [selectedProducts[0]],
75
+ );
76
+ });
@@ -0,0 +1,44 @@
1
+ const { describe, it } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+
4
+ const {
5
+ ROYALTIES_INVOICE_TYPE,
6
+ resolveRoyaltiesPayableRequestParams,
7
+ resolveRoyaltiesPayableVisibleColumnsKey,
8
+ DEFAULT_ROYALTIES_DATE_FILTER,
9
+ } = require('../../../react/utils/royaltiesPayableParams.js');
10
+
11
+ describe('royaltiesPayableParams', () => {
12
+ it('exports royalties invoice type constant', () => {
13
+ assert.equal(ROYALTIES_INVOICE_TYPE, 'royalties');
14
+ });
15
+
16
+ it('builds request params without company (type only)', () => {
17
+ const params = resolveRoyaltiesPayableRequestParams({});
18
+ assert.deepEqual(params, { invoiceType: 'royalties' });
19
+ });
20
+
21
+ it('builds franchisee payables params with payer + exclude own transfers', () => {
22
+ const params = resolveRoyaltiesPayableRequestParams({ companyId: 42 });
23
+ assert.deepEqual(params, {
24
+ invoiceType: 'royalties',
25
+ payer: 42,
26
+ excludeOwnTransfers: 1,
27
+ });
28
+ });
29
+
30
+ it('uses a dedicated visible-columns preference key', () => {
31
+ assert.equal(
32
+ resolveRoyaltiesPayableVisibleColumnsKey(),
33
+ 'financialEntries:royaltiesPayable',
34
+ );
35
+ });
36
+
37
+ it('defaults date filter to this_month for franchisee view', () => {
38
+ assert.equal(DEFAULT_ROYALTIES_DATE_FILTER.shortcut, 'this_month');
39
+ assert.deepEqual(DEFAULT_ROYALTIES_DATE_FILTER.customRange, {
40
+ from: '',
41
+ to: '',
42
+ });
43
+ });
44
+ });