@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
|
@@ -31,26 +31,23 @@ const FOURTH_INTERVAL_MS = THIRD_INTERVAL_MS * _smartInterval.DEFAULT_INCREMENT_
|
|
|
31
31
|
// N >= (ln (maxDelay / initialDelay) / ln (incrementFactor)) + 1
|
|
32
32
|
// => then use Math.ceil to handle the 'greater than' effect
|
|
33
33
|
const INTERVALS_TO_REACH_MAX_DELAY = Math.ceil(Math.log(_smartInterval.DEFAULT_MAX_DELAY_MS / _smartInterval.DEFAULT_INITIAL_DELAY_MS) / Math.log(_smartInterval.DEFAULT_INCREMENT_FACTOR) + 1);
|
|
34
|
-
const wrapper =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
patch: 0,
|
|
47
|
-
full: 'n/a'
|
|
48
|
-
}
|
|
34
|
+
const wrapper = ({
|
|
35
|
+
children
|
|
36
|
+
}) => /*#__PURE__*/_react2.default.createElement(_appServiceConfig.ConfigProvider, {
|
|
37
|
+
config: {
|
|
38
|
+
baseUrl: '..',
|
|
39
|
+
apiVersion: 42,
|
|
40
|
+
// ensure this is a server version where pings are enabled
|
|
41
|
+
serverVersion: {
|
|
42
|
+
major: 2,
|
|
43
|
+
minor: 40,
|
|
44
|
+
patch: 0,
|
|
45
|
+
full: 'n/a'
|
|
49
46
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
49
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
50
|
+
}, children));
|
|
54
51
|
|
|
55
52
|
/**
|
|
56
53
|
* Assert on the delay of the last time setTimeoutSpy was called with
|
|
@@ -105,14 +102,11 @@ describe('initialization to the right values based on offline interface', () =>
|
|
|
105
102
|
..._testMocks.mockOfflineInterface,
|
|
106
103
|
latestIsConnected: false
|
|
107
104
|
};
|
|
108
|
-
const customWrapper =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
offlineInterface: customMockOfflineInterface
|
|
114
|
-
}, children);
|
|
115
|
-
};
|
|
105
|
+
const customWrapper = ({
|
|
106
|
+
children
|
|
107
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
108
|
+
offlineInterface: customMockOfflineInterface
|
|
109
|
+
}, children);
|
|
116
110
|
const {
|
|
117
111
|
result
|
|
118
112
|
} = (0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -137,14 +131,11 @@ describe('initialization to the right values based on offline interface', () =>
|
|
|
137
131
|
..._testMocks.mockOfflineInterface,
|
|
138
132
|
latestIsConnected: null
|
|
139
133
|
};
|
|
140
|
-
const customWrapper =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
offlineInterface: customMockOfflineInterface
|
|
146
|
-
}, children);
|
|
147
|
-
};
|
|
134
|
+
const customWrapper = ({
|
|
135
|
+
children
|
|
136
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
137
|
+
offlineInterface: customMockOfflineInterface
|
|
138
|
+
}, children);
|
|
148
139
|
const {
|
|
149
140
|
result
|
|
150
141
|
} = (0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -689,14 +680,11 @@ describe('lastConnected status', () => {
|
|
|
689
680
|
..._testMocks.mockOfflineInterface,
|
|
690
681
|
latestIsConnected: false
|
|
691
682
|
};
|
|
692
|
-
const customWrapper =
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
offlineInterface: customMockOfflineInterface
|
|
698
|
-
}, children);
|
|
699
|
-
};
|
|
683
|
+
const customWrapper = ({
|
|
684
|
+
children
|
|
685
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
686
|
+
offlineInterface: customMockOfflineInterface
|
|
687
|
+
}, children);
|
|
700
688
|
|
|
701
689
|
// render hook with custom wrapper
|
|
702
690
|
(0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -716,14 +704,11 @@ describe('lastConnected status', () => {
|
|
|
716
704
|
..._testMocks.mockOfflineInterface,
|
|
717
705
|
latestIsConnected: false
|
|
718
706
|
};
|
|
719
|
-
const customWrapper =
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
offlineInterface: customMockOfflineInterface
|
|
725
|
-
}, children);
|
|
726
|
-
};
|
|
707
|
+
const customWrapper = ({
|
|
708
|
+
children
|
|
709
|
+
}) => /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
710
|
+
offlineInterface: customMockOfflineInterface
|
|
711
|
+
}, children);
|
|
727
712
|
const {
|
|
728
713
|
result
|
|
729
714
|
} = (0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -747,25 +732,22 @@ describe('lastConnected status', () => {
|
|
|
747
732
|
..._testMocks.mockOfflineInterface,
|
|
748
733
|
latestIsConnected: false
|
|
749
734
|
};
|
|
750
|
-
const customWrapper =
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
patch: 0,
|
|
762
|
-
full: 'n/a'
|
|
763
|
-
}
|
|
735
|
+
const customWrapper = ({
|
|
736
|
+
children
|
|
737
|
+
}) => /*#__PURE__*/_react2.default.createElement(_appServiceConfig.ConfigProvider, {
|
|
738
|
+
config: {
|
|
739
|
+
baseUrl: '..',
|
|
740
|
+
apiVersion: 42,
|
|
741
|
+
serverVersion: {
|
|
742
|
+
major: 2,
|
|
743
|
+
minor: 40,
|
|
744
|
+
patch: 0,
|
|
745
|
+
full: 'n/a'
|
|
764
746
|
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
};
|
|
747
|
+
}
|
|
748
|
+
}, /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
749
|
+
offlineInterface: customMockOfflineInterface
|
|
750
|
+
}, children));
|
|
769
751
|
const {
|
|
770
752
|
result
|
|
771
753
|
} = (0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -813,26 +795,23 @@ describe('lastConnected status', () => {
|
|
|
813
795
|
..._testMocks.mockOfflineInterface,
|
|
814
796
|
latestIsConnected: false
|
|
815
797
|
};
|
|
816
|
-
const customWrapper =
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
patch: 0,
|
|
829
|
-
full: 'n/a'
|
|
830
|
-
}
|
|
798
|
+
const customWrapper = ({
|
|
799
|
+
children
|
|
800
|
+
}) => /*#__PURE__*/_react2.default.createElement(_appServiceConfig.ConfigProvider, {
|
|
801
|
+
config: {
|
|
802
|
+
baseUrl: '..',
|
|
803
|
+
apiVersion: 42,
|
|
804
|
+
appName: testAppName,
|
|
805
|
+
serverVersion: {
|
|
806
|
+
major: 2,
|
|
807
|
+
minor: 40,
|
|
808
|
+
patch: 0,
|
|
809
|
+
full: 'n/a'
|
|
831
810
|
}
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
};
|
|
811
|
+
}
|
|
812
|
+
}, /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
813
|
+
offlineInterface: customMockOfflineInterface
|
|
814
|
+
}, children));
|
|
836
815
|
const {
|
|
837
816
|
result
|
|
838
817
|
} = (0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -862,26 +841,23 @@ describe('lastConnected status', () => {
|
|
|
862
841
|
});
|
|
863
842
|
});
|
|
864
843
|
describe("when the /api/ping endpoint isn't supported", () => {
|
|
865
|
-
const customWrapper =
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
patch: 0,
|
|
878
|
-
full: 'n/a'
|
|
879
|
-
}
|
|
844
|
+
const customWrapper = ({
|
|
845
|
+
children
|
|
846
|
+
}) => /*#__PURE__*/_react2.default.createElement(_appServiceConfig.ConfigProvider, {
|
|
847
|
+
config: {
|
|
848
|
+
baseUrl: '..',
|
|
849
|
+
apiVersion: 42,
|
|
850
|
+
// an unsupported version:
|
|
851
|
+
serverVersion: {
|
|
852
|
+
major: 2,
|
|
853
|
+
minor: 39,
|
|
854
|
+
patch: 0,
|
|
855
|
+
full: 'n/a'
|
|
880
856
|
}
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
};
|
|
857
|
+
}
|
|
858
|
+
}, /*#__PURE__*/_react2.default.createElement(_offlineProvider.OfflineProvider, {
|
|
859
|
+
offlineInterface: _testMocks.mockOfflineInterface
|
|
860
|
+
}, children));
|
|
885
861
|
test("pings aren't sent", async () => {
|
|
886
862
|
const setTimeoutSpy = jest.spyOn(window, 'setTimeout');
|
|
887
863
|
(0, _react.renderHook)(() => (0, _dhis2ConnectionStatus.useDhis2ConnectionStatus)(), {
|
|
@@ -13,14 +13,13 @@ const DEFAULT_INCREMENT_FACTOR = exports.DEFAULT_INCREMENT_FACTOR = 1.5;
|
|
|
13
13
|
const throwErrorIfNoCallbackIsProvided = () => {
|
|
14
14
|
throw new Error('Provide a callback');
|
|
15
15
|
};
|
|
16
|
-
function createSmartInterval(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
+
function createSmartInterval({
|
|
17
|
+
initialDelay = DEFAULT_INITIAL_DELAY_MS,
|
|
18
|
+
maxDelay = DEFAULT_MAX_DELAY_MS,
|
|
19
|
+
delayIncrementFactor = DEFAULT_INCREMENT_FACTOR,
|
|
20
|
+
initialPauseValue = false,
|
|
21
|
+
callback = throwErrorIfNoCallbackIsProvided
|
|
22
|
+
} = {}) {
|
|
24
23
|
const state = {
|
|
25
24
|
paused: initialPauseValue,
|
|
26
25
|
delay: initialDelay,
|
|
@@ -15,8 +15,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
15
15
|
// See more at https://github.com/amcgee/state-service-poc
|
|
16
16
|
|
|
17
17
|
const identity = state => state;
|
|
18
|
-
const createStore =
|
|
19
|
-
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
18
|
+
const createStore = (initialState = {}) => {
|
|
20
19
|
const subscriptions = new Set();
|
|
21
20
|
let state = initialState;
|
|
22
21
|
return {
|
|
@@ -38,22 +37,18 @@ const createStore = function () {
|
|
|
38
37
|
exports.createStore = createStore;
|
|
39
38
|
const GlobalStateContext = /*#__PURE__*/_react.default.createContext(createStore());
|
|
40
39
|
const useGlobalStateStore = () => (0, _react.useContext)(GlobalStateContext);
|
|
41
|
-
const GlobalStateProvider =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
value: store
|
|
48
|
-
}, children);
|
|
49
|
-
};
|
|
40
|
+
const GlobalStateProvider = ({
|
|
41
|
+
store,
|
|
42
|
+
children
|
|
43
|
+
}) => /*#__PURE__*/_react.default.createElement(GlobalStateContext.Provider, {
|
|
44
|
+
value: store
|
|
45
|
+
}, children);
|
|
50
46
|
exports.GlobalStateProvider = GlobalStateProvider;
|
|
51
47
|
GlobalStateProvider.propTypes = {
|
|
52
48
|
children: _propTypes.default.node,
|
|
53
49
|
store: _propTypes.default.shape({})
|
|
54
50
|
};
|
|
55
|
-
const useGlobalState =
|
|
56
|
-
let selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : identity;
|
|
51
|
+
const useGlobalState = (selector = identity) => {
|
|
57
52
|
const store = useGlobalStateStore();
|
|
58
53
|
const [selectedState, setSelectedState] = (0, _react.useState)(selector(store.getState()));
|
|
59
54
|
(0, _react.useEffect)(() => {
|
|
@@ -80,7 +75,7 @@ const useGlobalState = function () {
|
|
|
80
75
|
exports.useGlobalState = useGlobalState;
|
|
81
76
|
function useGlobalStateMutation(mutationCreator) {
|
|
82
77
|
const store = useGlobalStateStore();
|
|
83
|
-
return (0, _react.useCallback)(
|
|
84
|
-
store.mutate(mutationCreator(...
|
|
78
|
+
return (0, _react.useCallback)((...args) => {
|
|
79
|
+
store.mutate(mutationCreator(...args));
|
|
85
80
|
}, [mutationCreator, store]);
|
|
86
81
|
}
|
|
@@ -26,17 +26,15 @@ const lastOnlineKey = 'dhis2.lastOnline';
|
|
|
26
26
|
* @param {Number} [options.debounceDelay] - Timeout delay to debounce updates, in ms
|
|
27
27
|
* @returns {Object} `{ online: boolean, offline: boolean, lastOnline: Date | null }`
|
|
28
28
|
*/
|
|
29
|
-
function useNetworkStatus() {
|
|
29
|
+
function useNetworkStatus(options = {}) {
|
|
30
30
|
var _options$debounceDela;
|
|
31
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
31
|
// initialize state to `navigator.onLine` value
|
|
33
32
|
const [online, setOnline] = (0, _react.useState)(navigator.onLine);
|
|
34
33
|
|
|
35
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
-
const updateState = (0, _react.useCallback)((0, _debounce.default)(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} = _ref;
|
|
35
|
+
const updateState = (0, _react.useCallback)((0, _debounce.default)(({
|
|
36
|
+
type
|
|
37
|
+
}) => {
|
|
40
38
|
if (type === 'online') {
|
|
41
39
|
setOnline(true);
|
|
42
40
|
} else if (type === 'offline') {
|
|
@@ -27,11 +27,10 @@ const OfflineInterfaceContext = /*#__PURE__*/(0, _react.createContext)(noopOffli
|
|
|
27
27
|
* checks for service worker updates and, if updates are ready, prompts the
|
|
28
28
|
* user with an alert to skip waiting and reload the page to use new content.
|
|
29
29
|
*/
|
|
30
|
-
function OfflineInterfaceProvider(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} = _ref;
|
|
30
|
+
function OfflineInterfaceProvider({
|
|
31
|
+
offlineInterface,
|
|
32
|
+
children
|
|
33
|
+
}) {
|
|
35
34
|
return /*#__PURE__*/_react.default.createElement(OfflineInterfaceContext.Provider, {
|
|
36
35
|
value: offlineInterface
|
|
37
36
|
}, children);
|
|
@@ -12,11 +12,10 @@ var _offlineInterface = require("./offline-interface");
|
|
|
12
12
|
var _onlineStatusMessage = require("./online-status-message");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
/** A context provider for all the relevant offline contexts */
|
|
15
|
-
function OfflineProvider(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} = _ref;
|
|
15
|
+
function OfflineProvider({
|
|
16
|
+
offlineInterface,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
20
19
|
// If an offline interface is not provided, or if one is provided and PWA
|
|
21
20
|
// is not enabled, skip adding context providers
|
|
22
21
|
if (!offlineInterface || !offlineInterface.pwaEnabled) {
|
|
@@ -10,10 +10,9 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
10
10
|
// actually need the value don't have to rerender when the value changes:
|
|
11
11
|
const OnlineStatusMessageValueContext = /*#__PURE__*/_react.default.createContext(undefined);
|
|
12
12
|
const SetOnlineStatusMessageContext = /*#__PURE__*/_react.default.createContext(() => undefined);
|
|
13
|
-
const OnlineStatusMessageProvider =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = _ref;
|
|
13
|
+
const OnlineStatusMessageProvider = ({
|
|
14
|
+
children
|
|
15
|
+
}) => {
|
|
17
16
|
const [onlineStatusMessage, setOnlineStatusMessage] = (0, _react.useState)(); // note: not undefined
|
|
18
17
|
|
|
19
18
|
return /*#__PURE__*/_react.default.createElement(OnlineStatusMessageValueContext.Provider, {
|
|
@@ -6,11 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.resetRenderCounts = exports.RenderCounter = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const RenderCounter =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = _ref;
|
|
9
|
+
const RenderCounter = ({
|
|
10
|
+
id,
|
|
11
|
+
countsObj
|
|
12
|
+
}) => {
|
|
14
13
|
if (!(id in countsObj)) {
|
|
15
14
|
countsObj[id] = 0;
|
|
16
15
|
}
|
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.successfulRecordingMock = exports.mockOfflineInterface = exports.failedMessageRecordingMock = exports.errorRecordingMock = void 0;
|
|
7
|
-
const successfulRecordingMock = exports.successfulRecordingMock = jest.fn().mockImplementation(async
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
+
const successfulRecordingMock = exports.successfulRecordingMock = jest.fn().mockImplementation(async ({
|
|
8
|
+
onStarted,
|
|
9
|
+
onCompleted
|
|
10
|
+
} = {}) => {
|
|
12
11
|
// in 100ms, call 'onStarted' callback (allows 'pending' state)
|
|
13
12
|
if (onStarted) {
|
|
14
13
|
setTimeout(onStarted, 100);
|
|
@@ -22,11 +21,10 @@ const successfulRecordingMock = exports.successfulRecordingMock = jest.fn().mock
|
|
|
22
21
|
// resolve
|
|
23
22
|
return Promise.resolve();
|
|
24
23
|
});
|
|
25
|
-
const errorRecordingMock = exports.errorRecordingMock = jest.fn().mockImplementation(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
+
const errorRecordingMock = exports.errorRecordingMock = jest.fn().mockImplementation(({
|
|
25
|
+
onStarted,
|
|
26
|
+
onError
|
|
27
|
+
} = {}) => {
|
|
30
28
|
// in 100ms, call 'onStarted' callback (allows 'pending' state)
|
|
31
29
|
if (onStarted) {
|
|
32
30
|
setTimeout(onStarted, 100);
|
|
@@ -8,12 +8,11 @@ import { RenderCounter, resetRenderCounts } from '../utils/render-counter';
|
|
|
8
8
|
import { errorRecordingMock, failedMessageRecordingMock, mockOfflineInterface } from '../utils/test-mocks';
|
|
9
9
|
const renderCounts = {};
|
|
10
10
|
const identity = arg => arg;
|
|
11
|
-
const TestControls =
|
|
11
|
+
const TestControls = ({
|
|
12
|
+
id,
|
|
13
|
+
makeRecordingHandler = identity
|
|
14
|
+
}) => {
|
|
12
15
|
var _lastUpdated$toISOStr;
|
|
13
|
-
let {
|
|
14
|
-
id,
|
|
15
|
-
makeRecordingHandler = identity
|
|
16
|
-
} = _ref;
|
|
17
16
|
const {
|
|
18
17
|
startRecording,
|
|
19
18
|
remove,
|
|
@@ -40,21 +39,18 @@ const TestControls = _ref => {
|
|
|
40
39
|
"data-testid": `recording-state-${id}`
|
|
41
40
|
}, recordingState));
|
|
42
41
|
};
|
|
43
|
-
const TestSection =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
countsObj: renderCounts
|
|
56
|
-
}), children);
|
|
57
|
-
};
|
|
42
|
+
const TestSection = ({
|
|
43
|
+
id,
|
|
44
|
+
children
|
|
45
|
+
}) => /*#__PURE__*/React.createElement(CacheableSection, {
|
|
46
|
+
id: id,
|
|
47
|
+
loadingMask: /*#__PURE__*/React.createElement("div", {
|
|
48
|
+
"data-testid": `loading-mask-${id}`
|
|
49
|
+
})
|
|
50
|
+
}, /*#__PURE__*/React.createElement(RenderCounter, {
|
|
51
|
+
id: `section-rc-${id}`,
|
|
52
|
+
countsObj: renderCounts
|
|
53
|
+
}), children);
|
|
58
54
|
const TestSingleSection = props => {
|
|
59
55
|
// Props are spread so they can be overwritten
|
|
60
56
|
return /*#__PURE__*/React.createElement(AlertsProvider, null, /*#__PURE__*/React.createElement(OfflineProvider, _extends({
|
|
@@ -71,11 +67,8 @@ const originalError = console.error;
|
|
|
71
67
|
beforeEach(() => {
|
|
72
68
|
// This is done before each because the 'recording error' test uses its own
|
|
73
69
|
// spy on console.error
|
|
74
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
70
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
75
71
|
const pattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
76
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
77
|
-
args[_key] = arguments[_key];
|
|
78
|
-
}
|
|
79
72
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
80
73
|
return;
|
|
81
74
|
}
|
|
@@ -85,7 +78,7 @@ beforeEach(() => {
|
|
|
85
78
|
afterEach(() => {
|
|
86
79
|
jest.clearAllMocks()
|
|
87
80
|
// This syntax appeases typescript:
|
|
88
|
-
|
|
81
|
+
;
|
|
89
82
|
console.error.mockRestore();
|
|
90
83
|
resetRenderCounts(renderCounts);
|
|
91
84
|
});
|
|
@@ -137,12 +130,9 @@ describe('Coordination between useCacheableSection and CacheableSection', () =>
|
|
|
137
130
|
});
|
|
138
131
|
it('handles a recording that encounters an error', async done => {
|
|
139
132
|
// Suppress the expected error from console (in addition to 'act' warning)
|
|
140
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
133
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
141
134
|
const actPattern = /Warning: An update to .* inside a test was not wrapped in act/;
|
|
142
135
|
const errPattern = /Error during recording/;
|
|
143
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
144
|
-
args[_key2] = arguments[_key2];
|
|
145
|
-
}
|
|
146
136
|
const matchesPattern = actPattern.test(args[0]) || errPattern.test(args[0]);
|
|
147
137
|
if (typeof args[0] === 'string' && matchesPattern) {
|
|
148
138
|
return;
|
|
@@ -3,14 +3,11 @@ import React from 'react';
|
|
|
3
3
|
import { mockOfflineInterface } from '../../utils/test-mocks';
|
|
4
4
|
import { useCachedSection, useRecordingState } from '../cacheable-section-state';
|
|
5
5
|
import { OfflineProvider } from '../offline-provider';
|
|
6
|
-
const wrapper =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
offlineInterface: mockOfflineInterface
|
|
12
|
-
}, children);
|
|
13
|
-
};
|
|
6
|
+
const wrapper = ({
|
|
7
|
+
children
|
|
8
|
+
}) => /*#__PURE__*/React.createElement(OfflineProvider, {
|
|
9
|
+
offlineInterface: mockOfflineInterface
|
|
10
|
+
}, children);
|
|
14
11
|
test('useRecordingState has stable references', () => {
|
|
15
12
|
const {
|
|
16
13
|
result,
|
|
@@ -28,11 +28,8 @@ afterEach(() => {
|
|
|
28
28
|
// silence debug logs for these tests
|
|
29
29
|
const originalDebug = console.debug;
|
|
30
30
|
beforeAll(() => {
|
|
31
|
-
jest.spyOn(console, 'debug').mockImplementation(
|
|
31
|
+
jest.spyOn(console, 'debug').mockImplementation((...args) => {
|
|
32
32
|
const pattern = /Clearing sensitive caches/;
|
|
33
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
-
args[_key] = arguments[_key];
|
|
35
|
-
}
|
|
36
33
|
if (typeof args[0] === 'string' && pattern.test(args[0])) {
|
|
37
34
|
return;
|
|
38
35
|
}
|