@controleonline/ui-common 1.2.130 → 1.2.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,14 @@
1
1
  {
2
- "version": "1.2.130",
2
+ "version": "1.2.132",
3
3
  "rc": 1,
4
- "branch": "rc/1.2.130-rc.1",
5
- "baseMaster": "1772cd9c63a2bea067e6ed3b0fbfa81daac97b56",
4
+ "branch": "rc/1.2.132-rc.1",
5
+ "baseMaster": "6ca50f9716ba2ff370dce15669b68777271b7e99",
6
+ "baseTag": "v1.2.131",
6
7
  "tasks": [
7
- 153
8
+ 98
8
9
  ],
9
10
  "frozen": true,
10
11
  "repositories": {
11
- "ControleOnline/ui-common": "4842e5b48784eb68d8dc2bffd40ac38d8cd20320"
12
+ "ControleOnline/ui-common": "07ca4291f5553015f8cc898f015b4f3df68057cc"
12
13
  }
13
14
  }
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@controleonline/ui-common",
3
- "version": "1.2.130",
3
+ "version": "1.2.132",
4
4
  "author": "ControleOnline",
5
5
  "description": "ControleOnline Common Quasar UI Component",
6
6
  "license": "MIT",
7
7
  "main": "src/react/index.js",
8
8
  "scripts": {
9
- "test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary",
9
+ "test": "npm run test:receita-federal && npm run test:imports-status && npm run test:runtime-language && npm run test:runtime-footer && npm run test:runtime-footer-marquee && npm run test:invoice-presentation && npm run test:system-error-message && npm run test:bottom-navigation-toolbar && npm run test:copy-device-configs && npm run test:print-routing && npm run test:device-detail-dependencies && npm run test:runtime-zoom && npm run test:cash-register-summary && npm run test:linked-order-payload && npm run test:document-file-content",
10
10
  "test:receita-federal": "node --test src/tests/react/pages/receitaFederalIntegrationContract.test.mjs",
11
11
  "test:imports-status": "mkdir -p node_modules/@controleonline && rm -rf node_modules/@controleonline/ui-common && ln -s ../.. node_modules/@controleonline/ui-common && node --test src/tests/react/utils/importStatus.test.js",
12
12
  "test:cash-register-summary": "node --test src/tests/react/utils/cashRegisterSummary.test.js",
13
+ "test:linked-order-payload": "node --test src/tests/react/utils/linkedOrderPayload.test.js",
14
+ "test:document-file-content": "node --test src/tests/react/utils/documentFileContent.test.js",
13
15
  "test:runtime-language": "node --test src/tests/react/utils/runtimeLanguage.test.js",
14
16
  "test:runtime-footer": "node --test src/tests/react/utils/runtimeFooter.test.js src/tests/react/utils/runtimeFooterText.test.js",
15
17
  "test:invoice-presentation": "node --test src/tests/react/utils/invoicePresentation.test.mjs",
@@ -62,6 +62,8 @@ const LinkedOrderProductsTab = ({
62
62
  emptyTitle = 'Nenhum produto adicionado.',
63
63
  emptySubtitle = 'Você pode vincular produtos a este documento quando precisar.',
64
64
  searchPlaceholder = 'Buscar produto para adicionar...',
65
+ // Called after products change so the parent can regenerate/reload the document.
66
+ onProductsChanged,
65
67
  }) => {
66
68
  const peopleStore = useStore('people');
67
69
  const { currentCompany } = peopleStore.getters;
@@ -82,6 +84,9 @@ const LinkedOrderProductsTab = ({
82
84
  );
83
85
 
84
86
  const canEditProducts = !!canEdit && !!contract?.['@id'] && (!order || isOpenCommercialOrder(order));
87
+ // The backend only accepts products linked to the contract model category
88
+ // (ProposalProductCategoryGuard), so the search must use the same filter.
89
+ const modelCategoryId = normalizeEntityId(contract?.contractModel?.category);
85
90
 
86
91
  const loadLinkedOrderProducts = useCallback(async () => {
87
92
  if (!contract?.['@id']) {
@@ -128,6 +133,7 @@ const LinkedOrderProductsTab = ({
128
133
  const results = await searchCompanyProducts({
129
134
  companyId: currentCompany.id,
130
135
  query: trimmedQuery,
136
+ categoryId: modelCategoryId,
131
137
  });
132
138
 
133
139
  if (!cancelled) {
@@ -148,7 +154,7 @@ const LinkedOrderProductsTab = ({
148
154
  cancelled = true;
149
155
  clearTimeout(timeoutId);
150
156
  };
151
- }, [canEditProducts, currentCompany?.id, searchQuery]);
157
+ }, [canEditProducts, currentCompany?.id, modelCategoryId, searchQuery]);
152
158
 
153
159
  const ensureCurrentOrder = useCallback(async () => {
154
160
  if (order) {
@@ -161,7 +167,6 @@ const LinkedOrderProductsTab = ({
161
167
  client: contract?.client,
162
168
  payer: contract?.client,
163
169
  app: 'CRM',
164
- orderType: 'sale',
165
170
  });
166
171
 
167
172
  setOrder(createdOrder);
@@ -188,12 +193,13 @@ const LinkedOrderProductsTab = ({
188
193
  setSearchQuery('');
189
194
  setSearchResults([]);
190
195
  await loadLinkedOrderProducts();
196
+ await onProductsChanged?.();
191
197
  } catch (error) {
192
198
  showError?.(formatApiError(error));
193
199
  } finally {
194
200
  setAddingProductId(null);
195
201
  }
196
- }, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, showError]);
202
+ }, [addingProductId, canEditProducts, ensureCurrentOrder, loadLinkedOrderProducts, onProductsChanged, showError]);
197
203
 
198
204
  const handleChangeQuantity = useCallback(async (orderProduct, nextQuantity) => {
199
205
  if (updatingOrderProductId) {
@@ -217,12 +223,13 @@ const LinkedOrderProductsTab = ({
217
223
  }
218
224
 
219
225
  await loadLinkedOrderProducts();
226
+ await onProductsChanged?.();
220
227
  } catch (error) {
221
228
  showError?.(formatApiError(error));
222
229
  } finally {
223
230
  setUpdatingOrderProductId(null);
224
231
  }
225
- }, [loadLinkedOrderProducts, showError, updatingOrderProductId]);
232
+ }, [loadLinkedOrderProducts, onProductsChanged, showError, updatingOrderProductId]);
226
233
 
227
234
  const visibleSearchResults = useMemo(() => {
228
235
  const existingProductIds = new Set(
@@ -2,6 +2,7 @@ const React = require('react');
2
2
  const {useEffect, useRef, useState} = React;
3
3
  const RN = require('react-native');
4
4
  const Animated = RN.Animated;
5
+ const Easing = RN.Easing;
5
6
  const Text = RN.Text;
6
7
  const View = RN.View;
7
8
  const Platform = RN.Platform || {OS: 'native'};
@@ -12,10 +13,22 @@ const GAP_PX = 32;
12
13
  const MS_PER_PX = 28;
13
14
  const MIN_DURATION_MS = 4000;
14
15
  const HOLD_MS = 1200;
16
+ // Continuous ticker (right -> left): constant, readable speed.
17
+ const TICKER_MS_PER_PX = 20;
18
+ const TICKER_MIN_DURATION_MS = 3000;
19
+ // Native Text is measured with the parent width as the maximum, so a row as
20
+ // narrow as the container would truncate the text (and the measured content
21
+ // width). The ticker row is therefore much wider than any footer; the
22
+ // container clips it (overflow: hidden).
23
+ const TICKER_ROW_WIDTH_PX = 20000;
15
24
 
16
25
  /**
17
26
  * Single-line footer text. When content overflows the available width,
18
27
  * scrolls horizontally in a continuous loop. Short text stays static.
28
+ *
29
+ * `continuous` turns it into a ticker (marquee): the text ALWAYS scrolls from
30
+ * right to left in a seamless loop (repeated copies fill the width), on web
31
+ * (CSS keyframes) and native (Animated loop with the native driver).
19
32
  * On web, avoids Animated opacity/transform issues that hid the label.
20
33
  * RN Web also needs intrinsic sizing because Text can collapse to width 0
21
34
  * inside a flex row.
@@ -28,6 +41,7 @@ const RuntimeFooterMarqueeText = props => {
28
41
  const text = props && props.text;
29
42
  const color = props && props.color;
30
43
  const style = props && props.style;
44
+ const continuous = !!(props && props.continuous);
31
45
  const testID =
32
46
  (props && props.testID) || 'runtime-footer-marquee-text';
33
47
 
@@ -36,8 +50,9 @@ const RuntimeFooterMarqueeText = props => {
36
50
  const translateX = useRef(new Animated.Value(0)).current;
37
51
  const animationRef = useRef(null);
38
52
 
39
- const shouldMarquee =
40
- !IS_WEB && containerWidth > 0 && contentWidth > containerWidth + 2;
53
+ const shouldMarquee = continuous
54
+ ? containerWidth > 0 && contentWidth > 0
55
+ : !IS_WEB && containerWidth > 0 && contentWidth > containerWidth + 2;
41
56
 
42
57
  useEffect(() => {
43
58
  if (animationRef.current) {
@@ -47,18 +62,22 @@ const RuntimeFooterMarqueeText = props => {
47
62
  translateX.stopAnimation();
48
63
  translateX.setValue(0);
49
64
 
50
- if (!shouldMarquee) {
65
+ // On web the continuous ticker uses CSS keyframes (see render below).
66
+ if (!shouldMarquee || (continuous && IS_WEB)) {
51
67
  return undefined;
52
68
  }
53
69
 
54
70
  const distance = contentWidth + GAP_PX;
55
- const duration = Math.max(Math.round(distance * MS_PER_PX), MIN_DURATION_MS);
71
+ const duration = continuous
72
+ ? Math.max(Math.round(distance * TICKER_MS_PER_PX), TICKER_MIN_DURATION_MS)
73
+ : Math.max(Math.round(distance * MS_PER_PX), MIN_DURATION_MS);
56
74
  const loop = Animated.loop(
57
75
  Animated.sequence([
58
- Animated.delay(HOLD_MS),
76
+ Animated.delay(continuous ? 0 : HOLD_MS),
59
77
  Animated.timing(translateX, {
60
78
  toValue: -distance,
61
79
  duration: duration,
80
+ easing: continuous && Easing ? Easing.linear : undefined,
62
81
  useNativeDriver: USE_NATIVE_DRIVER,
63
82
  }),
64
83
  Animated.timing(translateX, {
@@ -75,7 +94,7 @@ const RuntimeFooterMarqueeText = props => {
75
94
  animationRef.current = null;
76
95
  translateX.stopAnimation();
77
96
  };
78
- }, [shouldMarquee, contentWidth, containerWidth, text, translateX]);
97
+ }, [shouldMarquee, continuous, contentWidth, containerWidth, text, translateX]);
79
98
 
80
99
  const handleContainerLayout = event => {
81
100
  const nextWidth = Math.round(
@@ -128,6 +147,88 @@ const RuntimeFooterMarqueeText = props => {
128
147
 
129
148
  textStyle.push(shouldMarquee ? {textAlign: 'left'} : {textAlign: 'center'});
130
149
 
150
+ if (continuous) {
151
+ // Enough copies so the row is always wider than the container + one cycle:
152
+ // the loop restarts (translateX 0) with no visible gap.
153
+ const distance = contentWidth + GAP_PX;
154
+ const copies = shouldMarquee
155
+ ? Math.max(2, Math.ceil(containerWidth / distance) + 1)
156
+ : 1;
157
+ const durationMs = Math.max(
158
+ Math.round(distance * TICKER_MS_PER_PX),
159
+ TICKER_MIN_DURATION_MS,
160
+ );
161
+
162
+ const copyNodes = [];
163
+ for (let index = 0; index < copies; index += 1) {
164
+ copyNodes.push(
165
+ React.createElement(
166
+ Text,
167
+ {
168
+ key: 'ticker-copy-' + index,
169
+ numberOfLines: 1,
170
+ ellipsizeMode: 'clip',
171
+ accessible: index === 0,
172
+ importantForAccessibility: index === 0 ? 'auto' : 'no',
173
+ onLayout: index === 0 ? handleTextLayout : undefined,
174
+ testID: index === 0 ? undefined : 'runtime-footer-ticker-copy',
175
+ style: textStyle.concat([
176
+ {textAlign: 'left', marginRight: GAP_PX},
177
+ IS_WEB ? {whiteSpace: 'nowrap'} : null,
178
+ ]),
179
+ },
180
+ text,
181
+ ),
182
+ );
183
+ }
184
+
185
+ const rowStyle = {
186
+ flexDirection: 'row',
187
+ flexWrap: 'nowrap',
188
+ alignItems: 'center',
189
+ alignSelf: 'flex-start',
190
+ opacity: 1,
191
+ };
192
+ if (!IS_WEB) {
193
+ rowStyle.width = TICKER_ROW_WIDTH_PX;
194
+ }
195
+ if (IS_WEB && shouldMarquee) {
196
+ rowStyle.animationKeyframes = [
197
+ {
198
+ '0%': {transform: [{translateX: 0}]},
199
+ '100%': {transform: [{translateX: -distance}]},
200
+ },
201
+ ];
202
+ rowStyle.animationDuration = durationMs + 'ms';
203
+ rowStyle.animationIterationCount = 'infinite';
204
+ rowStyle.animationTimingFunction = 'linear';
205
+ }
206
+
207
+ return React.createElement(
208
+ View,
209
+ {
210
+ testID: testID,
211
+ style: {
212
+ flex: 1,
213
+ overflow: 'hidden',
214
+ justifyContent: 'center',
215
+ opacity: 1,
216
+ },
217
+ onLayout: handleContainerLayout,
218
+ },
219
+ React.createElement(
220
+ IS_WEB ? View : Animated.View,
221
+ {
222
+ testID: 'runtime-footer-ticker-row',
223
+ style: IS_WEB
224
+ ? rowStyle
225
+ : [rowStyle, {transform: [{translateX: translateX}]}],
226
+ },
227
+ copyNodes,
228
+ ),
229
+ );
230
+ }
231
+
131
232
  const content = React.createElement(
132
233
  Text,
133
234
  {
@@ -1,4 +1,4 @@
1
- import React, {useEffect, useMemo, useState} from 'react';
1
+ import React, {useMemo} from 'react';
2
2
  import {
3
3
  ActivityIndicator,
4
4
  Platform,
@@ -18,14 +18,13 @@ import {
18
18
  getRuntimeFooterDebugInfo,
19
19
  getRuntimeFooterPrimaryText,
20
20
  getRuntimeFooterRotationEntries,
21
+ getRuntimeFooterTickerText,
21
22
  getRuntimeFooterText,
22
- getRuntimeFooterTextLines,
23
23
  } from '@controleonline/ui-common/src/react/utils/runtimeFooter';
24
24
  import styles from './RuntimeInfoFooter.styles';
25
25
  import RuntimeFooterMarqueeText from './RuntimeFooterMarqueeText';
26
26
  import resolveHomeFooterSpacing from './RuntimeInfoFooter.home.spacing';
27
27
 
28
- const ROTATION_INTERVAL_MS = 4000;
29
28
  const COMPACT_BREAKPOINT = 720;
30
29
  const MAX_INLINE_TEXT_LENGTH = 84;
31
30
  const FALLBACK_TEXT_COLOR = '#0f172a';
@@ -72,7 +71,6 @@ const RuntimeInfoFooter = ({
72
71
  }) => {
73
72
  const {width} = useWindowDimensions();
74
73
  const insets = useSafeAreaInsets();
75
- const [activeIndex, setActiveIndex] = useState(0);
76
74
  const allStores = useStores(state => state);
77
75
  const deviceConfigStore = useStore('device_config');
78
76
  const runtimeDebugStore = useStore('runtime_debug');
@@ -119,10 +117,6 @@ const RuntimeInfoFooter = ({
119
117
  deviceConfigItem?.configs,
120
118
  storeMainCompany?.configs,
121
119
  ]);
122
- const footerTextLines = useMemo(
123
- () => getRuntimeFooterTextLines(companyFooterText),
124
- [companyFooterText],
125
- );
126
120
  const deviceConfigs = useMemo(
127
121
  () => parseConfigsObject(deviceConfigItem?.configs),
128
122
  [deviceConfigItem?.configs],
@@ -143,14 +137,13 @@ const RuntimeInfoFooter = ({
143
137
  }),
144
138
  [companyFooterText, primaryText],
145
139
  );
140
+ // Ticker: the text written by the user (company footer) comes first, then the
141
+ // system text (e.g. "web • MANAGER (ip) / v1.10.x"). Both scroll together,
142
+ // right to left, in a continuous loop (no more alternating between them).
146
143
  const inlineText = useMemo(
147
- () => [primaryText, ...footerTextLines].filter(Boolean).join(' • '),
148
- [footerTextLines, primaryText],
144
+ () => getRuntimeFooterTickerText({companyFooterText, primaryText}),
145
+ [companyFooterText, primaryText],
149
146
  );
150
- // Always rotate when there is more than one entry (e.g. 1 footer line + primaryText).
151
- // Do not fall back to concatenated inlineText in that case.
152
- const shouldRotate =
153
- !showDebugInfo && rotationEntries.length > 1;
154
147
  const footerEntries = useMemo(
155
148
  () =>
156
149
  Object.values(runtimeDebugSummary?.entries || {})
@@ -222,44 +215,12 @@ const RuntimeInfoFooter = ({
222
215
  ? 0
223
216
  : Math.max(Number(insets.bottom) || 0, 16);
224
217
 
225
- useEffect(() => {
226
- if (!shouldRotate || rotationEntries.length <= 1) {
227
- setActiveIndex(0);
228
- return undefined;
229
- }
230
-
231
- let timeoutId;
232
- let cancelled = false;
233
-
234
- const scheduleTransition = () => {
235
- timeoutId = setTimeout(() => {
236
- if (cancelled) {
237
- return;
238
- }
239
- setActiveIndex(current => (current + 1) % rotationEntries.length);
240
- scheduleTransition();
241
- }, ROTATION_INTERVAL_MS);
242
- };
243
-
244
- scheduleTransition();
245
-
246
- return () => {
247
- cancelled = true;
248
- if (timeoutId) {
249
- clearTimeout(timeoutId);
250
- }
251
- };
252
- }, [rotationEntries.length, shouldRotate]);
253
-
254
218
  if (rotationEntries.length === 0 && !showDebugInfo) {
255
219
  return null;
256
220
  }
257
221
 
258
- const displayedText = (
259
- shouldRotate
260
- ? rotationEntries[activeIndex]
261
- : inlineText
262
- ) || primaryText || formatRuntimeFooterIdentifier(device?.id) || '';
222
+ const displayedText =
223
+ inlineText || primaryText || formatRuntimeFooterIdentifier(device?.id) || '';
263
224
  const backgroundColor = colors?.footerBackground;
264
225
  const homeSpacing = resolveHomeFooterSpacing(appearance, Platform.OS, insets.bottom);
265
226
  const borderColor = colors?.footerBorder;
@@ -305,6 +266,7 @@ const RuntimeInfoFooter = ({
305
266
  }
306
267
  color={textColor}
307
268
  opacity={1}
269
+ continuous
308
270
  style={styles.primaryText}
309
271
  testID="runtime-footer-primary-text"
310
272
  />
@@ -1,4 +1,8 @@
1
1
  import { api } from '@controleonline/ui-common/src/api';
2
+ import {
3
+ LINKED_ORDER_TYPE,
4
+ buildLinkedOrderPayload,
5
+ } from '@controleonline/ui-common/src/react/utils/linkedOrderPayload';
2
6
 
3
7
  const normalizeStatusKey = value => String(value || '').trim().toLowerCase();
4
8
 
@@ -158,30 +162,19 @@ export const createLinkedOrder = async ({
158
162
  client,
159
163
  payer,
160
164
  app = 'CRM',
161
- orderType = 'sale',
165
+ orderType = LINKED_ORDER_TYPE,
162
166
  fallbackStatusId = null,
163
167
  }) => {
164
168
  const status = await resolveOpenOrderStatusIri(fallbackStatusId);
165
- const payload = {
169
+ const payload = buildLinkedOrderPayload({
166
170
  app,
167
171
  orderType,
168
- contract: toEntityIri(contractRef, 'contracts'),
169
- provider: toEntityIri(provider, 'people'),
170
- };
171
-
172
- if (status) {
173
- payload.status = status;
174
- }
175
-
176
- const clientIri = toEntityIri(client, 'people');
177
- if (clientIri) {
178
- payload.client = clientIri;
179
- }
180
-
181
- const payerIri = toEntityIri(payer || client, 'people');
182
- if (payerIri) {
183
- payload.payer = payerIri;
184
- }
172
+ contractIri: toEntityIri(contractRef, 'contracts'),
173
+ providerIri: toEntityIri(provider, 'people'),
174
+ statusIri: status,
175
+ clientIri: toEntityIri(client, 'people'),
176
+ payerIri: toEntityIri(payer, 'people'),
177
+ });
185
178
 
186
179
  return api.fetch('orders', {
187
180
  method: 'POST',
@@ -195,7 +188,7 @@ export const ensureLinkedOrder = async ({
195
188
  client,
196
189
  payer,
197
190
  app = 'CRM',
198
- orderType = 'sale',
191
+ orderType = LINKED_ORDER_TYPE,
199
192
  fallbackStatusId = null,
200
193
  }) => {
201
194
  const existingOrder = await fetchLinkedOrder(contractRef);
@@ -0,0 +1,55 @@
1
+ // File.content comes base64 encoded from the API (File::getContent()). Contract
2
+ // and proposal documents are HTML generated from Twig models, while signed
3
+ // documents may be PDFs. Decode before deciding how to render.
4
+
5
+ const BASE64_PATTERN = /^[A-Za-z0-9+/=\r\n]+$/;
6
+
7
+ const decodeBase64Utf8 = value => {
8
+ const binary =
9
+ typeof globalThis.atob === 'function'
10
+ ? globalThis.atob(value)
11
+ : typeof Buffer !== 'undefined'
12
+ ? Buffer.from(value, 'base64').toString('binary')
13
+ : null;
14
+ if (binary === null) {
15
+ return null;
16
+ }
17
+
18
+ const percentEncoded = Array.from(binary)
19
+ .map(char => `%${char.charCodeAt(0).toString(16).padStart(2, '0')}`)
20
+ .join('');
21
+ return decodeURIComponent(percentEncoded);
22
+ };
23
+
24
+ const looksLikeHtml = value => String(value || '').trim().startsWith('<');
25
+
26
+ const resolveDocumentFileContent = content => {
27
+ const raw = String(content || '');
28
+ if (!raw.trim()) {
29
+ return { kind: 'empty', content: '' };
30
+ }
31
+
32
+ if (looksLikeHtml(raw)) {
33
+ return { kind: 'html', content: raw };
34
+ }
35
+
36
+ const compact = raw.trim();
37
+ if (BASE64_PATTERN.test(compact)) {
38
+ try {
39
+ const decoded = decodeBase64Utf8(compact.replace(/[\r\n]/g, ''));
40
+ if (decoded !== null && looksLikeHtml(decoded)) {
41
+ return { kind: 'html', content: decoded };
42
+ }
43
+ } catch {
44
+ // Not UTF-8 text: binary payload such as a PDF.
45
+ }
46
+
47
+ return { kind: 'pdf', content: compact };
48
+ }
49
+
50
+ return { kind: 'text', content: raw };
51
+ };
52
+
53
+ module.exports = {
54
+ resolveDocumentFileContent,
55
+ };
@@ -0,0 +1,43 @@
1
+ // Orders linked to proposals/contracts are commercial drafts: the backend only
2
+ // accepts add/remove of products while the order is a `cart`
3
+ // (api-platform-orders OrderProductServiceHelpers::isMutableCartOrder) and never
4
+ // lets a `sale` go back to `cart`. They must start as `cart` and be promoted to
5
+ // `sale` (PUT /orders/{id} with orderType=sale) only when the deal is confirmed.
6
+ const LINKED_ORDER_TYPE = 'cart';
7
+
8
+ const buildLinkedOrderPayload = ({
9
+ app = 'CRM',
10
+ orderType = LINKED_ORDER_TYPE,
11
+ contractIri = null,
12
+ providerIri = null,
13
+ statusIri = null,
14
+ clientIri = null,
15
+ payerIri = null,
16
+ } = {}) => {
17
+ const payload = {
18
+ app,
19
+ orderType: orderType || LINKED_ORDER_TYPE,
20
+ contract: contractIri,
21
+ provider: providerIri,
22
+ };
23
+
24
+ if (statusIri) {
25
+ payload.status = statusIri;
26
+ }
27
+
28
+ if (clientIri) {
29
+ payload.client = clientIri;
30
+ }
31
+
32
+ const resolvedPayerIri = payerIri || clientIri;
33
+ if (resolvedPayerIri) {
34
+ payload.payer = resolvedPayerIri;
35
+ }
36
+
37
+ return payload;
38
+ };
39
+
40
+ module.exports = {
41
+ LINKED_ORDER_TYPE,
42
+ buildLinkedOrderPayload,
43
+ };
@@ -1,6 +1,7 @@
1
1
  const {
2
2
  DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
3
3
  getRuntimeFooterRotationEntries,
4
+ getRuntimeFooterTickerText,
4
5
  getRuntimeFooterText,
5
6
  getRuntimeFooterTextLines,
6
7
  normalizeRuntimeFooterText,
@@ -482,6 +483,7 @@ module.exports = {
482
483
  getRuntimeFooterNativeIdentifierCandidates,
483
484
  getRuntimeFooterPrimaryText,
484
485
  getRuntimeFooterRotationEntries,
486
+ getRuntimeFooterTickerText,
485
487
  getRuntimeFooterStoredVersion,
486
488
  getRuntimeFooterTextLines,
487
489
  getRuntimeFooterVersionCandidates,
@@ -148,8 +148,19 @@ const getRuntimeFooterRotationEntries = ({companyFooterText, primaryText}) =>
148
148
  Boolean,
149
149
  );
150
150
 
151
+ const RUNTIME_FOOTER_TICKER_SEPARATOR = ' • ';
152
+
153
+ // Text of the footer ticker: the text written by the user (company footer)
154
+ // first, then the system text (e.g. "web • MANAGER (ip) / v1.10.x").
155
+ const getRuntimeFooterTickerText = ({companyFooterText, primaryText}) =>
156
+ getRuntimeFooterRotationEntries({companyFooterText, primaryText}).join(
157
+ RUNTIME_FOOTER_TICKER_SEPARATOR,
158
+ );
159
+
151
160
  module.exports = {
152
161
  DEVICE_RUNTIME_FOOTER_TEXT_CONFIG_KEY,
162
+ RUNTIME_FOOTER_TICKER_SEPARATOR,
163
+ getRuntimeFooterTickerText,
153
164
  getRuntimeFooterRotationEntries,
154
165
  getRuntimeFooterText,
155
166
  getRuntimeFooterTextLines,
@@ -7,6 +7,7 @@ const React = require('react');
7
7
  const originalLoad = Module._load;
8
8
  let lastLoopConfig = null;
9
9
  let animationStarts = 0;
10
+ let mockPlatformOS = 'android';
10
11
 
11
12
  before(() => {
12
13
  Module._load = function mockLoad(request, parent, isMain) {
@@ -63,6 +64,8 @@ before(() => {
63
64
  },
64
65
  Text: props => React.createElement('Text', props, props.children),
65
66
  View: props => React.createElement('View', props, props.children),
67
+ Easing: {linear: 'linear'},
68
+ Platform: {OS: mockPlatformOS},
66
69
  StyleSheet: {create: styles => styles},
67
70
  };
68
71
  }
@@ -193,3 +196,140 @@ test('native text keeps intrinsic width even when style carries flex: 1 (android
193
196
  assert.equal(flat.flexGrow, 0);
194
197
  assert.equal(flat.flexShrink, 0);
195
198
  });
199
+
200
+ const TICKER_TEXT =
201
+ 'www.controleonline.com \u2022 (11) 5555-5159 (Comercial) \u2022 web \u2022 MANAGER (179.125.133.217) / v1.10.236';
202
+
203
+ const renderTicker = ({containerWidth, contentWidth, text = TICKER_TEXT}) => {
204
+ const RuntimeFooterMarqueeText = loadComponent();
205
+ const renderer = require('react-test-renderer');
206
+
207
+ animationStarts = 0;
208
+ lastLoopConfig = null;
209
+
210
+ let tree;
211
+ renderer.act(() => {
212
+ tree = renderer.create(
213
+ React.createElement(RuntimeFooterMarqueeText, {
214
+ text,
215
+ color: '#111',
216
+ continuous: true,
217
+ style: {fontSize: 10},
218
+ }),
219
+ );
220
+ });
221
+
222
+ if (containerWidth) {
223
+ const root = tree.root.findByProps({testID: 'runtime-footer-marquee-text'});
224
+ renderer.act(() => {
225
+ root.props.onLayout({
226
+ nativeEvent: {layout: {width: containerWidth, height: 12}},
227
+ });
228
+ });
229
+ }
230
+ if (contentWidth) {
231
+ const firstText = tree.root.findAllByType('Text')[0];
232
+ renderer.act(() => {
233
+ firstText.props.onLayout({
234
+ nativeEvent: {layout: {width: contentWidth, height: 12}},
235
+ });
236
+ });
237
+ }
238
+ return tree;
239
+ };
240
+
241
+ describe('continuous ticker (right to left, loop)', () => {
242
+ test('native: scrolls even when the text fits, right to left, linear, no hold', () => {
243
+ mockPlatformOS = 'android';
244
+ // content (200) fits inside the container (800): a ticker must still scroll.
245
+ const tree = renderTicker({containerWidth: 800, contentWidth: 200});
246
+
247
+ assert.ok(lastLoopConfig, 'Animated.loop should start for a ticker');
248
+ const [hold, move, reset] = lastLoopConfig.items;
249
+ assert.equal(hold.ms, 0, 'ticker has no hold before moving');
250
+ assert.equal(move.config.toValue, -(200 + 32), 'moves left by one text cycle');
251
+ assert.equal(move.config.easing, 'linear');
252
+ assert.ok(move.config.toValue < 0, 'right to left');
253
+ assert.equal(reset.config.duration, 0, 'instant reset = seamless loop');
254
+
255
+ // The row must be wider than the container, otherwise native Text is
256
+ // measured with the container width as maximum and the text is truncated.
257
+ const row = tree.root.findByProps({testID: 'runtime-footer-ticker-row'});
258
+ const rowStyle = Object.assign({}, ...[].concat(row.props.style));
259
+ assert.ok(rowStyle.width >= 10000, 'ticker row must not be as narrow as the container');
260
+ assert.equal(rowStyle.flexWrap, 'nowrap');
261
+
262
+ // enough copies to always fill the width: ceil(800 / 232) + 1 = 5
263
+ const texts = tree.root.findAllByType('Text');
264
+ assert.equal(texts.length, 5);
265
+ texts.forEach(node => assert.equal(node.props.children, TICKER_TEXT));
266
+ });
267
+
268
+ test('native: speed is constant (duration proportional to the distance)', () => {
269
+ mockPlatformOS = 'android';
270
+ renderTicker({containerWidth: 800, contentWidth: 200});
271
+ const shortDuration = lastLoopConfig.items[1].config.duration;
272
+ renderTicker({containerWidth: 800, contentWidth: 1000});
273
+ const longDuration = lastLoopConfig.items[1].config.duration;
274
+
275
+ assert.ok(shortDuration >= 3000);
276
+ assert.ok(longDuration > shortDuration);
277
+ assert.equal(Math.round(longDuration / (1000 + 32)), 20);
278
+ });
279
+
280
+ test('native: before measuring there is a single copy and no animation', () => {
281
+ mockPlatformOS = 'android';
282
+ const tree = renderTicker({});
283
+ assert.equal(tree.root.findAllByType('Text').length, 1);
284
+ assert.equal(lastLoopConfig, null);
285
+ });
286
+
287
+ test('native: a long text still scrolls with at least two copies', () => {
288
+ mockPlatformOS = 'android';
289
+ const tree = renderTicker({containerWidth: 300, contentWidth: 1500});
290
+ assert.equal(tree.root.findAllByType('Text').length, 2);
291
+ assert.equal(lastLoopConfig.items[1].config.toValue, -(1500 + 32));
292
+ });
293
+
294
+ test('web: uses CSS keyframes (right to left, infinite, linear), not Animated', () => {
295
+ mockPlatformOS = 'web';
296
+ const tree = renderTicker({containerWidth: 800, contentWidth: 200});
297
+
298
+ assert.equal(lastLoopConfig, null, 'web must not use Animated.loop');
299
+ const row = tree.root.findByProps({testID: 'runtime-footer-ticker-row'});
300
+ const style = Object.assign({}, ...[].concat(row.props.style));
301
+ assert.equal(style.animationIterationCount, 'infinite');
302
+ assert.equal(style.animationTimingFunction, 'linear');
303
+ assert.match(style.animationDuration, /^\d+ms$/);
304
+ const [keyframes] = style.animationKeyframes;
305
+ assert.equal(keyframes['0%'].transform[0].translateX, 0);
306
+ assert.equal(keyframes['100%'].transform[0].translateX, -(200 + 32));
307
+ assert.equal(tree.root.findAllByType('Text').length, 5);
308
+ mockPlatformOS = 'android';
309
+ });
310
+
311
+ test('without the continuous prop the previous behaviour is kept', () => {
312
+ mockPlatformOS = 'android';
313
+ const RuntimeFooterMarqueeText = loadComponent();
314
+ const renderer = require('react-test-renderer');
315
+ animationStarts = 0;
316
+ lastLoopConfig = null;
317
+ let tree;
318
+ renderer.act(() => {
319
+ tree = renderer.create(
320
+ React.createElement(RuntimeFooterMarqueeText, {text: 'short', color: '#111'}),
321
+ );
322
+ });
323
+ const root = tree.root.findByProps({testID: 'runtime-footer-marquee-text'});
324
+ renderer.act(() => {
325
+ root.props.onLayout({nativeEvent: {layout: {width: 400, height: 12}}});
326
+ });
327
+ renderer.act(() => {
328
+ tree.root.findAllByType('Text')[0].props.onLayout({
329
+ nativeEvent: {layout: {width: 40, height: 12}},
330
+ });
331
+ });
332
+ assert.equal(lastLoopConfig, null);
333
+ assert.equal(tree.root.findAllByType('Text').length, 1);
334
+ });
335
+ });
@@ -0,0 +1,28 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const { resolveDocumentFileContent } = require('../../../react/utils/documentFileContent');
4
+
5
+ const toBase64 = text => Buffer.from(text, 'utf8').toString('base64');
6
+
7
+ test('decodes base64 HTML documents returned by the files API', () => {
8
+ const html = '<h1>Proposta</h1><p>Codex — R$ 260,00 (ação)</p>';
9
+ assert.deepEqual(resolveDocumentFileContent(toBase64(html)), { kind: 'html', content: html });
10
+ });
11
+
12
+ test('keeps plain HTML as is', () => {
13
+ assert.deepEqual(resolveDocumentFileContent(' <p>ok</p>'), { kind: 'html', content: ' <p>ok</p>' });
14
+ });
15
+
16
+ test('treats non-HTML base64 payloads as PDF', () => {
17
+ const pdf = Buffer.from([0x25, 0x50, 0x44, 0x46, 0x2d, 0xff, 0xfe, 0x00]).toString('base64');
18
+ assert.deepEqual(resolveDocumentFileContent(pdf), { kind: 'pdf', content: pdf });
19
+ });
20
+
21
+ test('empty and plain text contents', () => {
22
+ assert.deepEqual(resolveDocumentFileContent(''), { kind: 'empty', content: '' });
23
+ assert.deepEqual(resolveDocumentFileContent(null), { kind: 'empty', content: '' });
24
+ assert.deepEqual(resolveDocumentFileContent('Contrato simples, sem HTML.'), {
25
+ kind: 'text',
26
+ content: 'Contrato simples, sem HTML.',
27
+ });
28
+ });
@@ -0,0 +1,46 @@
1
+ const test = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const {
4
+ LINKED_ORDER_TYPE,
5
+ buildLinkedOrderPayload,
6
+ } = require('../../../react/utils/linkedOrderPayload');
7
+
8
+ test('linked commercial orders start as cart so products can be edited', () => {
9
+ assert.equal(LINKED_ORDER_TYPE, 'cart');
10
+ const payload = buildLinkedOrderPayload({
11
+ contractIri: '/contracts/27',
12
+ providerIri: '/people/1',
13
+ statusIri: '/statuses/119',
14
+ clientIri: '/people/105792',
15
+ });
16
+
17
+ assert.deepEqual(payload, {
18
+ app: 'CRM',
19
+ orderType: 'cart',
20
+ contract: '/contracts/27',
21
+ provider: '/people/1',
22
+ status: '/statuses/119',
23
+ client: '/people/105792',
24
+ payer: '/people/105792',
25
+ });
26
+ });
27
+
28
+ test('empty orderType falls back to cart instead of being sent blank', () => {
29
+ assert.equal(buildLinkedOrderPayload({orderType: ''}).orderType, 'cart');
30
+ assert.equal(buildLinkedOrderPayload({orderType: null}).orderType, 'cart');
31
+ });
32
+
33
+ test('explicit payer wins over client and optional refs are omitted', () => {
34
+ const payload = buildLinkedOrderPayload({
35
+ contractIri: '/contracts/1',
36
+ providerIri: '/people/1',
37
+ clientIri: '/people/2',
38
+ payerIri: '/people/3',
39
+ });
40
+ assert.equal(payload.payer, '/people/3');
41
+ assert.equal('status' in payload, false);
42
+
43
+ const withoutParties = buildLinkedOrderPayload({contractIri: '/contracts/1'});
44
+ assert.equal('client' in withoutParties, false);
45
+ assert.equal('payer' in withoutParties, false);
46
+ });
@@ -3,6 +3,7 @@ const {test} = require('node:test')
3
3
 
4
4
  const {
5
5
  getRuntimeFooterRotationEntries,
6
+ getRuntimeFooterTickerText,
6
7
  getRuntimeFooterText,
7
8
  getRuntimeFooterTextLines,
8
9
  } = require('../../../react/utils/runtimeFooterText')
@@ -86,3 +87,36 @@ test('returns empty string when footer text is absent', () => {
86
87
  assert.equal(getRuntimeFooterText(null, []), '')
87
88
  assert.deepEqual(getRuntimeFooterTextLines(''), [])
88
89
  })
90
+
91
+ test('ticker text: user text first, then the system text, joined by a bullet', () => {
92
+ const companyFooterText =
93
+ 'www.controleonline.com \u2022 (11) 5555-5159 (Comercial) \u2022 (11) 3136-0353 (Suporte)'
94
+ const primaryText = 'web \u2022 MANAGER (179.125.133.217) / v1.10.236'
95
+
96
+ assert.equal(
97
+ getRuntimeFooterTickerText({companyFooterText, primaryText}),
98
+ `${companyFooterText} \u2022 ${primaryText}`,
99
+ )
100
+ })
101
+
102
+ test('ticker text: multiple user lines keep their order before the system text', () => {
103
+ assert.equal(
104
+ getRuntimeFooterTickerText({
105
+ companyFooterText: 'linha 1\nlinha 2',
106
+ primaryText: 'web \u2022 PDV / v1',
107
+ }),
108
+ 'linha 1 \u2022 linha 2 \u2022 web \u2022 PDV / v1',
109
+ )
110
+ })
111
+
112
+ test('ticker text: shows only the available text, or nothing', () => {
113
+ assert.equal(
114
+ getRuntimeFooterTickerText({companyFooterText: '', primaryText: 'web \u2022 PDV / v1'}),
115
+ 'web \u2022 PDV / v1',
116
+ )
117
+ assert.equal(
118
+ getRuntimeFooterTickerText({companyFooterText: 'Somente usuario', primaryText: ''}),
119
+ 'Somente usuario',
120
+ )
121
+ assert.equal(getRuntimeFooterTickerText({companyFooterText: '', primaryText: ''}), '')
122
+ })