@controleonline/ui-common 1.2.88 → 1.2.90

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,3 +1,4 @@
1
+ const {installManagerSession} = require('./managerSession.fixture');
1
2
  const {expect, test} = require('playwright/test');
2
3
  const packageJson = require('../../../../../../../package.json');
3
4
  const {API_ORIGIN} = require('../../../../../../../src/tests/browser/apiOrigin');
@@ -76,6 +77,7 @@ const createDeviceConfig = ({id, type, device = currentDevice, alias}) => ({
76
77
  * (or omit type for All). Multi-type filters expand to sequential single-type GETs.
77
78
  */
78
79
  const mockDevicesTypeFilterApi = async page => {
80
+ await installManagerSession(page);
79
81
  const company = {
80
82
  id: 3,
81
83
  name: 'Teste',
@@ -0,0 +1,28 @@
1
+ // Match the authenticated session contract used by the application shell.
2
+ const installManagerSession = async page => {
3
+ await page.addInitScript(() => {
4
+ localStorage.setItem('session', JSON.stringify({
5
+ id: 7,
6
+ people: '/people/7',
7
+ api_key: 'test-api-key',
8
+ active: 1,
9
+ mycompany: 3,
10
+ roles: ['ROLE_SUPER'],
11
+ name: 'Test User',
12
+ realname: 'Test User',
13
+ username: 'tester',
14
+ }));
15
+ localStorage.setItem('app-type', 'MANAGER');
16
+ localStorage.setItem('translates', JSON.stringify({
17
+ 'pt-br': {companies: {3: {configs: {
18
+ device_label: {currentDevice: 'Este dispositivo'},
19
+ device_action: {
20
+ copyConfigHint: 'Escolha o device origem. As configurações serão aplicadas em',
21
+ copyConfigIdentityHint: 'identidade do destino não muda',
22
+ },
23
+ }}}},
24
+ }));
25
+ });
26
+ };
27
+
28
+ module.exports = {installManagerSession};
@@ -0,0 +1,42 @@
1
+ const React = require('react')
2
+ const renderer = require('react-test-renderer')
3
+ const {jest} = require('@jest/globals')
4
+ global.IS_REACT_ACT_ENVIRONMENT = true
5
+ jest.mock('react-native', () => ({Text: 'Text', View: 'View', Platform: {OS: 'web', select: x => x.web}, StyleSheet: {create: x => x}}))
6
+ jest.mock('../../../react/utils/screenMetrics', () => ({appendScreenMetrics: x => x, hasScreenMetricsChanges: () => false}))
7
+ const Section = require('../../../react/pages/Devices/detail/DeviceChargePermissionSection').default
8
+ const {isOrderChargeEnabled, isPosChargeEntryEnabled} = require('../../../react/config/deviceConfigBootstrap')
9
+ let tree, props
10
+ beforeEach(() => {
11
+ jest.clearAllMocks()
12
+ props = {configs: {'order-charge-enabled': false, 'pos-gateway': 'infinite-pay', 'payment-type-ids': [11]},
13
+ actionsRef: {current: {deviceConfigActions: {addDeviceConfigs: jest.fn(async () => {})}}},
14
+ currentCompany: {id: 3}, deviceString: 'web-10', deviceType: 'PDV', refreshCurrentConfig: jest.fn(),
15
+ showSystemError: jest.fn(), brandColors: {textSecondary: '#555'}, renderSwitchRow: value => React.createElement('Switch', value)}
16
+ })
17
+ afterEach(async () => {if (tree) await renderer.act(async () => tree.unmount()); tree = null})
18
+ it('saves the existing protected financial permission using the current device and company', async () => {
19
+ await renderer.act(async () => {tree = renderer.create(React.createElement(Section, props))})
20
+ await renderer.act(async () => tree.root.findByType('Switch').props.onValueChange(true))
21
+ expect(props.actionsRef.current.deviceConfigActions.addDeviceConfigs).toHaveBeenCalledWith({device: 'web-10', people: '/people/3', type: 'PDV', configs: '{"order-charge-enabled":true}'})
22
+ expect(props.refreshCurrentConfig).toHaveBeenCalledTimes(1)
23
+ expect(props.configs['pos-gateway']).toBe('infinite-pay')
24
+ expect(props.configs['payment-type-ids']).toEqual([11])
25
+ })
26
+ it('preserves the current permission and reports a rejected administrative write', async () => {
27
+ props.actionsRef.current.deviceConfigActions.addDeviceConfigs.mockRejectedValue(new Error('Acesso negado'))
28
+ await renderer.act(async () => {tree = renderer.create(React.createElement(Section, props))})
29
+ await renderer.act(async () => tree.root.findByType('Switch').props.onValueChange(true))
30
+ expect(props.refreshCurrentConfig).not.toHaveBeenCalled()
31
+ expect(tree.root.findByType('Switch').props.value).toBe(false)
32
+ expect(props.showSystemError).toHaveBeenCalledWith(expect.any(Error), expect.any(String))
33
+ })
34
+ it('honors an explicit canonical denial without erasing legacy config decisions', () => {
35
+ const configs = {'pos-operation-mode': 'waiter', 'pos-local-charge-enabled': true, 'order-charge-enabled': false}
36
+ expect(isOrderChargeEnabled(configs)).toBe(false)
37
+ expect(isPosChargeEntryEnabled(configs)).toBe(false)
38
+ expect(isPosChargeEntryEnabled({...configs, 'order-charge-enabled': true})).toBe(true)
39
+ expect(isOrderChargeEnabled('{"order-charge-enabled":"on"}')).toBe(true)
40
+ expect(isOrderChargeEnabled({})).toBe(false)
41
+ expect(configs['pos-local-charge-enabled']).toBe(true)
42
+ })