@controleonline/ui-common 1.2.70
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/agents/developer.agent.md +30 -0
- package/.github/agents/devops.agent.md +30 -0
- package/.github/agents/qa.agent.md +30 -0
- package/.github/agents/security.agent.md +30 -0
- package/.github/workflows/npmjs.yml +35 -0
- package/.github/workflows/pull-request-checks.yml +19 -0
- package/.scrutinizer.yml +24 -0
- package/FUNDING.yml +1 -0
- package/package.json +28 -0
- package/src/api/fetch.js +74 -0
- package/src/api/index.js +155 -0
- package/src/api/localDB.js +131 -0
- package/src/api/queue.js +66 -0
- package/src/react/assets/tap.mp3 +0 -0
- package/src/react/components/AddImportModal.js +157 -0
- package/src/react/components/AddImportModal.styles.js +81 -0
- package/src/react/components/BackgroundRuntimeBridge.js +219 -0
- package/src/react/components/BottomNavigationBar.config.js +238 -0
- package/src/react/components/BottomNavigationBar.js +120 -0
- package/src/react/components/BottomNavigationBar.styles.js +110 -0
- package/src/react/components/CategoryForm.js +572 -0
- package/src/react/components/CategoryForm.styles.js +334 -0
- package/src/react/components/ConfirmModal.js +24 -0
- package/src/react/components/ConfirmModal.styles.js +43 -0
- package/src/react/components/ContextHelpButton.js +69 -0
- package/src/react/components/ContextHelpButton.styles.js +62 -0
- package/src/react/components/DefaultProvider.native.js +848 -0
- package/src/react/components/DefaultProvider.styles.js +21 -0
- package/src/react/components/DefaultProvider.web.js +909 -0
- package/src/react/components/DeliveryPushBridge.native.js +314 -0
- package/src/react/components/DeliveryPushBridge.web.js +5 -0
- package/src/react/components/DeviceAlertSoundService.js +499 -0
- package/src/react/components/EntityLogContent.js +909 -0
- package/src/react/components/EntityLogContent.styles.js +400 -0
- package/src/react/components/EventBus.js +12 -0
- package/src/react/components/KioskModeBridge.js +65 -0
- package/src/react/components/LauncherModeBridge.js +47 -0
- package/src/react/components/LinkedOrderProductsTab.js +388 -0
- package/src/react/components/LinkedOrderProductsTab.styles.js +180 -0
- package/src/react/components/ManagerPushBridge.native.js +345 -0
- package/src/react/components/MessageService.js +314 -0
- package/src/react/components/Paywall/Google.js +89 -0
- package/src/react/components/PrintService.js +778 -0
- package/src/react/components/ProductCatalogCacheService.js +45 -0
- package/src/react/components/RemoteCheckoutService.js +292 -0
- package/src/react/components/RuntimeBottomNavigationBar.js +151 -0
- package/src/react/components/RuntimeInfoFooter.js +214 -0
- package/src/react/components/RuntimeInfoFooter.styles.js +56 -0
- package/src/react/components/SystemErrorToast.js +29 -0
- package/src/react/components/SystemErrorToast.styles.js +38 -0
- package/src/react/components/TouchFeedbackProvider.js +65 -0
- package/src/react/components/UnifiedPaymentBar.js +155 -0
- package/src/react/components/UnifiedPaymentBar.styles.js +174 -0
- package/src/react/components/WebsocketListener.native.js +487 -0
- package/src/react/components/WebsocketListener.web.js +102 -0
- package/src/react/components/inputs/IdInput.js +49 -0
- package/src/react/components/inputs/IdInput.styles.js +26 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.js +74 -0
- package/src/react/components/inputs/InvoiceDueDateFilterInput.styles.js +34 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.js +115 -0
- package/src/react/components/inputs/InvoiceDueDateRangeFilterInput.styles.js +39 -0
- package/src/react/components/lists/CategoriesList.js +56 -0
- package/src/react/components/lists/PaymentTypeList.js +55 -0
- package/src/react/components/lists/ReceiverList.js +56 -0
- package/src/react/components/lists/SelectList.styles.js +18 -0
- package/src/react/components/lists/StatusList.js +55 -0
- package/src/react/components/lists/WalletList.js +54 -0
- package/src/react/components/radio/Spotify.js +144 -0
- package/src/react/components/radio/Spotify.styles.js +32 -0
- package/src/react/components/radio/YouTube.js +82 -0
- package/src/react/components/radio/YouTube.styles.js +16 -0
- package/src/react/components/toastConfig.js +16 -0
- package/src/react/config/deviceConfigBootstrap.js +571 -0
- package/src/react/index.js +4 -0
- package/src/react/localStorage.js +30 -0
- package/src/react/pages/EntityLogPage.js +124 -0
- package/src/react/pages/EntityLogPage.styles.js +17 -0
- package/src/react/pages/GenericLogPage.js +760 -0
- package/src/react/pages/GenericLogPage.styles.js +401 -0
- package/src/react/pages/Imports.js +361 -0
- package/src/react/pages/Imports.styles.js +223 -0
- package/src/react/pages/SettingsPage/PaymentTypesByWalletTab.js +462 -0
- package/src/react/pages/SettingsPage/index.js +1171 -0
- package/src/react/pages/SettingsPage/index.styles.js +122 -0
- package/src/react/print/jobs.js +147 -0
- package/src/react/print/providers/local.js +53 -0
- package/src/react/print/providers/remote.js +81 -0
- package/src/react/print/selection.js +296 -0
- package/src/react/print/usePrintButtonController.js +474 -0
- package/src/react/router/routes.js +42 -0
- package/src/react/services/NetworkPrinterService.native.js +391 -0
- package/src/react/services/NetworkPrinterService.web.js +15 -0
- package/src/react/stores/index.js +128 -0
- package/src/react/stores/storeErrorBridge.js +36 -0
- package/src/react/utils/backgroundRuntimeRegistration.js +69 -0
- package/src/react/utils/cashPayment.js +87 -0
- package/src/react/utils/commercialDocumentOrders.js +269 -0
- package/src/react/utils/dateRangeFilter.js +264 -0
- package/src/react/utils/deviceRuntime.js +193 -0
- package/src/react/utils/entityDisplay.js +231 -0
- package/src/react/utils/entityLog.js +649 -0
- package/src/react/utils/fileUrl.js +102 -0
- package/src/react/utils/frontendDebugLog.js +45 -0
- package/src/react/utils/googleMapsConfig.js +49 -0
- package/src/react/utils/importStatus.js +100 -0
- package/src/react/utils/invoiceDueDateMessages.js +14 -0
- package/src/react/utils/invoicePresentation.js +46 -0
- package/src/react/utils/logSettings.js +143 -0
- package/src/react/utils/maintenanceSettings.js +53 -0
- package/src/react/utils/managerOrderNotifications.js +523 -0
- package/src/react/utils/mapNavigation.js +76 -0
- package/src/react/utils/menuCatalogConfig.js +8 -0
- package/src/react/utils/menuCatalogDownload.js +157 -0
- package/src/react/utils/networkCameraDevices.js +175 -0
- package/src/react/utils/networkDeviceProfiles.js +135 -0
- package/src/react/utils/normalizedCatalogDownload.js +157 -0
- package/src/react/utils/notificationNavigation.js +94 -0
- package/src/react/utils/notificationSound.js +42 -0
- package/src/react/utils/paymentDevices.js +397 -0
- package/src/react/utils/paymentGatewayExecution.js +91 -0
- package/src/react/utils/paymentOptions.js +88 -0
- package/src/react/utils/peopleDisplay.js +39 -0
- package/src/react/utils/printerDevices.js +465 -0
- package/src/react/utils/remotePayment.js +61 -0
- package/src/react/utils/runtimeFooter.js +475 -0
- package/src/react/utils/runtimeLanguage.js +50 -0
- package/src/react/utils/runtimeMenu.js +224 -0
- package/src/react/utils/screenMetrics.js +30 -0
- package/src/react/utils/shopConfig.js +294 -0
- package/src/react/utils/shopFranchises.js +114 -0
- package/src/react/utils/socketRuntimePipeline.js +454 -0
- package/src/react/utils/spoolAckTracker.js +77 -0
- package/src/react/utils/storeColumns.js +427 -0
- package/src/react/utils/systemErrorChannel.js +109 -0
- package/src/react/utils/systemErrorMessage.js +67 -0
- package/src/react/utils/toastPresentation.js +53 -0
- package/src/react/utils/websocketSharedRuntime.js +826 -0
- package/src/store/acl/getters.js +4 -0
- package/src/store/acl/index.js +19 -0
- package/src/store/acl/mutation_types.js +4 -0
- package/src/store/acl/mutations.js +17 -0
- package/src/store/address/city.js +22 -0
- package/src/store/categories/category_file/index.js +25 -0
- package/src/store/categories/index.js +93 -0
- package/src/store/configs/customActions.js +131 -0
- package/src/store/configs/index.js +25 -0
- package/src/store/connections/customActions.js +26 -0
- package/src/store/connections/index.js +124 -0
- package/src/store/device/index.js +22 -0
- package/src/store/device_config/customActions.js +190 -0
- package/src/store/device_config/index.js +28 -0
- package/src/store/entity_log/customActions.js +63 -0
- package/src/store/entity_log/index.js +25 -0
- package/src/store/extra/data.js +85 -0
- package/src/store/extra/fields.js +88 -0
- package/src/store/file/actions.js +27 -0
- package/src/store/file/index.js +24 -0
- package/src/store/imports/index.js +88 -0
- package/src/store/print/customActions.js +251 -0
- package/src/store/print/index.js +28 -0
- package/src/store/printer/customActions.js +54 -0
- package/src/store/printer/index.js +26 -0
- package/src/store/runtime_debug/customActions.js +71 -0
- package/src/store/runtime_debug/index.js +30 -0
- package/src/store/status/index.js +65 -0
- package/src/store/timezones/index.js +43 -0
- package/src/store/websocket/customActions.js +24 -0
- package/src/store/websocket/index.js +28 -0
- package/src/tests/react/components/LauncherModeBridge.test.js +93 -0
- package/src/tests/react/config/deviceConfigBootstrap.test.js +337 -0
- package/src/tests/react/print/localPrintProvider.test.js +45 -0
- package/src/tests/react/utils/backgroundRuntimeRegistration.test.js +123 -0
- package/src/tests/react/utils/cashPayment.test.js +41 -0
- package/src/tests/react/utils/dateRangeFilter.test.mjs +29 -0
- package/src/tests/react/utils/entityDisplay.test.js +18 -0
- package/src/tests/react/utils/googleMapsConfig.test.js +32 -0
- package/src/tests/react/utils/importStatus.test.js +85 -0
- package/src/tests/react/utils/invoicePresentation.test.mjs +40 -0
- package/src/tests/react/utils/managerOrderNotifications.test.js +127 -0
- package/src/tests/react/utils/mapNavigation.test.js +58 -0
- package/src/tests/react/utils/notificationNavigation.test.js +39 -0
- package/src/tests/react/utils/notificationSound.test.js +27 -0
- package/src/tests/react/utils/paymentDevices.test.js +88 -0
- package/src/tests/react/utils/runtimeFooter.test.js +429 -0
- package/src/tests/react/utils/runtimeLanguage.test.js +80 -0
- package/src/tests/react/utils/runtimeMenu.test.js +174 -0
- package/src/tests/react/utils/shopFranchises.test.js +82 -0
- package/src/tests/react/utils/socketRuntimePipeline.test.js +124 -0
- package/src/tests/react/utils/spoolAckTracker.test.js +40 -0
- package/src/tests/react/utils/storeErrorBridge.test.js +66 -0
- package/src/tests/react/utils/systemErrorChannel.test.js +58 -0
- package/src/tests/react/utils/systemErrorMessage.test.js +59 -0
- package/src/tests/react/utils/toastPresentation.test.js +75 -0
- package/src/tests/react/utils/translate.test.mjs +396 -0
- package/src/tests/react/utils/websocketSharedRuntime.test.js +245 -0
- package/src/utils/apiEntryPoint.js +31 -0
- package/src/utils/appDomain.js +50 -0
- package/src/utils/config.js +14 -0
- package/src/utils/formatter.js +419 -0
- package/src/utils/integrationConfigs.js +79 -0
- package/src/utils/methods.js +23 -0
- package/src/utils/oauth.js +42 -0
- package/src/utils/translate.js +620 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
|
|
4
|
+
import Translate from '../../../utils/translate.js';
|
|
5
|
+
|
|
6
|
+
const installLocalStorage = (config = {language: 'pt-br'}) => {
|
|
7
|
+
const storage = {};
|
|
8
|
+
|
|
9
|
+
global.localStorage = {
|
|
10
|
+
getItem(key) {
|
|
11
|
+
return Object.prototype.hasOwnProperty.call(storage, key)
|
|
12
|
+
? storage[key]
|
|
13
|
+
: null;
|
|
14
|
+
},
|
|
15
|
+
setItem(key, value) {
|
|
16
|
+
storage[key] = String(value);
|
|
17
|
+
},
|
|
18
|
+
removeItem(key) {
|
|
19
|
+
delete storage[key];
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
localStorage.setItem('config', JSON.stringify(config));
|
|
24
|
+
localStorage.setItem('translates', JSON.stringify({}));
|
|
25
|
+
delete global.refreshTranslationsUI;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const flushAsync = async () => {
|
|
29
|
+
await Promise.resolve();
|
|
30
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
31
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const normalizeLanguage = value =>
|
|
35
|
+
String(value || '')
|
|
36
|
+
.trim()
|
|
37
|
+
.replace(/_/g, '-')
|
|
38
|
+
.toLowerCase();
|
|
39
|
+
|
|
40
|
+
const normalizeId = value =>
|
|
41
|
+
String(value || '')
|
|
42
|
+
.replace(/\D+/g, '')
|
|
43
|
+
.trim();
|
|
44
|
+
|
|
45
|
+
const createPendingTranslateStore = ({getItems, save} = {}) => {
|
|
46
|
+
const store = {
|
|
47
|
+
getters: {
|
|
48
|
+
messages: {},
|
|
49
|
+
pendingMessages: {},
|
|
50
|
+
},
|
|
51
|
+
actions: {},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const translateActions = {
|
|
55
|
+
getItems: getItems || (async () => []),
|
|
56
|
+
save: save || (async payload => payload),
|
|
57
|
+
setMessages: nextMessages => {
|
|
58
|
+
store.getters.messages = nextMessages;
|
|
59
|
+
return nextMessages;
|
|
60
|
+
},
|
|
61
|
+
setPendingMessages: nextMessages => {
|
|
62
|
+
store.getters.pendingMessages = nextMessages;
|
|
63
|
+
return nextMessages;
|
|
64
|
+
},
|
|
65
|
+
queueMissingTranslate: ({language, companyId, store: storeName, type, key, translate}) => {
|
|
66
|
+
const normalizedLanguage = normalizeLanguage(language);
|
|
67
|
+
const normalizedCompanyId = normalizeId(companyId);
|
|
68
|
+
const pendingMessages = store.getters.pendingMessages;
|
|
69
|
+
|
|
70
|
+
if (!pendingMessages[normalizedLanguage]) {
|
|
71
|
+
pendingMessages[normalizedLanguage] = {};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!pendingMessages[normalizedLanguage].companies) {
|
|
75
|
+
pendingMessages[normalizedLanguage].companies = {};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!pendingMessages[normalizedLanguage].companies[normalizedCompanyId]) {
|
|
79
|
+
pendingMessages[normalizedLanguage].companies[normalizedCompanyId] = {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!pendingMessages[normalizedLanguage].companies[normalizedCompanyId][storeName]) {
|
|
83
|
+
pendingMessages[normalizedLanguage].companies[normalizedCompanyId][storeName] = {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
!pendingMessages[normalizedLanguage].companies[normalizedCompanyId][storeName][type]
|
|
88
|
+
) {
|
|
89
|
+
pendingMessages[normalizedLanguage].companies[normalizedCompanyId][storeName][type] =
|
|
90
|
+
{};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pendingMessages[normalizedLanguage].companies[normalizedCompanyId][storeName][type][
|
|
94
|
+
key
|
|
95
|
+
] = translate;
|
|
96
|
+
|
|
97
|
+
return pendingMessages;
|
|
98
|
+
},
|
|
99
|
+
removePendingTranslate: ({language, companyId, store: storeName, type, key}) => {
|
|
100
|
+
const normalizedLanguage = normalizeLanguage(language);
|
|
101
|
+
const normalizedCompanyId = normalizeId(companyId);
|
|
102
|
+
const pendingMessages = store.getters.pendingMessages;
|
|
103
|
+
const languageBucket = pendingMessages[normalizedLanguage];
|
|
104
|
+
const companyBucket = languageBucket?.companies?.[normalizedCompanyId];
|
|
105
|
+
const storeBucket = companyBucket?.[storeName];
|
|
106
|
+
const typeBucket = storeBucket?.[type];
|
|
107
|
+
|
|
108
|
+
if (!typeBucket || !Object.prototype.hasOwnProperty.call(typeBucket, key)) {
|
|
109
|
+
return pendingMessages;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
delete typeBucket[key];
|
|
113
|
+
|
|
114
|
+
if (Object.keys(typeBucket).length === 0) {
|
|
115
|
+
delete storeBucket[type];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (Object.keys(storeBucket).length === 0) {
|
|
119
|
+
delete companyBucket[storeName];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (Object.keys(companyBucket).length === 0) {
|
|
123
|
+
delete languageBucket.companies[normalizedCompanyId];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (Object.keys(languageBucket.companies || {}).length === 0) {
|
|
127
|
+
delete languageBucket.companies;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (Object.keys(languageBucket).length === 0) {
|
|
131
|
+
delete pendingMessages[normalizedLanguage];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return pendingMessages;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
store.actions = translateActions;
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
getters: store.getters,
|
|
142
|
+
actions: store.actions,
|
|
143
|
+
get messages() {
|
|
144
|
+
return store.getters.messages;
|
|
145
|
+
},
|
|
146
|
+
get pendingMessages() {
|
|
147
|
+
return store.getters.pendingMessages;
|
|
148
|
+
},
|
|
149
|
+
translateActions,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
test('prefers the current company translation and falls back to the default company', () => {
|
|
154
|
+
installLocalStorage();
|
|
155
|
+
|
|
156
|
+
const translateStore = createPendingTranslateStore();
|
|
157
|
+
const translate = new Translate(
|
|
158
|
+
[{id: 1}, {id: 5}],
|
|
159
|
+
{id: 1},
|
|
160
|
+
{id: 5},
|
|
161
|
+
['orders'],
|
|
162
|
+
translateStore,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
translate.findMessage('orders', 'label', 'save', 'Salvar', 1);
|
|
166
|
+
translate.findMessage('orders', 'label', 'save', 'Save for ASC', 5);
|
|
167
|
+
translate.persist();
|
|
168
|
+
|
|
169
|
+
assert.equal(translate.t('orders', 'label', 'save'), 'Save for ASC');
|
|
170
|
+
|
|
171
|
+
const fallbackTranslate = new Translate(
|
|
172
|
+
[{id: 1}, {id: 5}],
|
|
173
|
+
{id: 1},
|
|
174
|
+
{id: 9},
|
|
175
|
+
['orders'],
|
|
176
|
+
createPendingTranslateStore(),
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
assert.equal(fallbackTranslate.t('orders', 'label', 'save'), 'Salvar');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('keeps the translate method bound when passed as a standalone function', () => {
|
|
183
|
+
installLocalStorage();
|
|
184
|
+
|
|
185
|
+
const translate = new Translate(
|
|
186
|
+
[{id: 1}],
|
|
187
|
+
{id: 1},
|
|
188
|
+
{id: 1},
|
|
189
|
+
['orders'],
|
|
190
|
+
createPendingTranslateStore(),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
translate.findMessage('orders', 'label', 'save', 'Salvar', 1);
|
|
194
|
+
|
|
195
|
+
const detachedTranslate = translate.t;
|
|
196
|
+
|
|
197
|
+
assert.equal(detachedTranslate('orders', 'label', 'save'), 'Salvar');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('hydrates the cached translations into the translate store on startup', () => {
|
|
201
|
+
installLocalStorage();
|
|
202
|
+
localStorage.setItem('translates', JSON.stringify({
|
|
203
|
+
'pt-br': {
|
|
204
|
+
companies: {
|
|
205
|
+
1: {
|
|
206
|
+
invoice: {
|
|
207
|
+
label: {
|
|
208
|
+
accountsReceivable: 'Contas a receber',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}));
|
|
215
|
+
|
|
216
|
+
const translateStore = createPendingTranslateStore();
|
|
217
|
+
|
|
218
|
+
new Translate(
|
|
219
|
+
[{id: 1}],
|
|
220
|
+
{id: 1},
|
|
221
|
+
{id: 1},
|
|
222
|
+
['invoice'],
|
|
223
|
+
translateStore,
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
assert.equal(
|
|
227
|
+
translateStore.messages['pt-br'].companies[1].invoice.label.accountsReceivable,
|
|
228
|
+
'Contas a receber',
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('posts missing translations once and keeps the fallback until review', async () => {
|
|
233
|
+
installLocalStorage();
|
|
234
|
+
|
|
235
|
+
const discoveryCalls = [];
|
|
236
|
+
const saveCalls = [];
|
|
237
|
+
const translateStore = createPendingTranslateStore({
|
|
238
|
+
getItems: async params => {
|
|
239
|
+
discoveryCalls.push(params);
|
|
240
|
+
return [];
|
|
241
|
+
},
|
|
242
|
+
save: async payload => {
|
|
243
|
+
saveCalls.push(payload);
|
|
244
|
+
return payload;
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
const translate = new Translate(
|
|
248
|
+
[{id: 1}],
|
|
249
|
+
{id: 1},
|
|
250
|
+
{id: 1},
|
|
251
|
+
['contract'],
|
|
252
|
+
translateStore,
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const firstValue = translate.t('contract', 'empty', 'none_registered_title');
|
|
256
|
+
const secondValue = translate.t('contract', 'empty', 'none_registered_title');
|
|
257
|
+
|
|
258
|
+
assert.equal(firstValue, 'None registered title');
|
|
259
|
+
assert.equal(secondValue, 'None registered title');
|
|
260
|
+
|
|
261
|
+
await flushAsync();
|
|
262
|
+
|
|
263
|
+
assert.deepEqual(discoveryCalls, [
|
|
264
|
+
{store: 'contract', 'language.language': 'pt-br', people: '/people/1', page: 1},
|
|
265
|
+
]);
|
|
266
|
+
assert.deepEqual(saveCalls, [{
|
|
267
|
+
people: '/people/1',
|
|
268
|
+
language: 'pt-br',
|
|
269
|
+
store: 'contract',
|
|
270
|
+
type: 'empty',
|
|
271
|
+
key: 'none_registered_title',
|
|
272
|
+
translate: 'None registered title',
|
|
273
|
+
revised: false,
|
|
274
|
+
}]);
|
|
275
|
+
assert.equal(
|
|
276
|
+
translateStore.messages['pt-br'].companies[1].contract.empty.none_registered_title,
|
|
277
|
+
'None registered title',
|
|
278
|
+
);
|
|
279
|
+
assert.deepEqual(translateStore.pendingMessages, {});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test('persists missing translations with the normalized configured language', async () => {
|
|
283
|
+
installLocalStorage({language: 'en_US'});
|
|
284
|
+
|
|
285
|
+
const saveCalls = [];
|
|
286
|
+
const translateStore = createPendingTranslateStore({
|
|
287
|
+
getItems: async () => [],
|
|
288
|
+
save: async payload => {
|
|
289
|
+
saveCalls.push(payload);
|
|
290
|
+
return payload;
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
const translate = new Translate(
|
|
294
|
+
[{id: 1}],
|
|
295
|
+
{id: 1},
|
|
296
|
+
{id: 1},
|
|
297
|
+
['contract'],
|
|
298
|
+
translateStore,
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
translate.t('contract', 'empty', 'none_registered_title');
|
|
302
|
+
|
|
303
|
+
await flushAsync();
|
|
304
|
+
|
|
305
|
+
assert.equal(
|
|
306
|
+
saveCalls[0].language,
|
|
307
|
+
'en-us',
|
|
308
|
+
);
|
|
309
|
+
assert.equal(
|
|
310
|
+
translateStore.messages['en-us'].companies[1].contract.empty.none_registered_title,
|
|
311
|
+
'None registered title',
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('loads each requested store only for the current and default companies', async () => {
|
|
316
|
+
installLocalStorage();
|
|
317
|
+
|
|
318
|
+
const calls = [];
|
|
319
|
+
const translate = new Translate(
|
|
320
|
+
[{id: 1}, {id: 5}, {id: 9}],
|
|
321
|
+
{id: 1},
|
|
322
|
+
{id: 5},
|
|
323
|
+
['orders', 'crm'],
|
|
324
|
+
createPendingTranslateStore({
|
|
325
|
+
getItems: async params => {
|
|
326
|
+
calls.push(params);
|
|
327
|
+
return [];
|
|
328
|
+
},
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
await translate.discoveryAll();
|
|
333
|
+
|
|
334
|
+
assert.deepEqual(calls, [
|
|
335
|
+
{store: 'orders', 'language.language': 'pt-br', people: '/people/1', page: 1},
|
|
336
|
+
{store: 'crm', 'language.language': 'pt-br', people: '/people/1', page: 1},
|
|
337
|
+
{store: 'orders', 'language.language': 'pt-br', people: '/people/5', page: 1},
|
|
338
|
+
{store: 'crm', 'language.language': 'pt-br', people: '/people/5', page: 1},
|
|
339
|
+
]);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('removes stale pending entries once a discovered store returns the real translation', async () => {
|
|
343
|
+
installLocalStorage();
|
|
344
|
+
|
|
345
|
+
const translateStore = createPendingTranslateStore({
|
|
346
|
+
getItems: async params => {
|
|
347
|
+
if (params.page === 1) {
|
|
348
|
+
return [
|
|
349
|
+
{
|
|
350
|
+
store: 'menu',
|
|
351
|
+
type: 'menu',
|
|
352
|
+
key: 'orders',
|
|
353
|
+
translate: 'Pedidos',
|
|
354
|
+
},
|
|
355
|
+
];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return [];
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
let refreshCalls = 0;
|
|
363
|
+
global.refreshTranslationsUI = () => {
|
|
364
|
+
refreshCalls += 1;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const translate = new Translate(
|
|
368
|
+
[{id: 1}],
|
|
369
|
+
{id: 1},
|
|
370
|
+
{id: 1},
|
|
371
|
+
['orders'],
|
|
372
|
+
translateStore,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
translateStore.actions.setPendingMessages({
|
|
376
|
+
'pt-br': {
|
|
377
|
+
companies: {
|
|
378
|
+
1: {
|
|
379
|
+
menu: {
|
|
380
|
+
menu: {
|
|
381
|
+
orders: 'Orders',
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
assert.equal(translate.t('menu', 'menu', 'orders'), 'Orders');
|
|
390
|
+
|
|
391
|
+
await flushAsync();
|
|
392
|
+
|
|
393
|
+
assert.deepEqual(translateStore.pendingMessages, {});
|
|
394
|
+
assert.equal(refreshCalls, 1);
|
|
395
|
+
assert.equal(translate.t('menu', 'menu', 'orders'), 'Pedidos');
|
|
396
|
+
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
const {jest} = require('@jest/globals');
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
compareRuntimePriority,
|
|
5
|
+
createWebsocketSharedRuntime,
|
|
6
|
+
isHigherPriorityRuntime,
|
|
7
|
+
} = require('../../../react/utils/websocketSharedRuntime');
|
|
8
|
+
|
|
9
|
+
const {describe, expect, it, beforeEach, afterEach} = global;
|
|
10
|
+
|
|
11
|
+
const channelRegistry = new Map();
|
|
12
|
+
|
|
13
|
+
class FakeBroadcastChannel {
|
|
14
|
+
constructor(name) {
|
|
15
|
+
this.name = name;
|
|
16
|
+
this.closed = false;
|
|
17
|
+
this.onmessage = null;
|
|
18
|
+
|
|
19
|
+
if (!channelRegistry.has(name)) {
|
|
20
|
+
channelRegistry.set(name, new Set());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
channelRegistry.get(name).add(this);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
postMessage(message) {
|
|
27
|
+
const listeners = channelRegistry.get(this.name) || new Set();
|
|
28
|
+
listeners.forEach(listener => {
|
|
29
|
+
if (listener !== this && !listener.closed && listener.onmessage) {
|
|
30
|
+
listener.onmessage({data: message});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
close() {
|
|
36
|
+
this.closed = true;
|
|
37
|
+
channelRegistry.get(this.name)?.delete(this);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class FakeWebSocket {
|
|
42
|
+
static instances = [];
|
|
43
|
+
static CONNECTING = 0;
|
|
44
|
+
static OPEN = 1;
|
|
45
|
+
static CLOSING = 2;
|
|
46
|
+
static CLOSED = 3;
|
|
47
|
+
|
|
48
|
+
constructor(url) {
|
|
49
|
+
this.url = url;
|
|
50
|
+
this.readyState = FakeWebSocket.CONNECTING;
|
|
51
|
+
this.send = jest.fn();
|
|
52
|
+
FakeWebSocket.instances.push(this);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
close(code = 1000, reason = 'close') {
|
|
56
|
+
this.readyState = FakeWebSocket.CLOSED;
|
|
57
|
+
this.onclose?.({code, reason});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const buildPipeline = () => {
|
|
62
|
+
const state = {
|
|
63
|
+
connected: false,
|
|
64
|
+
identified: false,
|
|
65
|
+
status: 'idle',
|
|
66
|
+
attempts: 0,
|
|
67
|
+
updatedAt: new Date().toISOString(),
|
|
68
|
+
device: 'device-1',
|
|
69
|
+
error: null,
|
|
70
|
+
code: null,
|
|
71
|
+
reason: '',
|
|
72
|
+
ownerRegistrationId: '',
|
|
73
|
+
ownerPackageName: '',
|
|
74
|
+
ownerCompanyId: '',
|
|
75
|
+
lastEventAt: null,
|
|
76
|
+
lastEventCount: 0,
|
|
77
|
+
lastStores: [],
|
|
78
|
+
lastCompanies: [],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
getConnectionState: () => state,
|
|
83
|
+
processPayload: jest.fn(() => state),
|
|
84
|
+
refreshFooter: jest.fn(),
|
|
85
|
+
reset: jest.fn(() => {
|
|
86
|
+
state.connected = false;
|
|
87
|
+
state.identified = false;
|
|
88
|
+
state.status = 'idle';
|
|
89
|
+
state.attempts = 0;
|
|
90
|
+
state.error = null;
|
|
91
|
+
state.code = null;
|
|
92
|
+
state.reason = '';
|
|
93
|
+
state.lastEventAt = null;
|
|
94
|
+
state.lastEventCount = 0;
|
|
95
|
+
state.lastStores = [];
|
|
96
|
+
state.lastCompanies = [];
|
|
97
|
+
return state;
|
|
98
|
+
}),
|
|
99
|
+
updateConnectionState: jest.fn(nextState => {
|
|
100
|
+
Object.assign(state, nextState);
|
|
101
|
+
return state;
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
describe('websocketSharedRuntime', () => {
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
jest.useFakeTimers();
|
|
109
|
+
jest.setSystemTime(1000);
|
|
110
|
+
channelRegistry.clear();
|
|
111
|
+
FakeWebSocket.instances = [];
|
|
112
|
+
global.localStorage?.clear?.();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
afterEach(() => {
|
|
116
|
+
jest.clearAllTimers();
|
|
117
|
+
jest.useRealTimers();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('prefers the oldest runtime and routes payloads through the shared channel', async () => {
|
|
121
|
+
const leaderPipeline = buildPipeline();
|
|
122
|
+
const followerPipeline = buildPipeline();
|
|
123
|
+
|
|
124
|
+
const leaderRuntime = createWebsocketSharedRuntime({
|
|
125
|
+
socketUrl: 'wss://example.test/socket',
|
|
126
|
+
getDeviceId: () => 'device-1',
|
|
127
|
+
pipeline: leaderPipeline,
|
|
128
|
+
BroadcastChannelImpl: FakeBroadcastChannel,
|
|
129
|
+
WebSocketImpl: FakeWebSocket,
|
|
130
|
+
claimDelayMs: 20,
|
|
131
|
+
heartbeatMs: 50,
|
|
132
|
+
leaderStaleMs: 100,
|
|
133
|
+
reconnectBaseMs: 20,
|
|
134
|
+
reconnectMaxMs: 40,
|
|
135
|
+
channelName: 'websocket-runtime-test',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
jest.advanceTimersByTime(1);
|
|
139
|
+
|
|
140
|
+
const followerRuntime = createWebsocketSharedRuntime({
|
|
141
|
+
socketUrl: 'wss://example.test/socket',
|
|
142
|
+
getDeviceId: () => 'device-1',
|
|
143
|
+
pipeline: followerPipeline,
|
|
144
|
+
BroadcastChannelImpl: FakeBroadcastChannel,
|
|
145
|
+
WebSocketImpl: FakeWebSocket,
|
|
146
|
+
claimDelayMs: 20,
|
|
147
|
+
heartbeatMs: 50,
|
|
148
|
+
leaderStaleMs: 100,
|
|
149
|
+
reconnectBaseMs: 20,
|
|
150
|
+
reconnectMaxMs: 40,
|
|
151
|
+
channelName: 'websocket-runtime-test',
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
leaderRuntime.start();
|
|
155
|
+
followerRuntime.start();
|
|
156
|
+
|
|
157
|
+
jest.advanceTimersByTime(25);
|
|
158
|
+
|
|
159
|
+
expect(leaderRuntime.isLeader()).toBe(true);
|
|
160
|
+
expect(followerRuntime.isLeader()).toBe(false);
|
|
161
|
+
expect(FakeWebSocket.instances).toHaveLength(1);
|
|
162
|
+
|
|
163
|
+
const socket = FakeWebSocket.instances[0];
|
|
164
|
+
socket.readyState = FakeWebSocket.OPEN;
|
|
165
|
+
socket.onopen?.({});
|
|
166
|
+
jest.advanceTimersByTime(200);
|
|
167
|
+
|
|
168
|
+
const payload = JSON.stringify([
|
|
169
|
+
{
|
|
170
|
+
store: 'orders',
|
|
171
|
+
company: {id: 'company-1'},
|
|
172
|
+
order: '/orders/100',
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
socket.onmessage?.({data: payload});
|
|
177
|
+
await Promise.resolve();
|
|
178
|
+
|
|
179
|
+
expect(leaderPipeline.processPayload).toHaveBeenCalledWith(payload);
|
|
180
|
+
expect(followerPipeline.processPayload).toHaveBeenCalledWith(payload);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows a follower to take over when the leader stops broadcasting', () => {
|
|
184
|
+
const leaderPipeline = buildPipeline();
|
|
185
|
+
const followerPipeline = buildPipeline();
|
|
186
|
+
|
|
187
|
+
const leaderRuntime = createWebsocketSharedRuntime({
|
|
188
|
+
socketUrl: 'wss://example.test/socket',
|
|
189
|
+
getDeviceId: () => 'device-1',
|
|
190
|
+
pipeline: leaderPipeline,
|
|
191
|
+
BroadcastChannelImpl: FakeBroadcastChannel,
|
|
192
|
+
WebSocketImpl: FakeWebSocket,
|
|
193
|
+
claimDelayMs: 20,
|
|
194
|
+
heartbeatMs: 50,
|
|
195
|
+
leaderStaleMs: 100,
|
|
196
|
+
reconnectBaseMs: 20,
|
|
197
|
+
reconnectMaxMs: 40,
|
|
198
|
+
channelName: 'websocket-runtime-test',
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
jest.advanceTimersByTime(1);
|
|
202
|
+
|
|
203
|
+
const followerRuntime = createWebsocketSharedRuntime({
|
|
204
|
+
socketUrl: 'wss://example.test/socket',
|
|
205
|
+
getDeviceId: () => 'device-1',
|
|
206
|
+
pipeline: followerPipeline,
|
|
207
|
+
BroadcastChannelImpl: FakeBroadcastChannel,
|
|
208
|
+
WebSocketImpl: FakeWebSocket,
|
|
209
|
+
claimDelayMs: 20,
|
|
210
|
+
heartbeatMs: 50,
|
|
211
|
+
leaderStaleMs: 100,
|
|
212
|
+
reconnectBaseMs: 20,
|
|
213
|
+
reconnectMaxMs: 40,
|
|
214
|
+
channelName: 'websocket-runtime-test',
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
leaderRuntime.start();
|
|
218
|
+
followerRuntime.start();
|
|
219
|
+
jest.advanceTimersByTime(25);
|
|
220
|
+
|
|
221
|
+
expect(leaderRuntime.isLeader()).toBe(true);
|
|
222
|
+
expect(followerRuntime.isLeader()).toBe(false);
|
|
223
|
+
|
|
224
|
+
leaderRuntime.stop();
|
|
225
|
+
jest.advanceTimersByTime(25);
|
|
226
|
+
|
|
227
|
+
expect(followerRuntime.isLeader()).toBe(true);
|
|
228
|
+
expect(FakeWebSocket.instances).toHaveLength(2);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('compares runtime priority by start time before instance id', () => {
|
|
232
|
+
expect(
|
|
233
|
+
compareRuntimePriority(
|
|
234
|
+
{instanceId: 'a', startedAt: 1},
|
|
235
|
+
{instanceId: 'b', startedAt: 2},
|
|
236
|
+
),
|
|
237
|
+
).toBeLessThan(0);
|
|
238
|
+
expect(
|
|
239
|
+
isHigherPriorityRuntime(
|
|
240
|
+
{instanceId: 'a', startedAt: 1},
|
|
241
|
+
{instanceId: 'b', startedAt: 2},
|
|
242
|
+
),
|
|
243
|
+
).toBe(true);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Platform} from 'react-native';
|
|
2
|
+
|
|
3
|
+
const ANDROID_EMULATOR_HOST = '10.0.2.2';
|
|
4
|
+
const LOCALHOST_HOSTS = new Set(['localhost', '127.0.0.1', '::1']);
|
|
5
|
+
|
|
6
|
+
const normalizeText = value => String(value || '').trim();
|
|
7
|
+
|
|
8
|
+
const replaceLocalhostHost = value => {
|
|
9
|
+
const normalizedValue = normalizeText(value);
|
|
10
|
+
if (!normalizedValue) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const parsed = new URL(normalizedValue);
|
|
16
|
+
if (
|
|
17
|
+
Platform.OS === 'android' &&
|
|
18
|
+
LOCALHOST_HOSTS.has(String(parsed.hostname || '').trim().toLowerCase())
|
|
19
|
+
) {
|
|
20
|
+
parsed.hostname = ANDROID_EMULATOR_HOST;
|
|
21
|
+
return parsed.toString();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return normalizedValue;
|
|
25
|
+
} catch {
|
|
26
|
+
return normalizedValue;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const resolveApiEntryPoint = value =>
|
|
31
|
+
replaceLocalhostHost(value).replace(/\/$/, '');
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const toRawString = value => String(value || '').trim();
|
|
2
|
+
|
|
3
|
+
const tryParseHost = value => {
|
|
4
|
+
const raw = toRawString(value);
|
|
5
|
+
if (!raw) return '';
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const withProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(raw)
|
|
9
|
+
? raw
|
|
10
|
+
: `https://${raw}`;
|
|
11
|
+
const parsed = new URL(withProtocol);
|
|
12
|
+
return parsed.host || '';
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return raw
|
|
15
|
+
.replace(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//, '')
|
|
16
|
+
.replace(/\/.*$/, '')
|
|
17
|
+
.trim();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const resolveRuntimeHost = () => {
|
|
22
|
+
if (typeof location === 'undefined') return '';
|
|
23
|
+
return toRawString(location?.host || '');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const resolveAppDomain = configuredDomain => {
|
|
27
|
+
const configuredHost = tryParseHost(configuredDomain);
|
|
28
|
+
if (configuredHost) return configuredHost;
|
|
29
|
+
return tryParseHost(resolveRuntimeHost());
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const resolveCompanyDomain = (company, fallbackDomain = '') => {
|
|
33
|
+
const candidates = [
|
|
34
|
+
company?.domain,
|
|
35
|
+
company?.host,
|
|
36
|
+
company?.hostname,
|
|
37
|
+
company?.website,
|
|
38
|
+
company?.site,
|
|
39
|
+
company?.url,
|
|
40
|
+
company?.extraData?.domain,
|
|
41
|
+
company?.extraData?.hostname,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
for (const value of candidates) {
|
|
45
|
+
const normalized = tryParseHost(value);
|
|
46
|
+
if (normalized) return normalized;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return tryParseHost(fallbackDomain);
|
|
50
|
+
};
|