@dhis2/app-service-offline 3.11.3 → 3.12.0-alpha.1
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 +51 -82
- package/build/cjs/index.js +0 -7
- package/build/cjs/lib/__tests__/cacheable-section-state.test.js +7 -14
- package/build/cjs/lib/__tests__/clear-sensitive-caches.test.js +17 -20
- package/build/cjs/lib/__tests__/network-status.test.js +135 -148
- package/build/cjs/lib/__tests__/offline-provider.test.js +12 -22
- package/build/cjs/lib/__tests__/use-cacheable-section.test.js +87 -98
- package/build/cjs/lib/__tests__/use-online-status-message.test.js +7 -14
- package/build/cjs/lib/cacheable-section-state.js +27 -38
- package/build/cjs/lib/cacheable-section.js +26 -27
- package/build/cjs/lib/clear-sensitive-caches.js +14 -24
- package/build/cjs/lib/dhis2-connection-status/dev-debug-log.js +1 -3
- package/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.js +27 -58
- package/build/cjs/lib/dhis2-connection-status/dhis2-connection-status.test.js +287 -230
- package/build/cjs/lib/dhis2-connection-status/index.js +0 -1
- package/build/cjs/lib/dhis2-connection-status/is-ping-available.js +0 -6
- package/build/cjs/lib/dhis2-connection-status/is-ping-available.test.js +0 -1
- package/build/cjs/lib/dhis2-connection-status/smart-interval.js +35 -49
- package/build/cjs/lib/dhis2-connection-status/use-ping-query.js +4 -5
- package/build/cjs/lib/global-state-service.js +9 -27
- package/build/cjs/lib/network-status.js +10 -13
- package/build/cjs/lib/offline-interface.js +3 -14
- package/build/cjs/lib/offline-provider.js +1 -12
- package/build/cjs/lib/online-status-message.js +5 -17
- package/build/cjs/setupRTL.js +1 -1
- package/build/cjs/utils/__tests__/render-counter.test.js +3 -12
- package/build/cjs/utils/render-counter.js +2 -10
- package/build/cjs/utils/test-mocks.js +13 -18
- package/build/es/__tests__/integration.test.js +51 -74
- package/build/es/index.js +2 -2
- package/build/es/lib/__tests__/cacheable-section-state.test.js +2 -4
- package/build/es/lib/__tests__/clear-sensitive-caches.test.js +19 -16
- package/build/es/lib/__tests__/network-status.test.js +105 -114
- package/build/es/lib/__tests__/offline-provider.test.js +13 -15
- package/build/es/lib/__tests__/use-cacheable-section.test.js +69 -73
- package/build/es/lib/__tests__/use-online-status-message.test.js +2 -3
- package/build/es/lib/cacheable-section-state.js +25 -26
- package/build/es/lib/cacheable-section.js +23 -15
- package/build/es/lib/clear-sensitive-caches.js +13 -21
- package/build/es/lib/dhis2-connection-status/dev-debug-log.js +1 -3
- package/build/es/lib/dhis2-connection-status/dhis2-connection-status.js +26 -37
- package/build/es/lib/dhis2-connection-status/dhis2-connection-status.test.js +223 -159
- package/build/es/lib/dhis2-connection-status/is-ping-available.js +0 -5
- package/build/es/lib/dhis2-connection-status/smart-interval.js +34 -42
- package/build/es/lib/dhis2-connection-status/use-ping-query.js +6 -3
- package/build/es/lib/global-state-service.js +6 -12
- package/build/es/lib/network-status.js +10 -9
- package/build/es/lib/offline-interface.js +0 -3
- package/build/es/lib/offline-provider.js +0 -3
- package/build/es/lib/online-status-message.js +3 -2
- package/build/es/setupRTL.js +1 -1
- package/build/es/utils/__tests__/render-counter.test.js +2 -4
- package/build/es/utils/render-counter.js +1 -3
- package/build/es/utils/test-mocks.js +8 -9
- package/build/types/lib/cacheable-section.d.ts +1 -1
- package/build/types/lib/dhis2-connection-status/dhis2-connection-status.d.ts +1 -1
- package/build/types/lib/network-status.d.ts +1 -1
- package/build/types/lib/online-status-message.d.ts +1 -1
- package/build/types/types.d.ts +1 -1
- package/package.json +4 -4
|
@@ -1,44 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _react = require("@testing-library/react");
|
|
4
|
-
|
|
5
4
|
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
7
5
|
var _testMocks = require("../../utils/test-mocks");
|
|
8
|
-
|
|
9
6
|
var _cacheableSection = require("../cacheable-section");
|
|
10
|
-
|
|
11
7
|
var _cacheableSectionState = require("../cacheable-section-state");
|
|
12
|
-
|
|
13
8
|
var _offlineProvider = require("../offline-provider");
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
10
|
// Suppress 'act' warning for these tests
|
|
18
11
|
const originalError = console.error;
|
|
19
12
|
beforeEach(() => {
|
|
20
13
|
jest.spyOn(console, 'error').mockImplementation(function () {
|
|
21
14
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
22
|
-
|
|
23
15
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24
16
|
args[_key] = arguments[_key];
|
|
25
17
|
}
|
|
26
|
-
|
|
27
18
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
28
19
|
return;
|
|
29
20
|
}
|
|
30
|
-
|
|
31
21
|
return originalError.call(console, ...args);
|
|
32
22
|
});
|
|
33
23
|
});
|
|
34
24
|
afterEach(() => {
|
|
35
|
-
jest.clearAllMocks()
|
|
25
|
+
jest.clearAllMocks()
|
|
26
|
+
// syntax needed to appease typescript
|
|
36
27
|
;
|
|
37
28
|
console.error.mockRestore();
|
|
38
29
|
});
|
|
39
30
|
describe('Testing offline provider', () => {
|
|
40
31
|
it('Should render without failing', () => {
|
|
41
|
-
(0, _react.render)(
|
|
32
|
+
(0, _react.render)(/*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
42
33
|
offlineInterface: _testMocks.mockOfflineInterface
|
|
43
34
|
}, /*#__PURE__*/_react2.default.createElement("div", {
|
|
44
35
|
"data-testid": "test-div"
|
|
@@ -46,7 +37,8 @@ describe('Testing offline provider', () => {
|
|
|
46
37
|
expect(_react.screen.getByTestId('test-div')).toBeInTheDocument();
|
|
47
38
|
});
|
|
48
39
|
it('Should sync cached sections with indexedDB', async () => {
|
|
49
|
-
const testOfflineInterface = {
|
|
40
|
+
const testOfflineInterface = {
|
|
41
|
+
..._testMocks.mockOfflineInterface,
|
|
50
42
|
getCachedSections: jest.fn().mockResolvedValue([{
|
|
51
43
|
sectionId: '1',
|
|
52
44
|
lastUpdated: 'date1'
|
|
@@ -55,7 +47,6 @@ describe('Testing offline provider', () => {
|
|
|
55
47
|
lastUpdated: 'date2'
|
|
56
48
|
}])
|
|
57
49
|
};
|
|
58
|
-
|
|
59
50
|
const CachedSections = () => {
|
|
60
51
|
const {
|
|
61
52
|
cachedSections
|
|
@@ -64,8 +55,7 @@ describe('Testing offline provider', () => {
|
|
|
64
55
|
"data-testid": "sections"
|
|
65
56
|
}, JSON.stringify(cachedSections));
|
|
66
57
|
};
|
|
67
|
-
|
|
68
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
58
|
+
(0, _react.render)(/*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
69
59
|
offlineInterface: testOfflineInterface
|
|
70
60
|
}, /*#__PURE__*/_react2.default.createElement(CachedSections, null)));
|
|
71
61
|
const {
|
|
@@ -93,23 +83,23 @@ describe('Testing offline provider', () => {
|
|
|
93
83
|
"data-testid": "test-div"
|
|
94
84
|
}));
|
|
95
85
|
};
|
|
96
|
-
|
|
97
|
-
(0, _react.render)( /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
86
|
+
(0, _react.render)(/*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
98
87
|
offlineInterface: _testMocks.mockOfflineInterface
|
|
99
88
|
}, /*#__PURE__*/_react2.default.createElement(TestConsumer, null)));
|
|
100
89
|
expect(_react.screen.getByTestId('test-div')).toBeInTheDocument();
|
|
101
90
|
});
|
|
102
91
|
it('Should render without failing when no offlineInterface is provided', () => {
|
|
103
|
-
(0, _react.render)(
|
|
92
|
+
(0, _react.render)(/*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, null, /*#__PURE__*/_react2.default.createElement("div", {
|
|
104
93
|
"data-testid": "test-div"
|
|
105
94
|
})));
|
|
106
95
|
expect(_react.screen.getByTestId('test-div')).toBeInTheDocument();
|
|
107
96
|
});
|
|
108
97
|
it('Should render without failing if PWA is not enabled', () => {
|
|
109
|
-
const testOfflineInterface = {
|
|
98
|
+
const testOfflineInterface = {
|
|
99
|
+
..._testMocks.mockOfflineInterface,
|
|
110
100
|
pwaEnabled: false
|
|
111
101
|
};
|
|
112
|
-
(0, _react.render)(
|
|
102
|
+
(0, _react.render)(/*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
113
103
|
offlineInterface: testOfflineInterface
|
|
114
104
|
}, /*#__PURE__*/_react2.default.createElement("div", {
|
|
115
105
|
"data-testid": "test-div"
|
|
@@ -1,52 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var _react = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
7
5
|
var _testMocks = require("../../utils/test-mocks");
|
|
8
|
-
|
|
9
6
|
var _cacheableSection = require("../cacheable-section");
|
|
10
|
-
|
|
11
7
|
var _offlineProvider = require("../offline-provider");
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
9
|
// Suppress 'act' warning for these tests
|
|
16
10
|
const originalError = console.error;
|
|
17
11
|
beforeEach(() => {
|
|
18
12
|
jest.spyOn(console, 'error').mockImplementation(function () {
|
|
19
13
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
20
|
-
|
|
21
14
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
15
|
args[_key] = arguments[_key];
|
|
23
16
|
}
|
|
24
|
-
|
|
25
17
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
26
18
|
return;
|
|
27
19
|
}
|
|
28
|
-
|
|
29
20
|
return originalError.call(console, ...args);
|
|
30
21
|
});
|
|
31
22
|
});
|
|
32
23
|
afterEach(() => {
|
|
33
|
-
jest.clearAllMocks()
|
|
24
|
+
jest.clearAllMocks()
|
|
25
|
+
// This syntax appeases typescript:
|
|
34
26
|
;
|
|
35
27
|
console.error.mockRestore();
|
|
36
28
|
});
|
|
37
29
|
it('renders in the default state initially', () => {
|
|
38
|
-
const wrapper =
|
|
30
|
+
const wrapper = _ref => {
|
|
39
31
|
let {
|
|
40
32
|
children
|
|
41
33
|
} = _ref;
|
|
42
|
-
return /*#__PURE__*/
|
|
34
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
43
35
|
offlineInterface: _testMocks.mockOfflineInterface
|
|
44
36
|
}, children);
|
|
45
37
|
};
|
|
46
|
-
|
|
47
38
|
const {
|
|
48
39
|
result
|
|
49
|
-
} = (0,
|
|
40
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('one'), {
|
|
50
41
|
wrapper
|
|
51
42
|
});
|
|
52
43
|
expect(result.current.recordingState).toBe('default');
|
|
@@ -54,19 +45,18 @@ it('renders in the default state initially', () => {
|
|
|
54
45
|
expect(result.current.lastUpdated).toBeUndefined();
|
|
55
46
|
});
|
|
56
47
|
it('has stable references', () => {
|
|
57
|
-
const wrapper =
|
|
48
|
+
const wrapper = _ref2 => {
|
|
58
49
|
let {
|
|
59
50
|
children
|
|
60
51
|
} = _ref2;
|
|
61
|
-
return /*#__PURE__*/
|
|
52
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
62
53
|
offlineInterface: _testMocks.mockOfflineInterface
|
|
63
54
|
}, children);
|
|
64
55
|
};
|
|
65
|
-
|
|
66
56
|
const {
|
|
67
57
|
result,
|
|
68
58
|
rerender
|
|
69
|
-
} = (0,
|
|
59
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('one'), {
|
|
70
60
|
wrapper
|
|
71
61
|
});
|
|
72
62
|
const origRecordingState = result.current.recordingState;
|
|
@@ -83,61 +73,67 @@ it('has stable references', () => {
|
|
|
83
73
|
});
|
|
84
74
|
it('handles a successful recording', async done => {
|
|
85
75
|
const [sectionId, timeoutDelay] = ['one', 1234];
|
|
86
|
-
const
|
|
76
|
+
const recordingSuccessOfflineInterface = {
|
|
77
|
+
..._testMocks.mockOfflineInterface,
|
|
87
78
|
getCachedSections: jest.fn().mockResolvedValueOnce([]).mockResolvedValueOnce([{
|
|
88
79
|
sectionId: sectionId,
|
|
89
80
|
lastUpdated: new Date()
|
|
90
81
|
}])
|
|
91
82
|
};
|
|
92
|
-
|
|
93
|
-
const wrapper = (_ref3) => {
|
|
83
|
+
const wrapper = _ref3 => {
|
|
94
84
|
let {
|
|
95
85
|
children
|
|
96
86
|
} = _ref3;
|
|
97
|
-
return /*#__PURE__*/
|
|
98
|
-
offlineInterface:
|
|
87
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
88
|
+
offlineInterface: recordingSuccessOfflineInterface
|
|
99
89
|
}, children);
|
|
100
90
|
};
|
|
101
|
-
|
|
102
91
|
const {
|
|
103
|
-
result
|
|
104
|
-
|
|
105
|
-
} = (0, _reactHooks.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
92
|
+
result
|
|
93
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
106
94
|
wrapper
|
|
107
95
|
});
|
|
108
|
-
|
|
109
96
|
const assertRecordingStarted = () => {
|
|
110
97
|
expect(result.current.recordingState).toBe('recording');
|
|
111
98
|
};
|
|
112
|
-
|
|
113
99
|
const assertRecordingCompleted = async () => {
|
|
114
|
-
expect(result.current.recordingState).toBe('default');
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
100
|
+
expect(result.current.recordingState).toBe('default');
|
|
101
|
+
|
|
102
|
+
// Test that 'isCached' gets updated
|
|
103
|
+
expect(recordingSuccessOfflineInterface.getCachedSections).toBeCalledTimes(2);
|
|
104
|
+
// Recording states are updated synchronously, but getting isCached
|
|
105
|
+
// state is asynchronous -- need to wait for that here.
|
|
106
|
+
// An assertion is not used as the waitFor condition because it may skew
|
|
107
|
+
// the total number assertions in this test if it needs to retry. Number
|
|
108
|
+
// of assertions is checked at the bottom of this test to make sure both
|
|
109
|
+
// of these callbacks are called.
|
|
110
|
+
await (0, _react.waitFor)(() => result.current.isCached === true);
|
|
118
111
|
expect(result.current.isCached).toBe(true);
|
|
119
|
-
expect(result.current.lastUpdated).toBeInstanceOf(Date);
|
|
112
|
+
expect(result.current.lastUpdated).toBeInstanceOf(Date);
|
|
120
113
|
|
|
114
|
+
// If this cb is not called, test should time out and fail
|
|
121
115
|
done();
|
|
122
116
|
};
|
|
123
|
-
|
|
124
|
-
await (0, _reactHooks.act)(async () => {
|
|
117
|
+
await (0, _react.act)(async () => {
|
|
125
118
|
await result.current.startRecording({
|
|
126
119
|
onStarted: assertRecordingStarted,
|
|
127
120
|
onCompleted: assertRecordingCompleted,
|
|
128
121
|
recordingTimeoutDelay: timeoutDelay
|
|
129
122
|
});
|
|
130
|
-
});
|
|
123
|
+
});
|
|
131
124
|
|
|
132
|
-
|
|
125
|
+
// At this stage, recording should be 'pending'
|
|
126
|
+
expect(result.current.recordingState).toBe('pending');
|
|
133
127
|
|
|
128
|
+
// Check correct options sent to offline interface
|
|
134
129
|
const options = _testMocks.mockOfflineInterface.startRecording.mock.calls[0][0];
|
|
135
130
|
expect(options.sectionId).toBe(sectionId);
|
|
136
131
|
expect(options.recordingTimeoutDelay).toBe(timeoutDelay);
|
|
137
132
|
expect(typeof options.onStarted).toBe('function');
|
|
138
133
|
expect(typeof options.onCompleted).toBe('function');
|
|
139
|
-
expect(typeof options.onError).toBe('function');
|
|
134
|
+
expect(typeof options.onError).toBe('function');
|
|
140
135
|
|
|
136
|
+
// Make sure all async assertions are called
|
|
141
137
|
expect.assertions(11);
|
|
142
138
|
});
|
|
143
139
|
it('handles a recording that encounters an error', async done => {
|
|
@@ -145,81 +141,75 @@ it('handles a recording that encounters an error', async done => {
|
|
|
145
141
|
jest.spyOn(console, 'error').mockImplementation(function () {
|
|
146
142
|
const actPattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
147
143
|
const errPattern = /Error during recording/;
|
|
148
|
-
|
|
149
144
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
150
145
|
args[_key2] = arguments[_key2];
|
|
151
146
|
}
|
|
152
|
-
|
|
153
147
|
const matchesPattern = actPattern.test(args[0]) || errPattern.test(args[0]);
|
|
154
|
-
|
|
155
148
|
if (typeof args[0] === 'string' && matchesPattern) {
|
|
156
149
|
return;
|
|
157
150
|
}
|
|
158
|
-
|
|
159
151
|
return originalError.call(console, ...args);
|
|
160
152
|
});
|
|
161
|
-
const
|
|
153
|
+
const recordingErrorOfflineInterface = {
|
|
154
|
+
..._testMocks.mockOfflineInterface,
|
|
162
155
|
startRecording: _testMocks.errorRecordingMock
|
|
163
156
|
};
|
|
164
|
-
|
|
165
|
-
const wrapper = (_ref4) => {
|
|
157
|
+
const wrapper = _ref4 => {
|
|
166
158
|
let {
|
|
167
159
|
children
|
|
168
160
|
} = _ref4;
|
|
169
|
-
return /*#__PURE__*/
|
|
170
|
-
offlineInterface:
|
|
161
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
162
|
+
offlineInterface: recordingErrorOfflineInterface
|
|
171
163
|
}, children);
|
|
172
164
|
};
|
|
173
|
-
|
|
174
165
|
const {
|
|
175
166
|
result
|
|
176
|
-
} = (0,
|
|
167
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('one'), {
|
|
177
168
|
wrapper
|
|
178
169
|
});
|
|
179
|
-
|
|
180
170
|
const assertRecordingStarted = () => {
|
|
181
171
|
expect(result.current.recordingState).toBe('recording');
|
|
182
172
|
};
|
|
183
|
-
|
|
184
173
|
const assertRecordingError = error => {
|
|
185
174
|
expect(result.current.recordingState).toBe('error');
|
|
186
175
|
expect(error.message).toMatch(/test err/); // see errorRecordingMock
|
|
176
|
+
expect(console.error).toHaveBeenCalledWith('Error during recording:', error);
|
|
187
177
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
expect(_testMocks.mockOfflineInterface.getCachedSections).toBeCalledTimes(1); // If this cb is not called, test should time out and fail
|
|
178
|
+
// Expect only one call, from initialization:
|
|
179
|
+
expect(_testMocks.mockOfflineInterface.getCachedSections).toBeCalledTimes(1);
|
|
191
180
|
|
|
181
|
+
// If this cb is not called, test should time out and fail
|
|
192
182
|
done();
|
|
193
183
|
};
|
|
194
|
-
|
|
195
|
-
await (0, _reactHooks.act)(async () => {
|
|
184
|
+
await (0, _react.act)(async () => {
|
|
196
185
|
await result.current.startRecording({
|
|
197
186
|
onStarted: assertRecordingStarted,
|
|
198
187
|
onError: assertRecordingError
|
|
199
188
|
});
|
|
200
|
-
});
|
|
189
|
+
});
|
|
201
190
|
|
|
202
|
-
|
|
191
|
+
// At this stage, recording should be 'pending'
|
|
192
|
+
expect(result.current.recordingState).toBe('pending');
|
|
203
193
|
|
|
194
|
+
// Make sure all async assertions are called
|
|
204
195
|
expect.assertions(6);
|
|
205
196
|
});
|
|
206
197
|
it('handles an error starting the recording', async () => {
|
|
207
|
-
const
|
|
198
|
+
const messageErrorOfflineInterface = {
|
|
199
|
+
..._testMocks.mockOfflineInterface,
|
|
208
200
|
startRecording: _testMocks.failedMessageRecordingMock
|
|
209
201
|
};
|
|
210
|
-
|
|
211
|
-
const wrapper = (_ref5) => {
|
|
202
|
+
const wrapper = _ref5 => {
|
|
212
203
|
let {
|
|
213
204
|
children
|
|
214
205
|
} = _ref5;
|
|
215
|
-
return /*#__PURE__*/
|
|
216
|
-
offlineInterface:
|
|
206
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
207
|
+
offlineInterface: messageErrorOfflineInterface
|
|
217
208
|
}, children);
|
|
218
209
|
};
|
|
219
|
-
|
|
220
210
|
const {
|
|
221
211
|
result
|
|
222
|
-
} = (0,
|
|
212
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)('err'), {
|
|
223
213
|
wrapper
|
|
224
214
|
});
|
|
225
215
|
await expect(result.current.startRecording()).rejects.toThrow('Failed message' // from failedMessageRecordingMock
|
|
@@ -227,72 +217,71 @@ it('handles an error starting the recording', async () => {
|
|
|
227
217
|
});
|
|
228
218
|
it('handles remove and updates sections', async () => {
|
|
229
219
|
const sectionId = 'one';
|
|
230
|
-
const
|
|
220
|
+
const sectionOpsOfflineInterface = {
|
|
221
|
+
..._testMocks.mockOfflineInterface,
|
|
231
222
|
getCachedSections: jest.fn().mockResolvedValueOnce([{
|
|
232
223
|
sectionId: sectionId,
|
|
233
224
|
lastUpdated: new Date()
|
|
234
225
|
}]).mockResolvedValueOnce([])
|
|
235
226
|
};
|
|
236
|
-
|
|
237
|
-
const wrapper = (_ref6) => {
|
|
227
|
+
const wrapper = _ref6 => {
|
|
238
228
|
let {
|
|
239
229
|
children
|
|
240
230
|
} = _ref6;
|
|
241
|
-
return /*#__PURE__*/
|
|
242
|
-
offlineInterface:
|
|
231
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
232
|
+
offlineInterface: sectionOpsOfflineInterface
|
|
243
233
|
}, children);
|
|
244
234
|
};
|
|
245
|
-
|
|
246
235
|
const {
|
|
247
|
-
result
|
|
248
|
-
|
|
249
|
-
} = (0, _reactHooks.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
236
|
+
result
|
|
237
|
+
} = (0, _react.renderHook)(() => (0, _cacheableSection.useCacheableSection)(sectionId), {
|
|
250
238
|
wrapper
|
|
251
|
-
});
|
|
239
|
+
});
|
|
252
240
|
|
|
253
|
-
|
|
241
|
+
// Wait for state to sync with indexedDB
|
|
242
|
+
await (0, _react.waitFor)(() => expect(result.current.isCached).toBe(true));
|
|
254
243
|
let success;
|
|
255
|
-
await (0,
|
|
244
|
+
await (0, _react.act)(async () => {
|
|
256
245
|
success = await result.current.remove();
|
|
257
246
|
});
|
|
258
|
-
expect(success).toBe(true);
|
|
259
|
-
|
|
260
|
-
expect(
|
|
261
|
-
await waitFor(() => result.current.isCached
|
|
247
|
+
expect(success).toBe(true);
|
|
248
|
+
// Test that 'isCached' gets updated
|
|
249
|
+
expect(sectionOpsOfflineInterface.getCachedSections).toBeCalledTimes(2);
|
|
250
|
+
await (0, _react.waitFor)(() => expect(result.current.isCached).toBe(false));
|
|
262
251
|
expect(result.current.isCached).toBe(false);
|
|
263
252
|
expect(result.current.lastUpdated).toBeUndefined();
|
|
264
253
|
});
|
|
265
254
|
it('handles a change in ID', async () => {
|
|
266
|
-
const
|
|
255
|
+
const idChangeOfflineInterface = {
|
|
256
|
+
..._testMocks.mockOfflineInterface,
|
|
267
257
|
getCachedSections: jest.fn().mockResolvedValue([{
|
|
268
258
|
sectionId: 'id-one',
|
|
269
259
|
lastUpdated: new Date()
|
|
270
260
|
}])
|
|
271
261
|
};
|
|
272
|
-
|
|
273
|
-
const wrapper = (_ref7) => {
|
|
262
|
+
const wrapper = _ref7 => {
|
|
274
263
|
let {
|
|
275
264
|
children
|
|
276
265
|
} = _ref7;
|
|
277
|
-
return /*#__PURE__*/
|
|
278
|
-
offlineInterface:
|
|
266
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
267
|
+
offlineInterface: idChangeOfflineInterface
|
|
279
268
|
}, children);
|
|
280
269
|
};
|
|
281
|
-
|
|
282
270
|
const {
|
|
283
271
|
result,
|
|
284
|
-
waitFor,
|
|
285
272
|
rerender
|
|
286
|
-
} = (0,
|
|
273
|
+
} = (0, _react.renderHook)(id => (0, _cacheableSection.useCacheableSection)(id), {
|
|
287
274
|
wrapper,
|
|
288
275
|
initialProps: 'id-one'
|
|
289
|
-
});
|
|
276
|
+
});
|
|
290
277
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
278
|
+
// Wait for state to sync with indexedDB
|
|
279
|
+
await (0, _react.waitFor)(() => expect(result.current.isCached).toBe(true));
|
|
280
|
+
rerender('id-two');
|
|
294
281
|
|
|
295
|
-
|
|
282
|
+
// Test that 'isCached' gets updated
|
|
283
|
+
// expect(idChangeOfflineInterface.getCachedSections).toBeCalledTimes(2)
|
|
284
|
+
await (0, _react.waitFor)(() => expect(result.current.isCached).toBe(false));
|
|
296
285
|
expect(result.current.isCached).toBe(false);
|
|
297
286
|
expect(result.current.lastUpdated).toBeUndefined();
|
|
298
287
|
});
|
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var _react = _interopRequireDefault(require("react"));
|
|
6
|
-
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
7
5
|
var _testMocks = require("../../utils/test-mocks");
|
|
8
|
-
|
|
9
6
|
var _offlineProvider = require("../offline-provider");
|
|
10
|
-
|
|
11
7
|
var _onlineStatusMessage = require("../online-status-message");
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
9
|
describe('useOnlineStatusMessage', () => {
|
|
16
10
|
it('should allow the online status to be updated ', () => {
|
|
17
|
-
const wrapper =
|
|
11
|
+
const wrapper = _ref => {
|
|
18
12
|
let {
|
|
19
13
|
children
|
|
20
14
|
} = _ref;
|
|
21
|
-
return /*#__PURE__*/
|
|
15
|
+
return /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
22
16
|
offlineInterface: _testMocks.mockOfflineInterface
|
|
23
17
|
}, children);
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
const {
|
|
27
20
|
result
|
|
28
|
-
} = (0,
|
|
21
|
+
} = (0, _react.renderHook)(() => (0, _onlineStatusMessage.useOnlineStatusMessage)(), {
|
|
29
22
|
wrapper
|
|
30
23
|
});
|
|
31
24
|
expect(result.current.onlineStatusMessage).toBeUndefined();
|
|
32
|
-
(0,
|
|
25
|
+
(0, _react.act)(() => {
|
|
33
26
|
result.current.setOnlineStatusMessage('8 offline events');
|
|
34
27
|
});
|
|
35
28
|
expect(result.current.onlineStatusMessage).toEqual('8 offline events');
|