@dhis2/app-service-offline
Advanced tools
Comparing version 2.10.0-pwa.2 to 2.10.0-pwa.3
@@ -199,2 +199,30 @@ "use strict"; | ||
expect(result.current.lastUpdated).toBeUndefined(); | ||
}); | ||
it('handles a change in ID', async () => { | ||
const testOfflineInterface = { ..._testMocks.mockOfflineInterface, | ||
getCachedSections: jest.fn().mockResolvedValue([{ | ||
sectionId: 'id-one', | ||
lastUpdated: new Date() | ||
}]) | ||
}; | ||
const { | ||
result, | ||
waitFor, | ||
rerender | ||
} = (0, _reactHooks.renderHook)((...args) => (0, _cacheableSection.useCacheableSection)(...args), { | ||
wrapper: ({ | ||
children | ||
}) => /*#__PURE__*/_react.default.createElement(_offlineProvider.OfflineProvider, { | ||
offlineInterface: testOfflineInterface | ||
}, children), | ||
initialProps: 'id-one' | ||
}); // Wait for state to sync with indexedDB | ||
await waitFor(() => result.current.isCached === true); | ||
rerender('id-two'); // Test that 'isCached' gets updated | ||
// expect(testOfflineInterface.getCachedSections).toBeCalledTimes(2) | ||
await waitFor(() => result.current.isCached === false); | ||
expect(result.current.isCached).toBe(false); | ||
expect(result.current.lastUpdated).toBeUndefined(); | ||
}); |
@@ -78,5 +78,7 @@ "use strict"; | ||
store.subscribe(callback); | ||
store.subscribe(callback); // Make sure to update state when selector changes | ||
callback(store.getState()); | ||
return () => store.unsubscribe(callback); | ||
}, [store]); | ||
}, [store, selector]); | ||
/* eslint-disable-line react-hooks/exhaustive-deps */ | ||
@@ -83,0 +85,0 @@ |
@@ -190,2 +190,30 @@ /* eslint-disable react/display-name, react/prop-types */ | ||
expect(result.current.lastUpdated).toBeUndefined(); | ||
}); | ||
it('handles a change in ID', async () => { | ||
const testOfflineInterface = { ...mockOfflineInterface, | ||
getCachedSections: jest.fn().mockResolvedValue([{ | ||
sectionId: 'id-one', | ||
lastUpdated: new Date() | ||
}]) | ||
}; | ||
const { | ||
result, | ||
waitFor, | ||
rerender | ||
} = renderHook((...args) => useCacheableSection(...args), { | ||
wrapper: ({ | ||
children | ||
}) => /*#__PURE__*/React.createElement(OfflineProvider, { | ||
offlineInterface: testOfflineInterface | ||
}, children), | ||
initialProps: 'id-one' | ||
}); // Wait for state to sync with indexedDB | ||
await waitFor(() => result.current.isCached === true); | ||
rerender('id-two'); // Test that 'isCached' gets updated | ||
// expect(testOfflineInterface.getCachedSections).toBeCalledTimes(2) | ||
await waitFor(() => result.current.isCached === false); | ||
expect(result.current.isCached).toBe(false); | ||
expect(result.current.lastUpdated).toBeUndefined(); | ||
}); |
@@ -56,5 +56,7 @@ import isEqual from 'lodash/isEqual'; | ||
store.subscribe(callback); | ||
store.subscribe(callback); // Make sure to update state when selector changes | ||
callback(store.getState()); | ||
return () => store.unsubscribe(callback); | ||
}, [store]); | ||
}, [store, selector]); | ||
/* eslint-disable-line react-hooks/exhaustive-deps */ | ||
@@ -61,0 +63,0 @@ |
{ | ||
"name": "@dhis2/app-service-offline", | ||
"description": "A runtime service for online/offline detection and offline caching", | ||
"version": "2.10.0-pwa.2", | ||
"version": "2.10.0-pwa.3", | ||
"main": "./build/cjs/index.js", | ||
@@ -36,3 +36,3 @@ "module": "./build/es/index.js", | ||
"peerDependencies": { | ||
"@dhis2/app-service-alerts": "^2.10.0-pwa.2", | ||
"@dhis2/app-service-alerts": "^2.10.0-pwa.3", | ||
"prop-types": "^15.7.2", | ||
@@ -39,0 +39,0 @@ "react": "^16.8.6", |
117184
2916