@controleonline/ui-common 1.2.86 → 1.2.88

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 (73) hide show
  1. package/.github/workflows/integration-source-gate.yml +68 -0
  2. package/.github/workflows/manager-worker.yml +7 -156
  3. package/.github/workflows/publish-npm.yml +73 -27
  4. package/.github/workflows/pull-request-checks.yml +7 -5
  5. package/docs/technical/Device-Detail-Alias-UI-Sync.md +141 -0
  6. package/package.json +13 -8
  7. package/src/react/components/AddImportModal.js +61 -34
  8. package/src/react/components/BottomNavigationBar.js +178 -174
  9. package/src/react/components/BottomNavigationBar.styles.js +139 -118
  10. package/src/react/components/DefaultProvider.native.js +427 -421
  11. package/src/react/components/DefaultProvider.web.js +131 -125
  12. package/src/react/components/RemoteCheckoutService.js +3 -3
  13. package/src/react/components/RuntimeFooterMarqueeText.js +88 -36
  14. package/src/react/components/RuntimeInfoFooter.js +76 -43
  15. package/src/react/components/RuntimeInfoFooter.styles.js +22 -14
  16. package/src/react/config/deviceConfigBootstrap.js +3 -3
  17. package/src/react/pages/Devices/detail/DeviceDetailAlertsCommandsSection.js +4 -22
  18. package/src/react/pages/Devices/detail/DeviceDetailMovementSections.js +6 -2
  19. package/src/react/pages/Devices/detail/DeviceDetailOrdersPrintSection.js +4 -0
  20. package/src/react/pages/Devices/detail/DeviceDetailScreen.js +23 -338
  21. package/src/react/pages/Devices/detail/createDeviceDetailContext.js +20 -0
  22. package/src/react/pages/Devices/detail/useDeviceDetailActions.js +11 -36
  23. package/src/react/pages/Devices/detail/useDeviceDetailLoaders.js +129 -37
  24. package/src/react/pages/Devices/detail/useDeviceDetailSaves.js +11 -38
  25. package/src/react/pages/Devices/detail/useDeviceDetailStateA.js +9 -28
  26. package/src/react/pages/Imports.js +13 -11
  27. package/src/react/pages/IntegrationConfigFields.js +1 -0
  28. package/src/react/pages/IntegrationConfigPage.js +101 -45
  29. package/src/react/pages/IntegrationConfigPage.utils.js +21 -13
  30. package/src/react/pages/fetchPeopleConfigs.js +21 -0
  31. package/src/react/pages/integrationsCatalog.js +15 -110
  32. package/src/react/services/Cielo/Cielo.js +9 -9
  33. package/src/react/services/Getnet/Getnet.web.js +25 -0
  34. package/src/react/utils/companyAuthority.js +36 -0
  35. package/src/react/utils/fileUrl.js +14 -5
  36. package/src/react/utils/paymentDevices.js +375 -270
  37. package/src/react/utils/printerDevices.js +2 -2
  38. package/src/react/utils/runtimeFooter.js +178 -224
  39. package/src/react/utils/runtimeFooterText.js +160 -0
  40. package/src/react/utils/runtimeLanguage.js +5 -5
  41. package/src/react/utils/runtimeZoom.js +29 -5
  42. package/src/react/utils/shopFranchises.js +167 -12
  43. package/src/react/utils/storeColumns.js +235 -217
  44. package/src/react/utils/systemErrorMessage.js +2 -1
  45. package/src/store/imports/customActions.js +42 -2
  46. package/src/store/integration/index.js +43 -0
  47. package/src/tests/browser/manager/device-detail-apply-config-defined.spec.js +31 -0
  48. package/src/tests/browser/manager/device-detail-composition.spec.js +295 -0
  49. package/src/tests/browser/manager/device-detail-copy-config.spec.js +11 -1
  50. package/src/tests/browser/manager/device-detail-pdv-current-company.spec.js +273 -0
  51. package/src/tests/browser/manager/runtime-footer-rotation.spec.js +397 -0
  52. package/src/tests/react/components/DefaultProviderAuthority.test.js +28 -0
  53. package/src/tests/react/components/RuntimeFooterMarqueeText.build.test.js +29 -0
  54. package/src/tests/react/config/deviceConfigBootstrap.test.js +24 -1
  55. package/src/tests/react/pages/applyCurrentDeviceConfig.test.js +85 -0
  56. package/src/tests/react/pages/deviceDetailComposition.test.js +65 -0
  57. package/src/tests/react/pages/deviceDetailHookDependencies.test.mjs +31 -0
  58. package/src/tests/react/pages/deviceDetailLoaderDependencies.test.mjs +28 -0
  59. package/src/tests/react/pages/receitaFederalIntegrationContract.test.mjs +27 -6
  60. package/src/tests/react/services/Cielo.test.js +2 -2
  61. package/src/tests/react/utils/companyAuthority.test.js +53 -0
  62. package/src/tests/react/utils/formatter.test.mjs +6 -0
  63. package/src/tests/react/utils/paymentDevices.test.js +72 -0
  64. package/src/tests/react/utils/runtimeFooter.test.js +35 -0
  65. package/src/tests/react/utils/runtimeFooterText.test.js +88 -0
  66. package/src/tests/react/utils/runtimeLanguage.test.js +4 -4
  67. package/src/tests/react/utils/runtimeZoom.test.js +20 -0
  68. package/src/tests/react/utils/shopFranchises.test.js +32 -13
  69. package/src/tests/react/utils/translate.test.mjs +6 -6
  70. package/src/utils/formatter.js +7 -3
  71. package/src/utils/translate.js +16 -16
  72. package/src/utils/translatePending.js +6 -6
  73. package/src/utils/translateStorage.js +2 -2
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Smoke browser: PDV detail and all tabs render with their complete dependencies.
3
+ * fluxo: device-configuracao
4
+ * flowchartIds: [1]
5
+ * Refs: app-community#706
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const {expect, test} = require('playwright/test');
10
+ const packageJson = require('../../../../../../../package.json');
11
+
12
+ const FLOW_ID = 'device-configuracao';
13
+ const FLOWCHART_IDS = [1];
14
+ const APP_VERSION = packageJson?.version || '1.0.0';
15
+ const DEVICE_ENTITY_ID = 403;
16
+ const PDV_CONFIG_ID = 510;
17
+ const CURRENT_DEVICE_ID = 'web-7';
18
+ const ALIAS = 'PDV Fixture';
19
+
20
+ const CORS_HEADERS = {
21
+ 'access-control-allow-origin': '*',
22
+ 'access-control-allow-headers':
23
+ 'API-TOKEN, APP-DOMAIN, DEVICE, ACCEPT, CONTENT-TYPE, X-Requested-With',
24
+ 'access-control-allow-methods': 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
25
+ };
26
+
27
+ const jsonHeaders = () => ({
28
+ ...CORS_HEADERS,
29
+ 'content-type': 'application/ld+json; charset=utf-8',
30
+ });
31
+
32
+ const collection = member => ({
33
+ member,
34
+ 'hydra:member': member,
35
+ totalItems: member.length,
36
+ 'hydra:totalItems': member.length,
37
+ summary: {},
38
+ });
39
+
40
+ const evidenceSteps = [];
41
+
42
+ const writeEvidence = async (page, outputDir, stepId, title) => {
43
+ fs.mkdirSync(outputDir, {recursive: true});
44
+ const fileName = `${stepId}.png`;
45
+ await page.screenshot({path: path.join(outputDir, fileName), fullPage: true});
46
+ evidenceSteps.push({id: stepId, title, screenshot: fileName, url: page.url()});
47
+ };
48
+
49
+ const writeManifest = outputDir => {
50
+ const manifest = {
51
+ fluxo: FLOW_ID,
52
+ flowchartIds: FLOWCHART_IDS,
53
+ flowchartLinks: FLOWCHART_IDS.map(
54
+ id => `https://admin.controleonline.com/admin/flowcharts/${id}`,
55
+ ),
56
+ title: 'DeviceConfig PDV detail and tabs render without runtime errors',
57
+ issue: 'ControleOnline/app-community#706',
58
+ device: DEVICE_ENTITY_ID,
59
+ config: PDV_CONFIG_ID,
60
+ type: 'PDV',
61
+ steps: evidenceSteps,
62
+ };
63
+ fs.writeFileSync(
64
+ path.join(outputDir, 'manifest.json'),
65
+ `${JSON.stringify(manifest, null, 2)}\n`,
66
+ );
67
+ return manifest;
68
+ };
69
+
70
+ const currentDevice = {
71
+ '@id': `/devices/${DEVICE_ENTITY_ID}`,
72
+ '@type': 'Device',
73
+ id: DEVICE_ENTITY_ID,
74
+ device: 'pos-fixture-706',
75
+ alias: ALIAS,
76
+ metadata: {runtime: 'web', network: {publicIp: '127.0.0.1'}},
77
+ };
78
+
79
+ const createDeviceConfig = ({id, type, device = currentDevice}) => ({
80
+ '@id': `/device_configs/${id}`,
81
+ '@type': 'DeviceConfig',
82
+ id,
83
+ type,
84
+ people: '/people/3',
85
+ device,
86
+ configs: JSON.stringify({
87
+ 'config-version': APP_VERSION,
88
+ 'pos-gateway': 'infinite-pay',
89
+ }),
90
+ });
91
+
92
+ const mockDevicesApi = async page => {
93
+ const company = {
94
+ id: 3,
95
+ name: 'Teste',
96
+ alias: 'TESTE',
97
+ panel_enabled: true,
98
+ enabled: true,
99
+ commercial_enabled: true,
100
+ theme: {colors: {primary: '#0EA5E9'}},
101
+ };
102
+ const managerConfig = createDeviceConfig({id: 487, type: 'MANAGER'});
103
+ const pdvConfig = createDeviceConfig({id: PDV_CONFIG_ID, type: 'PDV'});
104
+ const deviceConfigs = [managerConfig, pdvConfig];
105
+
106
+ await page.route(/^https:\/\/(?:api|s)\.controleonline\.com\//, async route => {
107
+ const request = route.request();
108
+ const url = new URL(request.url());
109
+ const pathname = url.pathname.replace(/^\/+/, '');
110
+ const method = request.method().toUpperCase();
111
+
112
+ if (method === 'OPTIONS') {
113
+ return route.fulfill({status: 204, headers: CORS_HEADERS, body: ''});
114
+ }
115
+ if (pathname === 'themes-colors.css') {
116
+ return route.fulfill({
117
+ status: 200,
118
+ headers: {...CORS_HEADERS, 'content-type': 'text/css; charset=utf-8'},
119
+ body: ':root { --primary: #0ea5e9; }',
120
+ });
121
+ }
122
+ if (pathname === 'runtime/ip') {
123
+ return route.fulfill({
124
+ status: 200,
125
+ headers: jsonHeaders(),
126
+ body: JSON.stringify({ip: '127.0.0.1'}),
127
+ });
128
+ }
129
+ if (pathname === 'menus-people') {
130
+ return route.fulfill({
131
+ status: 200,
132
+ headers: jsonHeaders(),
133
+ body: JSON.stringify({modules: {}}),
134
+ });
135
+ }
136
+ if (pathname === 'people/companies/my') {
137
+ return route.fulfill({
138
+ status: 200,
139
+ headers: jsonHeaders(),
140
+ body: JSON.stringify(collection([company])),
141
+ });
142
+ }
143
+ if (pathname === 'people/company/default') {
144
+ return route.fulfill({
145
+ status: 200,
146
+ headers: jsonHeaders(),
147
+ body: JSON.stringify(company),
148
+ });
149
+ }
150
+ if (pathname === 'configs/discovery-configs') {
151
+ return route.fulfill({
152
+ status: 200,
153
+ headers: jsonHeaders(),
154
+ body: JSON.stringify({configs: {}}),
155
+ });
156
+ }
157
+ if (pathname === 'devices' && method === 'GET') {
158
+ return route.fulfill({
159
+ status: 200,
160
+ headers: jsonHeaders(),
161
+ body: JSON.stringify(collection([currentDevice])),
162
+ });
163
+ }
164
+ if (
165
+ (pathname === `devices/${DEVICE_ENTITY_ID}` ||
166
+ pathname === `devices/${CURRENT_DEVICE_ID}`) &&
167
+ method === 'GET'
168
+ ) {
169
+ return route.fulfill({
170
+ status: 200,
171
+ headers: jsonHeaders(),
172
+ body: JSON.stringify(currentDevice),
173
+ });
174
+ }
175
+ if (pathname === 'device_configs' && method === 'GET') {
176
+ return route.fulfill({
177
+ status: 200,
178
+ headers: jsonHeaders(),
179
+ body: JSON.stringify(collection(deviceConfigs.filter(config => {
180
+ const type = url.searchParams.get('type');
181
+ const identifier = url.searchParams.get('device.device');
182
+ return (!type || config.type === type) &&
183
+ (!identifier || config.device.device === identifier);
184
+ }))),
185
+ });
186
+ }
187
+ if (pathname.startsWith('device_configs/') && method === 'GET') {
188
+ const id = Number(pathname.split('/')[1]);
189
+ const found = deviceConfigs.find(c => c.id === id) || pdvConfig;
190
+ return route.fulfill({
191
+ status: 200,
192
+ headers: jsonHeaders(),
193
+ body: JSON.stringify(found),
194
+ });
195
+ }
196
+ return route.fulfill({
197
+ status: 200,
198
+ headers: jsonHeaders(),
199
+ body: JSON.stringify(collection([])),
200
+ });
201
+ });
202
+
203
+ await page.addInitScript(
204
+ ({appVersion}) => {
205
+ localStorage.setItem('session', JSON.stringify({id: 7, people: 7, active: 1, api_key: 'fixture-token-706'}));
206
+ localStorage.setItem('config', JSON.stringify({language: 'pt-br'}));
207
+ localStorage.setItem(
208
+ 'device',
209
+ JSON.stringify({
210
+ id: 'web-7',
211
+ device: 'web-7',
212
+ type: 'MANAGER',
213
+ appName: 'Browser Manager',
214
+ appVersion,
215
+ buildNumber: appVersion,
216
+ systemName: 'web',
217
+ systemVersion: 'web',
218
+ deviceType: 'web',
219
+ metadata: {runtime: 'web'},
220
+ }),
221
+ );
222
+ },
223
+ {appVersion: APP_VERSION},
224
+ );
225
+ };
226
+
227
+ test.describe('device-detail complete composition (#706)', () => {
228
+ test.describe.configure({timeout: 60000});
229
+
230
+ test('PDV detail and tabs open without runtime errors', async ({
231
+ page,
232
+ }, testInfo) => {
233
+ testInfo.annotations.push({type: 'fluxo', description: FLOW_ID});
234
+ testInfo.annotations.push({
235
+ type: 'flowchartIds',
236
+ description: JSON.stringify(FLOWCHART_IDS),
237
+ });
238
+
239
+ const outputDir = testInfo.outputDir;
240
+ const pageErrors = [];
241
+ page.on('pageerror', err => pageErrors.push(String(err)));
242
+ page.on('console', msg => {
243
+ if (msg.type() === 'error') pageErrors.push(msg.text());
244
+ });
245
+
246
+ await page.context().route('**/*', route => {
247
+ const host = new URL(route.request().url()).hostname;
248
+ return ['127.0.0.1', 'localhost'].includes(host)
249
+ ? route.continue() : route.abort();
250
+ });
251
+ await page.routeWebSocket('**/*', socket => socket.close());
252
+ await mockDevicesApi(page);
253
+ await page.goto('/devices-index?store=device_config');
254
+ await expect(page.getByTestId(`device-config-${PDV_CONFIG_ID}`)).toBeVisible({
255
+ timeout: 15000,
256
+ });
257
+ await writeEvidence(page, outputDir, '01-lista-devices', 'DevicesIndex');
258
+
259
+ await page.getByTestId(`device-config-${PDV_CONFIG_ID}`).click();
260
+ await expect(page).toHaveURL(/device-detail/, {timeout: 15000});
261
+ await expect(page.getByText('Configuração do PDV')).toBeVisible({
262
+ timeout: 15000,
263
+ });
264
+ await writeEvidence(
265
+ page,
266
+ outputDir,
267
+ '02-detalhe-pdv-510',
268
+ 'DeviceConfig PDV 510 / device 403',
269
+ );
270
+
271
+ const bodyText = await page.locator('body').innerText();
272
+ expect(bodyText).not.toMatch(/currentCompany is not defined/i);
273
+ expect(pageErrors.filter(error => /ReferenceError|is not defined|Maximum update depth/i.test(error))).toEqual([]);
274
+ for (const [label, expected] of [
275
+ [/^(Pdv ?Orders|Pedidos|Orders)$/i, /Pedidos do Device/i],
276
+ [/^(Pdv ?Device|Dispositivo|Device)$/i, /Aviso Sonoro/i],
277
+ [/^(Pdv ?Payments|Pagamentos|Payments)$/i, /Pagamentos do device/i],
278
+ [/^(Pdv ?Movement|Movimento|Movement)$/i, /Produtos Vendidos/i],
279
+ ]) {
280
+ const control = page.getByText(label, {exact: true}).first();
281
+ await control.click();
282
+ await expect(page.getByText(expected).first()).toBeVisible();
283
+ await writeEvidence(page, outputDir, `tab-${evidenceSteps.length}`, String(label));
284
+ }
285
+ expect(pageErrors.filter(error => /ReferenceError|is not defined|Maximum update depth/i.test(error))).toEqual([]);
286
+
287
+ const manifest = writeManifest(outputDir);
288
+ expect(manifest.fluxo).toBe(FLOW_ID);
289
+ expect(manifest.flowchartIds).toEqual(FLOWCHART_IDS);
290
+ expect(manifest.steps.slice(0, 2).map(s => s.id)).toEqual([
291
+ '01-lista-devices',
292
+ '02-detalhe-pdv-510',
293
+ ]);
294
+ });
295
+ });
@@ -304,8 +304,14 @@ test.describe('device-detail copy config (browser smoke #629)', () => {
304
304
 
305
305
  test('copy from source device posts destination identity only', async ({
306
306
  page,
307
- }) => {
307
+ }, testInfo) => {
308
308
  const api = await mockCopyApi(page);
309
+ const shot = async (name) => {
310
+ await page.screenshot({
311
+ path: testInfo.outputPath(name),
312
+ fullPage: true,
313
+ });
314
+ };
309
315
 
310
316
  await page.goto('/devices-index?store=device_config');
311
317
  await page.getByTestId('device-config-487').click();
@@ -313,6 +319,7 @@ test.describe('device-detail copy config (browser smoke #629)', () => {
313
319
  await expect(page.getByTestId('device-alias-text')).toHaveText(DEST_ALIAS, {
314
320
  timeout: 15000,
315
321
  });
322
+ await shot('01-device-detail-header-copy-btn.png');
316
323
 
317
324
  await page.getByTestId('device-detail-copy-config-btn').click();
318
325
  await expect(page.getByTestId('copy-device-config-modal')).toBeVisible({
@@ -321,6 +328,7 @@ test.describe('device-detail copy config (browser smoke #629)', () => {
321
328
  await expect(page.getByTestId('copy-device-config-hint')).toContainText(
322
329
  DEST_ALIAS,
323
330
  );
331
+ await shot('02-copy-modal-picker.png');
324
332
 
325
333
  await expect(
326
334
  page.getByTestId(`copy-device-config-option-${SRC_DEVICE_STRING}`),
@@ -342,6 +350,7 @@ test.describe('device-detail copy config (browser smoke #629)', () => {
342
350
  await expect(page.getByTestId('copy-device-config-preview')).toContainText(
343
351
  'pos-gateway',
344
352
  );
353
+ await shot('03-copy-modal-preview-keys.png');
345
354
 
346
355
  await page.getByTestId('copy-device-config-confirm').click();
347
356
 
@@ -361,5 +370,6 @@ test.describe('device-detail copy config (browser smoke #629)', () => {
361
370
 
362
371
  await expect(page).toHaveURL(/device-detail/);
363
372
  await expect(page.getByTestId('device-alias-text')).toHaveText(DEST_ALIAS);
373
+ await shot('04-device-detail-after-copy.png');
364
374
  });
365
375
  });
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Smoke browser: DeviceConfig PDV detail opens without currentCompany ReferenceError.
3
+ * fluxo: device-configuracao
4
+ * flowchartIds: [1]
5
+ * Refs: app-community#704
6
+ */
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+ const {expect, test} = require('playwright/test');
10
+ const packageJson = require('../../../../../../../package.json');
11
+ const {API_ORIGIN} = require('../../../../../../../src/tests/browser/apiOrigin');
12
+
13
+ const FLOW_ID = 'device-configuracao';
14
+ const FLOWCHART_IDS = [1];
15
+ const APP_VERSION = packageJson?.version || '1.0.0';
16
+ const DEVICE_ENTITY_ID = 403;
17
+ const PDV_CONFIG_ID = 510;
18
+ const CURRENT_DEVICE_ID = 'web-7';
19
+ const ALIAS = 'PDV Santa Redonda';
20
+
21
+ const CORS_HEADERS = {
22
+ 'access-control-allow-origin': '*',
23
+ 'access-control-allow-headers':
24
+ 'API-TOKEN, APP-DOMAIN, DEVICE, ACCEPT, CONTENT-TYPE, X-Requested-With',
25
+ 'access-control-allow-methods': 'GET,POST,PUT,PATCH,DELETE,OPTIONS',
26
+ };
27
+
28
+ const jsonHeaders = () => ({
29
+ ...CORS_HEADERS,
30
+ 'content-type': 'application/ld+json; charset=utf-8',
31
+ });
32
+
33
+ const collection = member => ({
34
+ member,
35
+ 'hydra:member': member,
36
+ totalItems: member.length,
37
+ 'hydra:totalItems': member.length,
38
+ summary: {},
39
+ });
40
+
41
+ const evidenceSteps = [];
42
+
43
+ const writeEvidence = async (page, outputDir, stepId, title) => {
44
+ fs.mkdirSync(outputDir, {recursive: true});
45
+ const fileName = `${stepId}.png`;
46
+ await page.screenshot({path: path.join(outputDir, fileName), fullPage: true});
47
+ evidenceSteps.push({id: stepId, title, screenshot: fileName, url: page.url()});
48
+ };
49
+
50
+ const writeManifest = outputDir => {
51
+ const manifest = {
52
+ fluxo: FLOW_ID,
53
+ flowchartIds: FLOWCHART_IDS,
54
+ flowchartLinks: FLOWCHART_IDS.map(
55
+ id => `https://admin.controleonline.com/admin/flowcharts/${id}`,
56
+ ),
57
+ title: 'DeviceConfig PDV detail opens without currentCompany error',
58
+ issue: 'ControleOnline/app-community#704',
59
+ device: DEVICE_ENTITY_ID,
60
+ config: PDV_CONFIG_ID,
61
+ type: 'PDV',
62
+ steps: evidenceSteps,
63
+ };
64
+ fs.writeFileSync(
65
+ path.join(outputDir, 'manifest.json'),
66
+ `${JSON.stringify(manifest, null, 2)}\n`,
67
+ );
68
+ return manifest;
69
+ };
70
+
71
+ const currentDevice = {
72
+ '@id': `/devices/${DEVICE_ENTITY_ID}`,
73
+ '@type': 'Device',
74
+ id: DEVICE_ENTITY_ID,
75
+ device: CURRENT_DEVICE_ID,
76
+ alias: ALIAS,
77
+ metadata: {runtime: 'web', network: {publicIp: '127.0.0.1'}},
78
+ };
79
+
80
+ const createDeviceConfig = ({id, type, device = currentDevice}) => ({
81
+ '@id': `/device_configs/${id}`,
82
+ '@type': 'DeviceConfig',
83
+ id,
84
+ type,
85
+ people: '/people/3',
86
+ device,
87
+ configs: JSON.stringify({
88
+ 'config-version': APP_VERSION,
89
+ 'pos-gateway': 'infinite-pay',
90
+ }),
91
+ });
92
+
93
+ const mockDevicesApi = async page => {
94
+ const company = {
95
+ id: 3,
96
+ name: 'Teste',
97
+ alias: 'TESTE',
98
+ panel_enabled: true,
99
+ enabled: true,
100
+ commercial_enabled: true,
101
+ theme: {colors: {primary: '#0EA5E9'}},
102
+ };
103
+ const managerConfig = createDeviceConfig({id: 487, type: 'MANAGER'});
104
+ const pdvConfig = createDeviceConfig({id: PDV_CONFIG_ID, type: 'PDV'});
105
+ const deviceConfigs = [managerConfig, pdvConfig];
106
+
107
+ await page.route(`${API_ORIGIN}/**`, async route => {
108
+ const request = route.request();
109
+ const url = new URL(request.url());
110
+ const pathname = url.pathname.replace(/^\/+/, '');
111
+ const method = request.method().toUpperCase();
112
+
113
+ if (method === 'OPTIONS') {
114
+ return route.fulfill({status: 204, headers: CORS_HEADERS, body: ''});
115
+ }
116
+ if (pathname === 'themes-colors.css') {
117
+ return route.fulfill({
118
+ status: 200,
119
+ headers: {...CORS_HEADERS, 'content-type': 'text/css; charset=utf-8'},
120
+ body: ':root { --primary: #0ea5e9; }',
121
+ });
122
+ }
123
+ if (pathname === 'runtime/ip') {
124
+ return route.fulfill({
125
+ status: 200,
126
+ headers: jsonHeaders(),
127
+ body: JSON.stringify({ip: '127.0.0.1'}),
128
+ });
129
+ }
130
+ if (pathname === 'menus-people') {
131
+ return route.fulfill({
132
+ status: 200,
133
+ headers: jsonHeaders(),
134
+ body: JSON.stringify({modules: {}}),
135
+ });
136
+ }
137
+ if (pathname === 'people/companies/my') {
138
+ return route.fulfill({
139
+ status: 200,
140
+ headers: jsonHeaders(),
141
+ body: JSON.stringify(collection([company])),
142
+ });
143
+ }
144
+ if (pathname === 'people/company/default') {
145
+ return route.fulfill({
146
+ status: 200,
147
+ headers: jsonHeaders(),
148
+ body: JSON.stringify(company),
149
+ });
150
+ }
151
+ if (pathname === 'configs/discovery-configs') {
152
+ return route.fulfill({
153
+ status: 200,
154
+ headers: jsonHeaders(),
155
+ body: JSON.stringify({configs: {}}),
156
+ });
157
+ }
158
+ if (pathname === 'devices' && method === 'GET') {
159
+ return route.fulfill({
160
+ status: 200,
161
+ headers: jsonHeaders(),
162
+ body: JSON.stringify(collection([currentDevice])),
163
+ });
164
+ }
165
+ if (
166
+ (pathname === `devices/${DEVICE_ENTITY_ID}` ||
167
+ pathname === `devices/${CURRENT_DEVICE_ID}`) &&
168
+ method === 'GET'
169
+ ) {
170
+ return route.fulfill({
171
+ status: 200,
172
+ headers: jsonHeaders(),
173
+ body: JSON.stringify(currentDevice),
174
+ });
175
+ }
176
+ if (pathname === 'device_configs' && method === 'GET') {
177
+ return route.fulfill({
178
+ status: 200,
179
+ headers: jsonHeaders(),
180
+ body: JSON.stringify(collection(deviceConfigs)),
181
+ });
182
+ }
183
+ if (pathname.startsWith('device_configs/') && method === 'GET') {
184
+ const id = Number(pathname.split('/')[1]);
185
+ const found = deviceConfigs.find(c => c.id === id) || pdvConfig;
186
+ return route.fulfill({
187
+ status: 200,
188
+ headers: jsonHeaders(),
189
+ body: JSON.stringify(found),
190
+ });
191
+ }
192
+ return route.fulfill({
193
+ status: 200,
194
+ headers: jsonHeaders(),
195
+ body: JSON.stringify(collection([])),
196
+ });
197
+ });
198
+
199
+ await page.addInitScript(
200
+ ({appVersion}) => {
201
+ localStorage.setItem('token', 'smoke-token-704');
202
+ localStorage.setItem('config', JSON.stringify({language: 'pt-br'}));
203
+ localStorage.setItem(
204
+ 'device',
205
+ JSON.stringify({
206
+ id: 'web-7',
207
+ device: 'web-7',
208
+ type: 'MANAGER',
209
+ appName: 'Browser Manager',
210
+ appVersion,
211
+ buildNumber: appVersion,
212
+ systemName: 'web',
213
+ systemVersion: 'web',
214
+ deviceType: 'web',
215
+ metadata: {runtime: 'web'},
216
+ }),
217
+ );
218
+ },
219
+ {appVersion: APP_VERSION},
220
+ );
221
+ };
222
+
223
+ test.describe('device-detail PDV currentCompany (#704)', () => {
224
+ test.describe.configure({timeout: 60000});
225
+
226
+ test('PDV config 510 of device 403 opens without currentCompany error', async ({
227
+ page,
228
+ }, testInfo) => {
229
+ testInfo.annotations.push({type: 'fluxo', description: FLOW_ID});
230
+ testInfo.annotations.push({
231
+ type: 'flowchartIds',
232
+ description: JSON.stringify(FLOWCHART_IDS),
233
+ });
234
+
235
+ const outputDir = testInfo.outputDir;
236
+ const pageErrors = [];
237
+ page.on('pageerror', err => pageErrors.push(String(err)));
238
+ page.on('console', msg => {
239
+ if (msg.type() === 'error') pageErrors.push(msg.text());
240
+ });
241
+
242
+ await mockDevicesApi(page);
243
+ await page.goto('/devices-index?store=device_config');
244
+ await expect(page.getByTestId(`device-config-${PDV_CONFIG_ID}`)).toBeVisible({
245
+ timeout: 15000,
246
+ });
247
+ await writeEvidence(page, outputDir, '01-lista-devices', 'DevicesIndex');
248
+
249
+ await page.getByTestId(`device-config-${PDV_CONFIG_ID}`).click();
250
+ await expect(page).toHaveURL(/device-detail/, {timeout: 15000});
251
+ await expect(page.getByText('Configuração do PDV')).toBeVisible({
252
+ timeout: 15000,
253
+ });
254
+ await writeEvidence(
255
+ page,
256
+ outputDir,
257
+ '02-detalhe-pdv-510',
258
+ 'DeviceConfig PDV 510 / device 403',
259
+ );
260
+
261
+ const bodyText = await page.locator('body').innerText();
262
+ expect(bodyText).not.toMatch(/currentCompany is not defined/i);
263
+ expect(pageErrors.join('\n')).not.toMatch(/currentCompany is not defined/i);
264
+
265
+ const manifest = writeManifest(outputDir);
266
+ expect(manifest.fluxo).toBe(FLOW_ID);
267
+ expect(manifest.flowchartIds).toEqual(FLOWCHART_IDS);
268
+ expect(manifest.steps.map(s => s.id)).toEqual([
269
+ '01-lista-devices',
270
+ '02-detalhe-pdv-510',
271
+ ]);
272
+ });
273
+ });