@dhis2/app-service-offline 3.16.0 → 3.17.0-beta.2
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/build/cjs/__tests__/integration.test.js +19 -29
- package/build/cjs/lib/__tests__/cacheable-section-state.test.js +5 -8
- package/build/cjs/lib/__tests__/clear-sensitive-caches.test.js +1 -4
- package/build/cjs/lib/__tests__/network-status.test.js +13 -34
- package/build/cjs/lib/__tests__/offline-provider.test.js +2 -5
- package/build/cjs/lib/__tests__/use-cacheable-section.test.js +38 -65
- package/build/cjs/lib/__tests__/use-online-status-message.test.js +5 -8
- package/build/cjs/lib/cacheable-section-state.js +11 -15
- package/build/cjs/lib/cacheable-section.js +11 -13
- package/build/cjs/lib/clear-sensitive-caches.js +4 -8
- package/build/cjs/lib/dhis2-connection-status/dev-debug-log.js +2 -2
- package/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js +9 -11
- package/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.test.js +83 -107
- package/build/cjs/lib/dhis2-connection-status/smart-interval.js +7 -8
- package/build/cjs/lib/global-state-service.js +10 -15
- package/build/cjs/lib/network-status.js +4 -6
- package/build/cjs/lib/offline-interface.js +4 -5
- package/build/cjs/lib/offline-provider.js +4 -5
- package/build/cjs/lib/online-status-message.js +3 -4
- package/build/cjs/utils/render-counter.js +4 -5
- package/build/cjs/utils/test-mocks.js +8 -10
- package/build/es/__tests__/integration.test.js +19 -29
- package/build/es/lib/__tests__/cacheable-section-state.test.js +5 -8
- package/build/es/lib/__tests__/clear-sensitive-caches.test.js +1 -4
- package/build/es/lib/__tests__/network-status.test.js +13 -34
- package/build/es/lib/__tests__/offline-provider.test.js +2 -5
- package/build/es/lib/__tests__/use-cacheable-section.test.js +38 -65
- package/build/es/lib/__tests__/use-online-status-message.test.js +5 -8
- package/build/es/lib/cacheable-section-state.js +11 -15
- package/build/es/lib/cacheable-section.js +11 -13
- package/build/es/lib/clear-sensitive-caches.js +4 -8
- package/build/es/lib/dhis2-connection-status/dev-debug-log.js +2 -2
- package/build/es/lib/dhis2-connection-status/dhis2-connection-status.js +9 -11
- package/build/es/lib/dhis2-connection-status/dhis2-connection-status.test.js +83 -107
- package/build/es/lib/dhis2-connection-status/smart-interval.js +7 -8
- package/build/es/lib/global-state-service.js +10 -15
- package/build/es/lib/network-status.js +4 -6
- package/build/es/lib/offline-interface.js +4 -5
- package/build/es/lib/offline-provider.js +4 -5
- package/build/es/lib/online-status-message.js +3 -4
- package/build/es/utils/render-counter.js +4 -5
- package/build/es/utils/test-mocks.js +8 -10
- package/package.json +3 -3
- package/build/cjs/locales/en/translations.json +0 -4
- package/build/cjs/locales/index.js +0 -21
- package/build/es/locales/en/translations.json +0 -4
- package/build/es/locales/index.js +0 -13
|
@@ -11,12 +11,11 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
11
11
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
12
12
|
const renderCounts = {};
|
|
13
13
|
const identity = arg => arg;
|
|
14
|
-
const TestControls =
|
|
14
|
+
const TestControls = ({
|
|
15
|
+
id,
|
|
16
|
+
makeRecordingHandler = identity
|
|
17
|
+
}) => {
|
|
15
18
|
var _lastUpdated$toISOStr;
|
|
16
|
-
let {
|
|
17
|
-
id,
|
|
18
|
-
makeRecordingHandler = identity
|
|
19
|
-
} = _ref;
|
|
20
19
|
const {
|
|
21
20
|
startRecording,
|
|
22
21
|
remove,
|
|
@@ -43,21 +42,18 @@ const TestControls = _ref => {
|
|
|
43
42
|
"data-testid": `recording-state-${id}`
|
|
44
43
|
}, recordingState));
|
|
45
44
|
};
|
|
46
|
-
const TestSection =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
countsObj: renderCounts
|
|
59
|
-
}), children);
|
|
60
|
-
};
|
|
45
|
+
const TestSection = ({
|
|
46
|
+
id,
|
|
47
|
+
children
|
|
48
|
+
}) => /*#__PURE__*/_react2.default.createElement(_cacheableSection.CacheableSection, {
|
|
49
|
+
id: id,
|
|
50
|
+
loadingMask: /*#__PURE__*/_react2.default.createElement("div", {
|
|
51
|
+
"data-testid": `loading-mask-${id}`
|
|
52
|
+
})
|
|
53
|
+
}, /*#__PURE__*/_react2.default.createElement(_renderCounter.RenderCounter, {
|
|
54
|
+
id: `section-rc-${id}`,
|
|
55
|
+
countsObj: renderCounts
|
|
56
|
+
}), children);
|
|
61
57
|
const TestSingleSection = props => {
|
|
62
58
|
// Props are spread so they can be overwritten
|
|
63
59
|
return /*#__PURE__*/_react2.default.createElement(_appServiceAlerts.AlertsProvider, null, /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, _extends({
|
|
@@ -74,11 +70,8 @@ const originalError = console.error;
|
|
|
74
70
|
beforeEach(() => {
|
|
75
71
|
// This is done before each because the 'recording error' test uses its own
|
|
76
72
|
// spy on console.error
|
|
77
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
73
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
78
74
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
79
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
80
|
-
args[_key] = arguments[_key];
|
|
81
|
-
}
|
|
82
75
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
83
76
|
return;
|
|
84
77
|
}
|
|
@@ -88,7 +81,7 @@ beforeEach(() => {
|
|
|
88
81
|
afterEach(() => {
|
|
89
82
|
jest.clearAllMocks()
|
|
90
83
|
// This syntax appeases typescript:
|
|
91
|
-
|
|
84
|
+
;
|
|
92
85
|
console.error.mockRestore();
|
|
93
86
|
(0, _renderCounter.resetRenderCounts)(renderCounts);
|
|
94
87
|
});
|
|
@@ -140,12 +133,9 @@ describe('Coordination between useCacheableSection and CacheableSection', () =>
|
|
|
140
133
|
});
|
|
141
134
|
it('handles a recording that encounters an error', async done => {
|
|
142
135
|
// Suppress the expected error from console (in addition to 'act' warning)
|
|
143
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
136
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
144
137
|
const actPattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
145
138
|
const errPattern = /Error during recording/;
|
|
146
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
147
|
-
args[_key2] = arguments[_key2];
|
|
148
|
-
}
|
|
149
139
|
const matchesPattern = actPattern.test(args[0]) || errPattern.test(args[0]);
|
|
150
140
|
if (typeof args[0] === 'string' && matchesPattern) {
|
|
151
141
|
return;
|
|
@@ -6,14 +6,11 @@ var _testMocks = require("../../utils/test-mocks");
|
|
|
6
6
|
var _cacheableSectionState = require("../cacheable-section-state");
|
|
7
7
|
var _offlineProvider = require("../offline-provider");
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const wrapper =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
offlineInterface: _testMocks.mockOfflineInterface
|
|
15
|
-
}, children);
|
|
16
|
-
};
|
|
9
|
+
const wrapper = ({
|
|
10
|
+
children
|
|
11
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
12
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
13
|
+
}, children);
|
|
17
14
|
test('useRecordingState has stable references', () => {
|
|
18
15
|
const {
|
|
19
16
|
result,
|
|
@@ -30,11 +30,8 @@ afterEach(() => {
|
|
|
30
30
|
// silence debug logs for these tests
|
|
31
31
|
const originalDebug = console.debug;
|
|
32
32
|
beforeAll(() => {
|
|
33
|
-
jest.spyOn(console, 'debug').mockImplementation(
|
|
33
|
+
jest.spyOn(console, 'debug').mockImplementation((...args) => {
|
|
34
34
|
const pattern = /Clearing sensitive caches/;
|
|
35
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
36
|
-
args[_key] = arguments[_key];
|
|
37
|
-
}
|
|
38
35
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
39
36
|
return;
|
|
40
37
|
}
|
|
@@ -41,9 +41,7 @@ describe('state changes in response to browser "online" and "offline" events', (
|
|
|
41
41
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
42
42
|
const {
|
|
43
43
|
result
|
|
44
|
-
} = (0, _react.renderHook)(
|
|
45
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
46
|
-
}, {
|
|
44
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
47
45
|
initialProps: {
|
|
48
46
|
debounceDelay: 50
|
|
49
47
|
}
|
|
@@ -65,9 +63,7 @@ describe('state changes in response to browser "online" and "offline" events', (
|
|
|
65
63
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
66
64
|
const {
|
|
67
65
|
result
|
|
68
|
-
} = (0, _react.renderHook)(
|
|
69
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
70
|
-
}, {
|
|
66
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
71
67
|
initialProps: {
|
|
72
68
|
debounceDelay: 50
|
|
73
69
|
}
|
|
@@ -114,9 +110,7 @@ describe('debouncing state changes', () => {
|
|
|
114
110
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
115
111
|
const {
|
|
116
112
|
result
|
|
117
|
-
} = (0, _react.renderHook)(
|
|
118
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
119
|
-
}, {
|
|
113
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
120
114
|
initialProps: {
|
|
121
115
|
debounceDelay: 50
|
|
122
116
|
}
|
|
@@ -142,9 +136,7 @@ describe('debouncing state changes', () => {
|
|
|
142
136
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
143
137
|
const {
|
|
144
138
|
result
|
|
145
|
-
} = (0, _react.renderHook)(
|
|
146
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
147
|
-
}, {
|
|
139
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
148
140
|
initialProps: {
|
|
149
141
|
debounceDelay: 0
|
|
150
142
|
}
|
|
@@ -170,9 +162,7 @@ describe('debouncing state changes', () => {
|
|
|
170
162
|
const {
|
|
171
163
|
result,
|
|
172
164
|
rerender
|
|
173
|
-
} = (0, _react.renderHook)(
|
|
174
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
175
|
-
}, {
|
|
165
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
176
166
|
initialProps: {
|
|
177
167
|
debounceDelay: 150
|
|
178
168
|
}
|
|
@@ -250,10 +240,9 @@ describe('debouncing state changes', () => {
|
|
|
250
240
|
jest.spyOn(navigator, 'onLine', 'get').mockReturnValueOnce(true);
|
|
251
241
|
const events = {};
|
|
252
242
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
253
|
-
const TestComponent =
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
} = _ref;
|
|
243
|
+
const TestComponent = ({
|
|
244
|
+
options
|
|
245
|
+
}) => {
|
|
257
246
|
const {
|
|
258
247
|
online
|
|
259
248
|
} = (0, _networkStatus.useNetworkStatus)(options);
|
|
@@ -352,9 +341,7 @@ describe('it updates the lastOnline value in local storage', () => {
|
|
|
352
341
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
353
342
|
const {
|
|
354
343
|
result
|
|
355
|
-
} = (0, _react.renderHook)(
|
|
356
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
357
|
-
}, {
|
|
344
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
358
345
|
initialProps: {
|
|
359
346
|
debounceDelay: 0
|
|
360
347
|
}
|
|
@@ -388,9 +375,7 @@ describe('it updates the lastOnline value in local storage', () => {
|
|
|
388
375
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
389
376
|
const {
|
|
390
377
|
result
|
|
391
|
-
} = (0, _react.renderHook)(
|
|
392
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
393
|
-
}, {
|
|
378
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
394
379
|
initialProps: {
|
|
395
380
|
debounceDelay: 0
|
|
396
381
|
}
|
|
@@ -408,9 +393,7 @@ describe('it updates the lastOnline value in local storage', () => {
|
|
|
408
393
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
409
394
|
const {
|
|
410
395
|
result
|
|
411
|
-
} = (0, _react.renderHook)(
|
|
412
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
413
|
-
}, {
|
|
396
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
414
397
|
initialProps: {
|
|
415
398
|
debounceDelay: 0
|
|
416
399
|
}
|
|
@@ -434,9 +417,7 @@ describe('it updates the lastOnline value in local storage', () => {
|
|
|
434
417
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
435
418
|
const {
|
|
436
419
|
result
|
|
437
|
-
} = (0, _react.renderHook)(
|
|
438
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
439
|
-
}, {
|
|
420
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
440
421
|
initialProps: {
|
|
441
422
|
debounceDelay: 0
|
|
442
423
|
}
|
|
@@ -462,9 +443,7 @@ describe('it updates the lastOnline value in local storage', () => {
|
|
|
462
443
|
window.addEventListener = jest.fn((event, cb) => events[event] = cb);
|
|
463
444
|
const {
|
|
464
445
|
result
|
|
465
|
-
} = (0, _react.renderHook)(
|
|
466
|
-
return (0, _networkStatus.useNetworkStatus)(...arguments);
|
|
467
|
-
}, {
|
|
446
|
+
} = (0, _react.renderHook)((...args) => (0, _networkStatus.useNetworkStatus)(...args), {
|
|
468
447
|
initialProps: {
|
|
469
448
|
debounceDelay: 0
|
|
470
449
|
}
|
|
@@ -10,11 +10,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
10
10
|
// Suppress 'act' warning for these tests
|
|
11
11
|
const originalError = console.error;
|
|
12
12
|
beforeEach(() => {
|
|
13
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
13
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
14
14
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
15
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
16
|
-
args[_key] = arguments[_key];
|
|
17
|
-
}
|
|
18
15
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
19
16
|
return;
|
|
20
17
|
}
|
|
@@ -24,7 +21,7 @@ beforeEach(() => {
|
|
|
24
21
|
afterEach(() => {
|
|
25
22
|
jest.clearAllMocks()
|
|
26
23
|
// syntax needed to appease typescript
|
|
27
|
-
|
|
24
|
+
;
|
|
28
25
|
console.error.mockRestore();
|
|
29
26
|
});
|
|
30
27
|
describe('Testing offline provider', () => {
|
|
@@ -9,11 +9,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
9
9
|
// Suppress 'act' warning for these tests
|
|
10
10
|
const originalError = console.error;
|
|
11
11
|
beforeEach(() => {
|
|
12
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
12
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
13
13
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
14
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
15
|
-
args[_key] = arguments[_key];
|
|
16
|
-
}
|
|
17
14
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
18
15
|
return;
|
|
19
16
|
}
|
|
@@ -23,18 +20,15 @@ beforeEach(() => {
|
|
|
23
20
|
afterEach(() => {
|
|
24
21
|
jest.clearAllMocks()
|
|
25
22
|
// This syntax appeases typescript:
|
|
26
|
-
|
|
23
|
+
;
|
|
27
24
|
console.error.mockRestore();
|
|
28
25
|
});
|
|
29
26
|
it('renders in the default state initially', () => {
|
|
30
|
-
const wrapper =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
offlineInterface: _testMocks.mockOfflineInterface
|
|
36
|
-
}, children);
|
|
37
|
-
};
|
|
27
|
+
const wrapper = ({
|
|
28
|
+
children
|
|
29
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
30
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
31
|
+
}, children);
|
|
38
32
|
const {
|
|
39
33
|
result
|
|
40
34
|
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('one'), {
|
|
@@ -45,14 +39,11 @@ it('renders in the default state initially', () => {
|
|
|
45
39
|
expect(result.current.lastUpdated).toBeUndefined();
|
|
46
40
|
});
|
|
47
41
|
it('has stable references', () => {
|
|
48
|
-
const wrapper =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
offlineInterface: _testMocks.mockOfflineInterface
|
|
54
|
-
}, children);
|
|
55
|
-
};
|
|
42
|
+
const wrapper = ({
|
|
43
|
+
children
|
|
44
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
45
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
46
|
+
}, children);
|
|
56
47
|
const {
|
|
57
48
|
result,
|
|
58
49
|
rerender
|
|
@@ -80,14 +71,11 @@ it('handles a successful recording', async done => {
|
|
|
80
71
|
lastUpdated: new Date()
|
|
81
72
|
}])
|
|
82
73
|
};
|
|
83
|
-
const wrapper =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
offlineInterface: recordingSuccessOfflineInterface
|
|
89
|
-
}, children);
|
|
90
|
-
};
|
|
74
|
+
const wrapper = ({
|
|
75
|
+
children
|
|
76
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
77
|
+
offlineInterface: recordingSuccessOfflineInterface
|
|
78
|
+
}, children);
|
|
91
79
|
const {
|
|
92
80
|
result
|
|
93
81
|
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
@@ -138,12 +126,9 @@ it('handles a successful recording', async done => {
|
|
|
138
126
|
});
|
|
139
127
|
it('handles a recording that encounters an error', async done => {
|
|
140
128
|
// Suppress the expected error from console (in addition to 'act' warning)
|
|
141
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
129
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
142
130
|
const actPattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
143
131
|
const errPattern = /Error during recording/;
|
|
144
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
145
|
-
args[_key2] = arguments[_key2];
|
|
146
|
-
}
|
|
147
132
|
const matchesPattern = actPattern.test(args[0]) || errPattern.test(args[0]);
|
|
148
133
|
if (typeof args[0] === 'string' && matchesPattern) {
|
|
149
134
|
return;
|
|
@@ -154,14 +139,11 @@ it('handles a recording that encounters an error', async done => {
|
|
|
154
139
|
..._testMocks.mockOfflineInterface,
|
|
155
140
|
startRecording: _testMocks.errorRecordingMock
|
|
156
141
|
};
|
|
157
|
-
const wrapper =
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
offlineInterface: recordingErrorOfflineInterface
|
|
163
|
-
}, children);
|
|
164
|
-
};
|
|
142
|
+
const wrapper = ({
|
|
143
|
+
children
|
|
144
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
145
|
+
offlineInterface: recordingErrorOfflineInterface
|
|
146
|
+
}, children);
|
|
165
147
|
const {
|
|
166
148
|
result
|
|
167
149
|
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('one'), {
|
|
@@ -199,14 +181,11 @@ it('handles an error starting the recording', async () => {
|
|
|
199
181
|
..._testMocks.mockOfflineInterface,
|
|
200
182
|
startRecording: _testMocks.failedMessageRecordingMock
|
|
201
183
|
};
|
|
202
|
-
const wrapper =
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
offlineInterface: messageErrorOfflineInterface
|
|
208
|
-
}, children);
|
|
209
|
-
};
|
|
184
|
+
const wrapper = ({
|
|
185
|
+
children
|
|
186
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
187
|
+
offlineInterface: messageErrorOfflineInterface
|
|
188
|
+
}, children);
|
|
210
189
|
const {
|
|
211
190
|
result
|
|
212
191
|
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('err'), {
|
|
@@ -224,14 +203,11 @@ it('handles remove and updates sections', async () => {
|
|
|
224
203
|
lastUpdated: new Date()
|
|
225
204
|
}]).mockResolvedValueOnce([])
|
|
226
205
|
};
|
|
227
|
-
const wrapper =
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
offlineInterface: sectionOpsOfflineInterface
|
|
233
|
-
}, children);
|
|
234
|
-
};
|
|
206
|
+
const wrapper = ({
|
|
207
|
+
children
|
|
208
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
209
|
+
offlineInterface: sectionOpsOfflineInterface
|
|
210
|
+
}, children);
|
|
235
211
|
const {
|
|
236
212
|
result
|
|
237
213
|
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
@@ -259,14 +235,11 @@ it('handles a change in ID', async () => {
|
|
|
259
235
|
lastUpdated: new Date()
|
|
260
236
|
}])
|
|
261
237
|
};
|
|
262
|
-
const wrapper =
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
offlineInterface: idChangeOfflineInterface
|
|
268
|
-
}, children);
|
|
269
|
-
};
|
|
238
|
+
const wrapper = ({
|
|
239
|
+
children
|
|
240
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
241
|
+
offlineInterface: idChangeOfflineInterface
|
|
242
|
+
}, children);
|
|
270
243
|
const {
|
|
271
244
|
result,
|
|
272
245
|
rerender
|
|
@@ -8,14 +8,11 @@ var _onlineStatusMessage = require("../online-status-message");
|
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
describe('useOnlineStatusMessage', () => {
|
|
10
10
|
it('should allow the online status to be updated ', () => {
|
|
11
|
-
const wrapper =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
offlineInterface: _testMocks.mockOfflineInterface
|
|
17
|
-
}, children);
|
|
18
|
-
};
|
|
11
|
+
const wrapper = ({
|
|
12
|
+
children
|
|
13
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
14
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
15
|
+
}, children);
|
|
19
16
|
const {
|
|
20
17
|
result
|
|
21
18
|
} = (0, _react.renderHook)(() => (0, _onlineStatusMessage.useOnlineStatusMessage)(), {
|
|
@@ -25,18 +25,15 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
25
25
|
* @returns {Object} An object of sections, keyed by ID
|
|
26
26
|
*/
|
|
27
27
|
function getSectionsById(sectionsArray) {
|
|
28
|
-
return sectionsArray.reduce((result,
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
return sectionsArray.reduce((result, {
|
|
29
|
+
sectionId,
|
|
30
|
+
lastUpdated
|
|
31
|
+
}) => ({
|
|
32
|
+
...result,
|
|
33
|
+
[sectionId]: {
|
|
31
34
|
lastUpdated
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
...result,
|
|
35
|
-
[sectionId]: {
|
|
36
|
-
lastUpdated
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}, {});
|
|
35
|
+
}
|
|
36
|
+
}), {});
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
/**
|
|
@@ -70,10 +67,9 @@ function useConst(factory) {
|
|
|
70
67
|
* determine how that component will render. The provider will be a part of
|
|
71
68
|
* the OfflineProvider.
|
|
72
69
|
*/
|
|
73
|
-
function CacheableSectionProvider(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} = _ref2;
|
|
70
|
+
function CacheableSectionProvider({
|
|
71
|
+
children
|
|
72
|
+
}) {
|
|
77
73
|
const offlineInterface = (0, _offlineInterface.useOfflineInterface)();
|
|
78
74
|
const store = useConst(createCacheableSectionStore);
|
|
79
75
|
|
|
@@ -64,13 +64,12 @@ function useCacheableSection(id) {
|
|
|
64
64
|
console.error('Error during recording:', error);
|
|
65
65
|
setRecordingState(recordingStates.error);
|
|
66
66
|
}, [setRecordingState]);
|
|
67
|
-
const startRecording = (0, _react.useCallback)(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
67
|
+
const startRecording = (0, _react.useCallback)(({
|
|
68
|
+
recordingTimeoutDelay = 1000,
|
|
69
|
+
onStarted,
|
|
70
|
+
onCompleted,
|
|
71
|
+
onError
|
|
72
|
+
} = {}) => {
|
|
74
73
|
// This promise resolving means that the message to the service worker
|
|
75
74
|
// to start recording was successful. Waiting for resolution prevents
|
|
76
75
|
// unnecessarily rerendering the whole component in case of an error
|
|
@@ -121,12 +120,11 @@ function useCacheableSection(id) {
|
|
|
121
120
|
* intended to prevent other interaction with the app that might interfere
|
|
122
121
|
* with the recording process.
|
|
123
122
|
*/
|
|
124
|
-
function CacheableSection(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} = _ref;
|
|
123
|
+
function CacheableSection({
|
|
124
|
+
id,
|
|
125
|
+
loadingMask,
|
|
126
|
+
children
|
|
127
|
+
}) {
|
|
130
128
|
// Accesses recording state that useCacheableSection controls
|
|
131
129
|
const {
|
|
132
130
|
recordingState
|
|
@@ -27,12 +27,9 @@ const clearDB = async dbName => {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
const dbs = await window.indexedDB.databases();
|
|
30
|
-
if (!dbs.some(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} = _ref;
|
|
34
|
-
return name === dbName;
|
|
35
|
-
})) {
|
|
30
|
+
if (!dbs.some(({
|
|
31
|
+
name
|
|
32
|
+
}) => name === dbName)) {
|
|
36
33
|
// Sections-db is not created; nothing to do here
|
|
37
34
|
return;
|
|
38
35
|
}
|
|
@@ -60,8 +57,7 @@ const clearDB = async dbName => {
|
|
|
60
57
|
* different user logs in to prevent someone from accessing a different user's
|
|
61
58
|
* caches. Should be able to be used in a non-PWA app.
|
|
62
59
|
*/
|
|
63
|
-
async function clearSensitiveCaches() {
|
|
64
|
-
let dbName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SECTIONS_DB;
|
|
60
|
+
async function clearSensitiveCaches(dbName = SECTIONS_DB) {
|
|
65
61
|
console.debug('Clearing sensitive caches');
|
|
66
62
|
let cacheKeys;
|
|
67
63
|
|
|
@@ -17,8 +17,8 @@ if (shouldLog) {
|
|
|
17
17
|
* The behavior of the connection status can be quite hard to inspect without
|
|
18
18
|
* logs, but the logs are quite chatty and should be omitted normally.
|
|
19
19
|
*/
|
|
20
|
-
function devDebugLog() {
|
|
20
|
+
function devDebugLog(...args) {
|
|
21
21
|
if (shouldLog) {
|
|
22
|
-
console.log(...
|
|
22
|
+
console.log(...args);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -47,10 +47,9 @@ const Dhis2ConnectionStatusContext = /*#__PURE__*/_react.default.createContext({
|
|
|
47
47
|
* and then will initiate periodic pings if there are no incidental requests in
|
|
48
48
|
* order to check the connection consistently
|
|
49
49
|
*/
|
|
50
|
-
const Dhis2ConnectionStatusProvider =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} = _ref;
|
|
50
|
+
const Dhis2ConnectionStatusProvider = ({
|
|
51
|
+
children
|
|
52
|
+
}) => {
|
|
54
53
|
const offlineInterface = (0, _offlineInterface.useOfflineInterface)();
|
|
55
54
|
const {
|
|
56
55
|
appName,
|
|
@@ -81,7 +80,7 @@ const Dhis2ConnectionStatusProvider = _ref => {
|
|
|
81
80
|
if (newIsConnected !== prevIsConnected) {
|
|
82
81
|
var _smartIntervalRef$cur;
|
|
83
82
|
// if value changed, reset ping interval to initial delay
|
|
84
|
-
(_smartIntervalRef$cur = smartIntervalRef.current) === null || _smartIntervalRef$cur === void 0
|
|
83
|
+
(_smartIntervalRef$cur = smartIntervalRef.current) === null || _smartIntervalRef$cur === void 0 || _smartIntervalRef$cur.reset();
|
|
85
84
|
if (newIsConnected) {
|
|
86
85
|
// Need to clear this here so it doesn't affect another
|
|
87
86
|
// session that starts while offline
|
|
@@ -110,15 +109,14 @@ const Dhis2ConnectionStatusProvider = _ref => {
|
|
|
110
109
|
}, [ping, updateConnectedState]);
|
|
111
110
|
|
|
112
111
|
/** Called when SW reports updates from incidental network traffic */
|
|
113
|
-
const onUpdate = (0, _react.useCallback)(
|
|
112
|
+
const onUpdate = (0, _react.useCallback)(({
|
|
113
|
+
isConnected: newIsConnected
|
|
114
|
+
}) => {
|
|
114
115
|
var _smartIntervalRef$cur2;
|
|
115
|
-
let {
|
|
116
|
-
isConnected: newIsConnected
|
|
117
|
-
} = _ref2;
|
|
118
116
|
(0, _devDebugLog.devDebugLog)('[D2CS] handling update from sw');
|
|
119
117
|
|
|
120
118
|
// Snooze ping timer to reduce pings since we know state from SW
|
|
121
|
-
(_smartIntervalRef$cur2 = smartIntervalRef.current) === null || _smartIntervalRef$cur2 === void 0
|
|
119
|
+
(_smartIntervalRef$cur2 = smartIntervalRef.current) === null || _smartIntervalRef$cur2 === void 0 || _smartIntervalRef$cur2.snooze();
|
|
122
120
|
updateConnectedState(newIsConnected);
|
|
123
121
|
}, [updateConnectedState]);
|
|
124
122
|
(0, _react.useEffect)(() => {
|
|
@@ -163,7 +161,7 @@ const Dhis2ConnectionStatusProvider = _ref => {
|
|
|
163
161
|
var _smartIntervalRef$cur3;
|
|
164
162
|
// Missing this functionality from the offline interface --
|
|
165
163
|
// use a ping on startup to get the status
|
|
166
|
-
(_smartIntervalRef$cur3 = smartIntervalRef.current) === null || _smartIntervalRef$cur3 === void 0
|
|
164
|
+
(_smartIntervalRef$cur3 = smartIntervalRef.current) === null || _smartIntervalRef$cur3 === void 0 || _smartIntervalRef$cur3.invokeCallbackImmediately();
|
|
167
165
|
console.warn('Please upgrade to @dhis2/cli-app-scripts@>10.3.8 for full connection status features');
|
|
168
166
|
return;
|
|
169
167
|
}
|