fix: lint and prettier fixes
This commit is contained in:
parent
97b438069a
commit
169b5365e9
|
@ -2,6 +2,5 @@
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true
|
||||||
"jsxBracketSameLine": false
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
{
|
{
|
||||||
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
|
"extends": [
|
||||||
|
"@react-native-community",
|
||||||
|
"plugin:react-native-a11y/all",
|
||||||
|
"plugin:@nrwl/nx/react",
|
||||||
|
"../../.eslintrc.json"
|
||||||
|
],
|
||||||
"ignorePatterns": ["!**/*", "public", ".cache", "node_modules"],
|
"ignorePatterns": ["!**/*", "public", ".cache", "node_modules"],
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"bracketSameLine": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,7 @@ const reporter = __DEV__
|
||||||
log: (message) => console.log(message),
|
log: (message) => console.log(message),
|
||||||
error: (error, label) => console.error(label, error),
|
error: (error, label) => console.error(label, error),
|
||||||
}
|
}
|
||||||
: {
|
: undefined
|
||||||
log: () => {},
|
|
||||||
error: () => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
const DevMenu = require('react-native-dev-menu')
|
const DevMenu = require('react-native-dev-menu')
|
||||||
|
|
|
@ -31,7 +31,9 @@ const setup = (customProps = {}) => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Hide errors from act
|
// Hide errors from act
|
||||||
// https://github.com/callstack/react-native-testing-library/issues/379
|
// https://github.com/callstack/react-native-testing-library/issues/379
|
||||||
jest.spyOn(console, 'error').mockImplementation(() => {})
|
jest.spyOn(console, 'error').mockImplementation(() => {
|
||||||
|
// noop
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -44,7 +44,9 @@ const setup = (customProps = {}) => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Hide errors from state illegal state transition
|
// Hide errors from state illegal state transition
|
||||||
// Probably due to mock
|
// Probably due to mock
|
||||||
jest.spyOn(console, 'error').mockImplementation(() => {})
|
jest.spyOn(console, 'error').mockImplementation(() => {
|
||||||
|
// noop
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(jest.clearAllMocks)
|
beforeEach(jest.clearAllMocks)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { fireEvent } from '@testing-library/react-native'
|
import { fireEvent } from '@testing-library/react-native'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import RNCalendarEvents from 'react-native-calendar-events'
|
import RNCalendarEvents from 'react-native-calendar-events'
|
||||||
|
import Toast from 'react-native-simple-toast'
|
||||||
import { render } from '../../utils/testHelpers'
|
import { render } from '../../utils/testHelpers'
|
||||||
import { SaveToCalendar } from '../saveToCalendar.component'
|
import { SaveToCalendar } from '../saveToCalendar.component'
|
||||||
import Toast from 'react-native-simple-toast'
|
|
||||||
|
|
||||||
jest.mock('react-native-simple-toast', () => ({
|
jest.mock('react-native-simple-toast', () => ({
|
||||||
SHORT: 'short',
|
SHORT: 'short',
|
||||||
|
@ -53,7 +53,9 @@ const setup = (customProps = {}) => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
// Hide errors from state illegal state transition
|
// Hide errors from state illegal state transition
|
||||||
// Probably due to mock
|
// Probably due to mock
|
||||||
jest.spyOn(console, 'error').mockImplementation(() => {})
|
jest.spyOn(console, 'error').mockImplementation(() => {
|
||||||
|
// noop
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(jest.clearAllMocks)
|
beforeEach(jest.clearAllMocks)
|
||||||
|
|
|
@ -38,7 +38,9 @@ type ChildListItemNavigationProp = StackNavigationProp<
|
||||||
|
|
||||||
export const ChildListItem = ({ child, color }: ChildListItemProps) => {
|
export const ChildListItem = ({ child, color }: ChildListItemProps) => {
|
||||||
// Forces rerender when child.id changes
|
// Forces rerender when child.id changes
|
||||||
React.useEffect(() => {}, [child.id])
|
React.useEffect(() => {
|
||||||
|
// noop
|
||||||
|
}, [child.id])
|
||||||
|
|
||||||
const navigation = useNavigation<ChildListItemNavigationProp>()
|
const navigation = useNavigation<ChildListItemNavigationProp>()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const Notification = ({ item }: NotificationProps) => {
|
||||||
const date = item.dateModified || item.dateCreated
|
const date = item.dateModified || item.dateCreated
|
||||||
const displayDate = date ? moment(date).fromNow() : null
|
const displayDate = date ? moment(date).fromNow() : null
|
||||||
|
|
||||||
const sharedCookiesEnabled: boolean = Boolean(
|
const sharedCookiesEnabled = Boolean(
|
||||||
item.url && item.url.startsWith('https://start.unikum.net/')
|
item.url && item.url.startsWith('https://start.unikum.net/')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ export const SaveToCalendar = ({ event }: SaveToCalendarProps) => {
|
||||||
const toast = (text: string) =>
|
const toast = (text: string) =>
|
||||||
Toast.showWithGravity(text, Toast.SHORT, Toast.BOTTOM)
|
Toast.showWithGravity(text, Toast.SHORT, Toast.BOTTOM)
|
||||||
|
|
||||||
function removeEmptyValues<T extends object>(obj: T) {
|
function removeEmptyValues<T extends Record<string, unknown>>(obj: T) {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(obj).filter(([_, v]) => v != null)
|
Object.entries(obj).filter(([_, v]) => v != null)
|
||||||
) as { [K in keyof T]: any }
|
) as { [K in keyof T]: any }
|
||||||
|
|
|
@ -12,7 +12,9 @@ export default function useAsyncStorage<T>(
|
||||||
if (!storageKey) return
|
if (!storageKey) return
|
||||||
await AsyncStorage.setItem(storageKey, JSON.stringify(value))
|
await AsyncStorage.setItem(storageKey, JSON.stringify(value))
|
||||||
setStorageItem(value)
|
setStorageItem(value)
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -20,7 +22,9 @@ export default function useAsyncStorage<T>(
|
||||||
try {
|
try {
|
||||||
const data = await AsyncStorage.getItem(storageKey)
|
const data = await AsyncStorage.getItem(storageKey)
|
||||||
if (typeof data === 'string') setStorageItem(JSON.parse(data))
|
if (typeof data === 'string') setStorageItem(JSON.parse(data))
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getStoredValue()
|
getStoredValue()
|
||||||
|
|
|
@ -10,4 +10,4 @@ module.exports = {
|
||||||
'react-native/jest/assetFileTransformer.js'
|
'react-native/jest/assetFileTransformer.js'
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ const rtlList: { [key: string]: boolean } = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isRTL = (langCode: string) => {
|
export const isRTL = (langCode: string) => {
|
||||||
if (!rtlList.hasOwnProperty(langCode)) {
|
if (!Object.prototype.hasOwnProperty.call(rtlList, langCode)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return rtlList[langCode]
|
return rtlList[langCode]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import '@testing-library/jest-native/extend-expect';
|
import '@testing-library/jest-native/extend-expect'
|
||||||
import moment from 'moment';
|
import moment from 'moment'
|
||||||
import 'moment/locale/sv';
|
import 'moment/locale/sv'
|
||||||
import 'react-native-gesture-handler/jestSetup';
|
import 'react-native-gesture-handler/jestSetup'
|
||||||
|
|
||||||
moment.locale('sv')
|
moment.locale('sv')
|
||||||
|
|
||||||
|
@ -9,12 +9,14 @@ moment.locale('sv')
|
||||||
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
|
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper')
|
||||||
|
|
||||||
jest.mock('react-native-reanimated', () => {
|
jest.mock('react-native-reanimated', () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const Reanimated = require('react-native-reanimated/mock')
|
const Reanimated = require('react-native-reanimated/mock')
|
||||||
|
|
||||||
// The mock for `call` immediately calls the callback which is incorrect
|
// The mock for `call` immediately calls the callback which is incorrect
|
||||||
// So we override it with a no-op
|
// So we override it with a no-op
|
||||||
Reanimated.default.call = () => {}
|
Reanimated.default.call = () => {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
|
||||||
return Reanimated
|
return Reanimated
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { translate, translations } from '../translation'
|
||||||
|
|
||||||
describe('translation in swedish', () => {
|
describe('translation in swedish', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
i18n.translations = { ['sv']: translations.sv }
|
i18n.translations = { sv: translations.sv }
|
||||||
i18n.locale = 'sv'
|
i18n.locale = 'sv'
|
||||||
})
|
})
|
||||||
it('should be able to translate the word settings', () => {
|
it('should be able to translate the word settings', () => {
|
||||||
|
@ -13,7 +13,7 @@ describe('translation in swedish', () => {
|
||||||
|
|
||||||
describe('translation in english', () => {
|
describe('translation in english', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
i18n.translations = { ['en']: translations.en }
|
i18n.translations = { en: translations.en }
|
||||||
i18n.locale = 'en'
|
i18n.locale = 'en'
|
||||||
})
|
})
|
||||||
it('should be able to translate the word settings', () => {
|
it('should be able to translate the word settings', () => {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { useChild } from '../components/childContext.component'
|
||||||
import { Typography } from '../styles'
|
import { Typography } from '../styles'
|
||||||
|
|
||||||
// https://github.com/facebook/react-native/issues/14796#issuecomment-389743259
|
// https://github.com/facebook/react-native/issues/14796#issuecomment-389743259
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
global.Buffer = global.Buffer || require('buffer').Buffer
|
global.Buffer = global.Buffer || require('buffer').Buffer
|
||||||
|
|
||||||
const NUM_CHARS_AROUND_SEARCH_MATCH = 20
|
const NUM_CHARS_AROUND_SEARCH_MATCH = 20
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"bracketSameLine": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"bracketSameLine": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ const HttpProxyAgent = require('https-proxy-agent')
|
||||||
const agentWrapper = require('./agentFetchWrapper')
|
const agentWrapper = require('./agentFetchWrapper')
|
||||||
const init = require('./dist').default
|
const init = require('./dist').default
|
||||||
|
|
||||||
|
|
||||||
const [, , personalNumber] = process.argv
|
const [, , personalNumber] = process.argv
|
||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||||
const cookieJar = new CookieJar()
|
const cookieJar = new CookieJar()
|
||||||
|
@ -53,11 +52,11 @@ async function run() {
|
||||||
console.log('user')
|
console.log('user')
|
||||||
const user = await api.getUser()
|
const user = await api.getUser()
|
||||||
console.log(user)
|
console.log(user)
|
||||||
|
|
||||||
console.log('children')
|
console.log('children')
|
||||||
const children = await api.getChildren()
|
const children = await api.getChildren()
|
||||||
console.log(children)
|
console.log(children)
|
||||||
/*
|
/*
|
||||||
console.log('calendar')
|
console.log('calendar')
|
||||||
const calendar = await api.getCalendar(children[0])
|
const calendar = await api.getCalendar(children[0])
|
||||||
console.log(calendar)
|
console.log(calendar)
|
||||||
|
@ -68,12 +67,16 @@ async function run() {
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
console.log('schedule')
|
console.log('schedule')
|
||||||
const schedule = await api.getSchedule(children[1], DateTime.local(), DateTime.local().plus({ week: 1 }))
|
const schedule = await api.getSchedule(
|
||||||
|
children[1],
|
||||||
|
DateTime.local(),
|
||||||
|
DateTime.local().plus({ week: 1 })
|
||||||
|
)
|
||||||
console.log(schedule)
|
console.log(schedule)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
let skola24children
|
let skola24children
|
||||||
try {
|
try {
|
||||||
skola24children = await api.getSkola24Children()
|
skola24children = await api.getSkola24Children()
|
||||||
|
@ -81,16 +84,21 @@ async function run() {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('timetable')
|
console.log('timetable')
|
||||||
const timetable = await api.getTimetable(skola24children[0], 15, 2021, "sv")
|
const timetable = await api.getTimetable(
|
||||||
console.log(inspect(timetable, false, 1000, true))
|
skola24children[0],
|
||||||
|
15,
|
||||||
|
2021,
|
||||||
|
'sv'
|
||||||
|
)
|
||||||
|
console.log(inspect(timetable, false, 1000, true))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
console.log('news')
|
console.log('news')
|
||||||
const news = await api.getNews(children[0])
|
const news = await api.getNews(children[0])
|
||||||
*/
|
*/
|
||||||
|
@ -216,7 +224,9 @@ const record = async (info, data) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack to keep it running while wating for await
|
// Hack to keep it running while wating for await
|
||||||
const timer = setTimeout(() => {}, 999999)
|
const timer = setTimeout(() => {
|
||||||
|
// noop
|
||||||
|
}, 999999)
|
||||||
|
|
||||||
run()
|
run()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
/* eslint-disable no-plusplus */
|
/* eslint-disable no-plusplus */
|
||||||
export class URLSearchParams {
|
export class URLSearchParams {
|
||||||
|
private dict: { [key: string]: string[] } = {}
|
||||||
private dict: {[key: string]: string[]} = {}
|
|
||||||
|
|
||||||
constructor(search: string | string[] | any | URLSearchParams = '') {
|
constructor(search: string | string[] | any | URLSearchParams = '') {
|
||||||
if (search instanceof URLSearchParams) {
|
if (search instanceof URLSearchParams) {
|
||||||
|
@ -70,21 +69,25 @@ export class URLSearchParams {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
parseToDict(search: string | string[] | any): any {
|
parseToDict(search: string | string[] | any): any {
|
||||||
const dict = {}
|
const dict = {}
|
||||||
|
|
||||||
if (typeof search === 'object') {
|
if (typeof search === 'object') {
|
||||||
// if 'search' is an array, treat it as a sequence
|
// if 'search' is an array, treat it as a sequence
|
||||||
if (Array.isArray(search)) {
|
if (Array.isArray(search)) {
|
||||||
for (let i=0; i<search.length; i++) {
|
for (let i = 0; i < search.length; i++) {
|
||||||
const item = search[i]
|
const item = search[i]
|
||||||
if (Array.isArray(item) && item.length === 2) {
|
if (Array.isArray(item) && item.length === 2) {
|
||||||
this.appendTo(dict, item[0], item[1])
|
this.appendTo(dict, item[0], item[1])
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("Failed to construct 'URLSearchParams': Sequence initalizer must only contain pair elements")
|
throw new TypeError(
|
||||||
|
"Failed to construct 'URLSearchParams': Sequence initalizer must only contain pair elements"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Object.entries(search).forEach(([key, value]) => this.appendTo(dict, key, value))
|
Object.entries(search).forEach(([key, value]) =>
|
||||||
|
this.appendTo(dict, key, value)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// remove 1st ?
|
// remove 1st ?
|
||||||
|
@ -93,11 +96,15 @@ export class URLSearchParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
const pairs = search.split('&')
|
const pairs = search.split('&')
|
||||||
for (let j=0; j<pairs.length; j++) {
|
for (let j = 0; j < pairs.length; j++) {
|
||||||
const value = pairs[j]
|
const value = pairs[j]
|
||||||
const index = value.indexOf('=')
|
const index = value.indexOf('=')
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
this.appendTo(dict, this.decode(value.slice(0, index)), this.decode(value.slice(index+1)))
|
this.appendTo(
|
||||||
|
dict,
|
||||||
|
this.decode(value.slice(0, index)),
|
||||||
|
this.decode(value.slice(index + 1))
|
||||||
|
)
|
||||||
} else if (value) {
|
} else if (value) {
|
||||||
this.appendTo(dict, this.decode(value), '')
|
this.appendTo(dict, this.decode(value), '')
|
||||||
}
|
}
|
||||||
|
@ -107,11 +114,16 @@ export class URLSearchParams {
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
appendTo(dict: any, name: string, value: string | Function | any): void {
|
appendTo(dict: any, name: string, value: string | (() => void) | any): void {
|
||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
const val = typeof value === 'string' ? value: (
|
const val =
|
||||||
value !== null && value !== undefined && typeof value.toString === 'function' ? value.toString() : JSON.stringify(value)
|
typeof value === 'string'
|
||||||
)
|
? value
|
||||||
|
: value !== null &&
|
||||||
|
value !== undefined &&
|
||||||
|
typeof value.toString === 'function'
|
||||||
|
? value.toString()
|
||||||
|
: JSON.stringify(value)
|
||||||
|
|
||||||
if (name in dict) {
|
if (name in dict) {
|
||||||
dict[name].push(value)
|
dict[name].push(value)
|
||||||
|
@ -123,20 +135,23 @@ export class URLSearchParams {
|
||||||
decode(str: string): string {
|
decode(str: string): string {
|
||||||
return str
|
return str
|
||||||
.replace(/[ +]/g, '%20')
|
.replace(/[ +]/g, '%20')
|
||||||
.replace(/(%[a-f0-9]{2})+/ig, (match) => decodeURIComponent(match))
|
.replace(/(%[a-f0-9]{2})+/gi, (match) => decodeURIComponent(match))
|
||||||
}
|
}
|
||||||
|
|
||||||
encode(str: string[]): string {
|
encode(str: string[]): string {
|
||||||
const replace: {[key: string]: string} = {
|
const replace: { [key: string]: string } = {
|
||||||
'!': '%21',
|
'!': '%21',
|
||||||
"'": '%27',
|
"'": '%27',
|
||||||
'(': '%28',
|
'(': '%28',
|
||||||
')': '%29',
|
')': '%29',
|
||||||
'~': '%7E',
|
'~': '%7E',
|
||||||
'%20': '+',
|
'%20': '+',
|
||||||
'%00': '\x00'
|
'%00': '\x00',
|
||||||
}
|
}
|
||||||
|
return encodeURIComponent(str.join(',')).replace(
|
||||||
// eslint-disable-next-line no-useless-escape
|
// eslint-disable-next-line no-useless-escape
|
||||||
return encodeURIComponent(str.join(',')).replace(/[!'\(\)~]|%20|%00/g, (match) => replace[match] || '')
|
/[!'\(\)~]|%20|%00/g,
|
||||||
|
(match) => replace[match] || ''
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,9 @@ export class Api extends EventEmitter {
|
||||||
|
|
||||||
private cookieManager: CookieManager
|
private cookieManager: CookieManager
|
||||||
|
|
||||||
public isLoggedIn: boolean = false
|
public isLoggedIn = false
|
||||||
|
|
||||||
public isFake: boolean = false
|
public isFake = false
|
||||||
|
|
||||||
private authorizedSystems: SSOSystems = {}
|
private authorizedSystems: SSOSystems = {}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import wrap, { CallInfo, Fetcher, Recorder } from './fetcher'
|
import wrap, { CallInfo, Fetcher, Recorder } from './fetcher'
|
||||||
import { Fetch, Headers, Response } from './types'
|
import { Fetch, Headers, Response } from './types'
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const Blob = require('node-blob')
|
const Blob = require('node-blob')
|
||||||
Blob.prototype.arrayBuffer = async function () {
|
Blob.prototype.arrayBuffer = async function () {
|
||||||
return this.buffer.buffer
|
return this.buffer.buffer
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Checker extends EventEmitter {
|
||||||
|
|
||||||
private url: string
|
private url: string
|
||||||
|
|
||||||
private cancelled: boolean = false
|
private cancelled = false
|
||||||
|
|
||||||
constructor(fetcher: Fetcher, ticket: AuthTicket) {
|
constructor(fetcher: Fetcher, ticket: AuthTicket) {
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const camel = require('camelcase-keys')
|
import camel from 'camelcase-keys'
|
||||||
|
|
||||||
export interface EtjanstResponse {
|
export interface EtjanstResponse {
|
||||||
Success: boolean
|
Success: boolean
|
||||||
|
|
|
@ -62,10 +62,11 @@ const record = async (info, data) => {
|
||||||
case 'text':
|
case 'text':
|
||||||
content.text = data
|
content.text = data
|
||||||
break
|
break
|
||||||
case 'blob':
|
case 'blob': {
|
||||||
const buffer = await data.arrayBuffer()
|
const buffer = await data.arrayBuffer()
|
||||||
content.blob = Buffer.from(buffer).toString('base64')
|
content.blob = Buffer.from(buffer).toString('base64')
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (info.error) {
|
} else if (info.error) {
|
||||||
const { message, stack } = info.error
|
const { message, stack } = info.error
|
||||||
|
@ -103,11 +104,11 @@ async function run() {
|
||||||
console.log('children')
|
console.log('children')
|
||||||
const children = await api.getChildren()
|
const children = await api.getChildren()
|
||||||
console.log(children)
|
console.log(children)
|
||||||
|
|
||||||
console.log('calendar')
|
console.log('calendar')
|
||||||
const calendar = await api.getCalendar(children[0])
|
const calendar = await api.getCalendar(children[0])
|
||||||
console.log(calendar)
|
console.log(calendar)
|
||||||
/*
|
/*
|
||||||
console.log('classmates')
|
console.log('classmates')
|
||||||
const classmates = await api.getClassmates(children[0])
|
const classmates = await api.getClassmates(children[0])
|
||||||
console.log(classmates)
|
console.log(classmates)
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"jsxBracketSameLine": false
|
"bracketSameLine": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
{
|
{
|
||||||
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
|
"extends": [
|
||||||
|
"@react-native-community",
|
||||||
|
"plugin:react-native-a11y/all",
|
||||||
|
"plugin:@nrwl/nx/react",
|
||||||
|
"../../.eslintrc.json"
|
||||||
|
],
|
||||||
"ignorePatterns": ["!**/*"],
|
"ignorePatterns": ["!**/*"],
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,9 +14,14 @@ export default (init = {}, delay = 0) => {
|
||||||
cache[key] = val
|
cache[key] = val
|
||||||
}
|
}
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
Object.keys(cache).forEach((key) => { cache[key] = undefined })
|
Object.keys(cache).forEach((key) => {
|
||||||
|
cache[key] = undefined
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
getItem, setItem, cache, clear,
|
getItem,
|
||||||
|
setItem,
|
||||||
|
cache,
|
||||||
|
clear,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {
|
import { EntityAction, EntityName, ExtraActionProps } from './types'
|
||||||
EntityAction, EntityName, ExtraActionProps,
|
|
||||||
} from './types'
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
export const loadAction = <T>(
|
||||||
export const loadAction = <T>(entity: EntityName, extra: ExtraActionProps<T>): EntityAction<T> => ({
|
entity: EntityName,
|
||||||
|
extra: ExtraActionProps<T>
|
||||||
|
): EntityAction<T> => ({
|
||||||
entity,
|
entity,
|
||||||
extra,
|
extra,
|
||||||
type: 'GET_FROM_API',
|
type: 'GET_FROM_API',
|
||||||
|
|
|
@ -26,8 +26,16 @@ describe('childlists', () => {
|
||||||
]
|
]
|
||||||
|
|
||||||
const children = [
|
const children = [
|
||||||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' },
|
{
|
||||||
{ name: 'Cassius Übrink (elev)', firstName: 'Cassius', lastName: 'Vredstein Übrink' },
|
name: 'Uwe Übrink (elev)',
|
||||||
|
firstName: 'Uwe',
|
||||||
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Cassius Übrink (elev)',
|
||||||
|
firstName: 'Cassius',
|
||||||
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
||||||
})
|
})
|
||||||
|
@ -41,7 +49,11 @@ describe('childlists', () => {
|
||||||
]
|
]
|
||||||
|
|
||||||
const children = [
|
const children = [
|
||||||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' },
|
{
|
||||||
|
name: 'Uwe Übrink (elev)',
|
||||||
|
firstName: 'Uwe',
|
||||||
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
{ name: 'Cassius Übrink (elev)' },
|
{ name: 'Cassius Übrink (elev)' },
|
||||||
]
|
]
|
||||||
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
||||||
|
@ -57,7 +69,11 @@ describe('childlists', () => {
|
||||||
]
|
]
|
||||||
|
|
||||||
const children = [
|
const children = [
|
||||||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' },
|
{
|
||||||
|
name: 'Uwe Übrink (elev)',
|
||||||
|
firstName: 'Uwe',
|
||||||
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
{ name: 'Cassius Übrink (elev)' },
|
{ name: 'Cassius Übrink (elev)' },
|
||||||
]
|
]
|
||||||
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
expect(merge(etjanstChildren, skola24Children)).toEqual(children)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
Skola24Child,
|
Skola24Child,
|
||||||
} from '@skolplattformen/api-skolplattformen'
|
} from '@skolplattformen/api-skolplattformen'
|
||||||
|
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
|
||||||
export const merge = (
|
export const merge = (
|
||||||
etjanstChildren: EtjanstChild[],
|
etjanstChildren: EtjanstChild[],
|
||||||
skola24Children: Skola24Child[]
|
skola24Children: Skola24Child[]
|
||||||
|
|
|
@ -23,7 +23,9 @@ describe('useApi()', () => {
|
||||||
expect(result.current.isLoggedIn).toBe(false)
|
expect(result.current.isLoggedIn).toBe(false)
|
||||||
})
|
})
|
||||||
it('updates isLoggedIn', async () => {
|
it('updates isLoggedIn', async () => {
|
||||||
const { result, waitForValueToChange } = renderHook(() => useApi(), { wrapper })
|
const { result, waitForValueToChange } = renderHook(() => useApi(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.emitter.emit('login')
|
api.emitter.emit('login')
|
||||||
|
@ -33,7 +35,9 @@ describe('useApi()', () => {
|
||||||
expect(result.current.isLoggedIn).toBe(true)
|
expect(result.current.isLoggedIn).toBe(true)
|
||||||
})
|
})
|
||||||
it('updates isFake', async () => {
|
it('updates isFake', async () => {
|
||||||
const { result, waitForValueToChange } = renderHook(() => useApi(), { wrapper })
|
const { result, waitForValueToChange } = renderHook(() => useApi(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
api.emitter.emit('login')
|
api.emitter.emit('login')
|
||||||
|
|
|
@ -30,8 +30,12 @@ describe('hooks with fake data', () => {
|
||||||
)
|
)
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
api = init(
|
api = init(
|
||||||
() => {},
|
() => {
|
||||||
() => {}
|
// noop
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
//noop
|
||||||
|
}
|
||||||
)
|
)
|
||||||
await api.login('121212121212')
|
await api.login('121212121212')
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable react-hooks/rules-of-hooks */
|
||||||
import {
|
import {
|
||||||
Api,
|
Api,
|
||||||
CalendarItem,
|
CalendarItem,
|
||||||
|
|
|
@ -14,11 +14,7 @@ describe('logout - cleanup', () => {
|
||||||
let storage
|
let storage
|
||||||
let response
|
let response
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -26,14 +22,18 @@ describe('logout - cleanup', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getChildren.mockImplementation(() => (
|
api.getChildren.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_etjanst_children': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_etjanst_children': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -46,7 +46,10 @@ describe('logout - cleanup', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate: wait1 } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { waitForNextUpdate: wait1 } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await wait1()
|
await wait1()
|
||||||
await wait1()
|
await wait1()
|
||||||
|
@ -63,7 +66,10 @@ describe('logout - cleanup', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.emitter.emit('login')
|
api.emitter.emit('login')
|
||||||
|
|
||||||
const { result: result2, waitForNextUpdate: wait2 } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result: result2, waitForNextUpdate: wait2 } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await wait2()
|
await wait2()
|
||||||
|
|
||||||
|
|
|
@ -2,110 +2,112 @@
|
||||||
import { Middleware } from 'redux'
|
import { Middleware } from 'redux'
|
||||||
import { EntityAction, EntityStoreRootState, ExtraActionProps } from './types'
|
import { EntityAction, EntityStoreRootState, ExtraActionProps } from './types'
|
||||||
|
|
||||||
type IMiddleware = Middleware<{}, EntityStoreRootState>
|
type IMiddleware = Middleware<Record<string, unknown>, EntityStoreRootState>
|
||||||
export const apiMiddleware: IMiddleware = (storeApi) => (next) => (action: EntityAction<any>) => {
|
export const apiMiddleware: IMiddleware =
|
||||||
try {
|
(storeApi) => (next) => (action: EntityAction<any>) => {
|
||||||
switch (action.type) {
|
try {
|
||||||
case 'GET_FROM_API': {
|
switch (action.type) {
|
||||||
// Retrieve from cache
|
case 'GET_FROM_API': {
|
||||||
if (action.extra?.getFromCache) {
|
// Retrieve from cache
|
||||||
const cacheAction: EntityAction<any> = {
|
if (action.extra?.getFromCache) {
|
||||||
...action,
|
const cacheAction: EntityAction<any> = {
|
||||||
type: 'GET_FROM_CACHE',
|
...action,
|
||||||
|
type: 'GET_FROM_CACHE',
|
||||||
|
}
|
||||||
|
storeApi.dispatch(cacheAction)
|
||||||
}
|
}
|
||||||
storeApi.dispatch(cacheAction)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call api
|
// Call api
|
||||||
const apiCall = action.extra?.apiCall
|
const apiCall = action.extra?.apiCall
|
||||||
if (apiCall) {
|
if (apiCall) {
|
||||||
const extra = action.extra as ExtraActionProps<any>
|
const extra = action.extra as ExtraActionProps<any>
|
||||||
apiCall()
|
apiCall()
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
const resultAction: EntityAction<any> = {
|
const resultAction: EntityAction<any> = {
|
||||||
...action,
|
...action,
|
||||||
type: 'RESULT_FROM_API',
|
type: 'RESULT_FROM_API',
|
||||||
data: res,
|
data: res,
|
||||||
}
|
}
|
||||||
storeApi.dispatch(resultAction)
|
storeApi.dispatch(resultAction)
|
||||||
|
|
||||||
if (extra.saveToCache && res) {
|
if (extra.saveToCache && res) {
|
||||||
const cacheAction: EntityAction<any> = {
|
const cacheAction: EntityAction<any> = {
|
||||||
...resultAction,
|
...resultAction,
|
||||||
type: 'STORE_IN_CACHE',
|
type: 'STORE_IN_CACHE',
|
||||||
}
|
}
|
||||||
storeApi.dispatch(cacheAction)
|
storeApi.dispatch(cacheAction)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
const retries = extra.retries + 1
|
const retries = extra.retries + 1
|
||||||
|
|
||||||
const errorAction: EntityAction<any> = {
|
const errorAction: EntityAction<any> = {
|
||||||
...action,
|
|
||||||
extra: {
|
|
||||||
...extra,
|
|
||||||
retries,
|
|
||||||
},
|
|
||||||
type: 'API_ERROR',
|
|
||||||
error,
|
|
||||||
}
|
|
||||||
storeApi.dispatch(errorAction)
|
|
||||||
|
|
||||||
// Retry 3 times
|
|
||||||
if (retries < 3) {
|
|
||||||
const retryAction: EntityAction<any> = {
|
|
||||||
...action,
|
...action,
|
||||||
type: 'GET_FROM_API',
|
|
||||||
extra: {
|
extra: {
|
||||||
...extra,
|
...extra,
|
||||||
retries,
|
retries,
|
||||||
},
|
},
|
||||||
|
type: 'API_ERROR',
|
||||||
|
error,
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
storeApi.dispatch(errorAction)
|
||||||
storeApi.dispatch(retryAction)
|
|
||||||
}, retries * 500)
|
// Retry 3 times
|
||||||
|
if (retries < 3) {
|
||||||
|
const retryAction: EntityAction<any> = {
|
||||||
|
...action,
|
||||||
|
type: 'GET_FROM_API',
|
||||||
|
extra: {
|
||||||
|
...extra,
|
||||||
|
retries,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
storeApi.dispatch(retryAction)
|
||||||
|
}, retries * 500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
return next(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const cacheMiddleware: IMiddleware =
|
||||||
|
(storeApi) => (next) => (action: EntityAction<any>) => {
|
||||||
|
try {
|
||||||
|
switch (action.type) {
|
||||||
|
case 'GET_FROM_CACHE': {
|
||||||
|
const getFromCache = action.extra?.getFromCache
|
||||||
|
if (getFromCache) {
|
||||||
|
getFromCache().then((res: string | null) => {
|
||||||
|
if (res) {
|
||||||
|
const cacheResultAction: EntityAction<any> = {
|
||||||
|
...action,
|
||||||
|
type: 'RESULT_FROM_CACHE',
|
||||||
|
data: JSON.parse(res),
|
||||||
|
}
|
||||||
|
storeApi.dispatch(cacheResultAction)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'STORE_IN_CACHE': {
|
||||||
|
const saveToCache = action.extra?.saveToCache
|
||||||
|
if (saveToCache && action.data) {
|
||||||
|
saveToCache(JSON.stringify(action.data))
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(err)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
return next(action)
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(err)
|
|
||||||
}
|
}
|
||||||
return next(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const cacheMiddleware: IMiddleware = (storeApi) => (next) => (action: EntityAction<any>) => {
|
|
||||||
try {
|
|
||||||
switch (action.type) {
|
|
||||||
case 'GET_FROM_CACHE': {
|
|
||||||
const getFromCache = action.extra?.getFromCache
|
|
||||||
if (getFromCache) {
|
|
||||||
getFromCache().then((res: string | null) => {
|
|
||||||
if (res) {
|
|
||||||
const cacheResultAction: EntityAction<any> = {
|
|
||||||
...action,
|
|
||||||
type: 'RESULT_FROM_CACHE',
|
|
||||||
data: JSON.parse(res),
|
|
||||||
}
|
|
||||||
storeApi.dispatch(cacheResultAction)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'STORE_IN_CACHE': {
|
|
||||||
const saveToCache = action.extra?.saveToCache
|
|
||||||
if (saveToCache && action.data) {
|
|
||||||
saveToCache(JSON.stringify(action.data))
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
return next(action)
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,7 +18,11 @@ describe('ApiProvider', () => {
|
||||||
api = init()
|
api = init()
|
||||||
})
|
})
|
||||||
it('enables useApi()', () => {
|
it('enables useApi()', () => {
|
||||||
const { getByTestId } = render(<ApiProvider api={api}><Login /></ApiProvider>)
|
const { getByTestId } = render(
|
||||||
|
<ApiProvider api={api}>
|
||||||
|
<Login />
|
||||||
|
</ApiProvider>
|
||||||
|
)
|
||||||
|
|
||||||
expect(getByTestId('isLoggedIn').textContent).toEqual('n')
|
expect(getByTestId('isLoggedIn').textContent).toEqual('n')
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,8 +15,12 @@ type TApiProvider = FC<
|
||||||
}>
|
}>
|
||||||
>
|
>
|
||||||
const noopReporter: Reporter = {
|
const noopReporter: Reporter = {
|
||||||
log: () => {},
|
log: () => {
|
||||||
error: () => {},
|
// noop
|
||||||
|
},
|
||||||
|
error: () => {
|
||||||
|
// noop
|
||||||
|
},
|
||||||
}
|
}
|
||||||
export const ApiProvider: TApiProvider = ({
|
export const ApiProvider: TApiProvider = ({
|
||||||
children,
|
children,
|
||||||
|
|
|
@ -15,11 +15,7 @@ describe('useCalendar(child)', () => {
|
||||||
let response
|
let response
|
||||||
let child
|
let child
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -27,14 +23,18 @@ describe('useCalendar(child)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getCalendar.mockImplementation(() => (
|
api.getCalendar.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_calendar_10': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_calendar_10': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -51,7 +51,9 @@ describe('useCalendar(child)', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useCalendar(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -63,7 +65,9 @@ describe('useCalendar(child)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useCalendar(child), { wrapper })
|
renderHook(() => useCalendar(child), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useCalendar(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useCalendar(child), { wrapper })
|
renderHook(() => useCalendar(child), { wrapper })
|
||||||
|
@ -80,7 +84,10 @@ describe('useCalendar(child)', () => {
|
||||||
it('retrieves data from cache', async () => {
|
it('retrieves data from cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -92,7 +99,10 @@ describe('useCalendar(child)', () => {
|
||||||
storage.clear()
|
storage.clear()
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -103,7 +113,10 @@ describe('useCalendar(child)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -114,7 +127,10 @@ describe('useCalendar(child)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -128,7 +144,9 @@ describe('useCalendar(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useCalendar(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -143,7 +161,9 @@ describe('useCalendar(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useCalendar(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -158,7 +178,10 @@ describe('useCalendar(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getCalendar.mockRejectedValueOnce(error)
|
api.getCalendar.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -186,7 +209,10 @@ describe('useCalendar(child)', () => {
|
||||||
api.getCalendar.mockRejectedValueOnce(error)
|
api.getCalendar.mockRejectedValueOnce(error)
|
||||||
api.getCalendar.mockRejectedValueOnce(error)
|
api.getCalendar.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -213,7 +239,10 @@ describe('useCalendar(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getCalendar.mockRejectedValueOnce(error)
|
api.getCalendar.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useCalendar(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useCalendar(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -221,7 +250,10 @@ describe('useCalendar(child)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting CALENDAR from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting CALENDAR from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -18,38 +18,43 @@ describe('useChildList()', () => {
|
||||||
let echildrenResponse
|
let echildrenResponse
|
||||||
let skola24Response
|
let skola24Response
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
echildrenCache = [{ id: 2, name: 'Uwe Übrink (elev)' }]
|
echildrenCache = [{ id: 2, name: 'Uwe Übrink (elev)' }]
|
||||||
skola24Cache = [{ personGuid: '2', firstName: 'Uwe', lastName: 'Vredstein Übrink' }]
|
skola24Cache = [
|
||||||
|
{ personGuid: '2', firstName: 'Uwe', lastName: 'Vredstein Übrink' },
|
||||||
|
]
|
||||||
|
|
||||||
echildrenResponse = [{ id: 1, name: 'Uwe Übrink (elev)' }]
|
echildrenResponse = [{ id: 1, name: 'Uwe Übrink (elev)' }]
|
||||||
skola24Response = [{ personGuid: '1', firstName: 'Uwe', lastName: 'Vredstein Übrink' }]
|
skola24Response = [
|
||||||
|
{ personGuid: '1', firstName: 'Uwe', lastName: 'Vredstein Übrink' },
|
||||||
|
]
|
||||||
|
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
|
|
||||||
api.getChildren.mockImplementation(() => (
|
api.getChildren.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(echildrenResponse), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(echildrenResponse), 50)
|
||||||
))
|
})
|
||||||
api.getSkola24Children.mockImplementation(() => (
|
)
|
||||||
new Promise((res) => {
|
api.getSkola24Children.mockImplementation(
|
||||||
setTimeout(() => res(skola24Response), 50)
|
() =>
|
||||||
})
|
new Promise((res) => {
|
||||||
))
|
setTimeout(() => res(skola24Response), 50)
|
||||||
storage = createStorage({
|
})
|
||||||
'123_etjanst_children': echildrenCache,
|
)
|
||||||
'123_skola24_children': skola24Cache,
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_etjanst_children': echildrenCache,
|
||||||
|
'123_skola24_children': skola24Cache,
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -65,7 +70,9 @@ describe('useChildList()', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -78,7 +85,9 @@ describe('useChildList()', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useChildList(), { wrapper })
|
renderHook(() => useChildList(), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useChildList(), { wrapper })
|
renderHook(() => useChildList(), { wrapper })
|
||||||
|
@ -97,7 +106,9 @@ describe('useChildList()', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -105,19 +116,23 @@ describe('useChildList()', () => {
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
|
||||||
expect(result.current.data).toEqual([{
|
expect(result.current.data).toEqual([
|
||||||
id: 2,
|
{
|
||||||
name: 'Uwe Übrink (elev)',
|
id: 2,
|
||||||
personGuid: '2',
|
name: 'Uwe Übrink (elev)',
|
||||||
firstName: 'Uwe',
|
personGuid: '2',
|
||||||
lastName: 'Vredstein Übrink',
|
firstName: 'Uwe',
|
||||||
}])
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -128,7 +143,9 @@ describe('useChildList()', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -145,7 +162,9 @@ describe('useChildList()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -155,8 +174,12 @@ describe('useChildList()', () => {
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_etjanst_children']).toEqual(JSON.stringify(echildrenResponse))
|
expect(storage.cache['123_etjanst_children']).toEqual(
|
||||||
expect(storage.cache['123_skola24_children']).toEqual(JSON.stringify(skola24Response))
|
JSON.stringify(echildrenResponse)
|
||||||
|
)
|
||||||
|
expect(storage.cache['123_skola24_children']).toEqual(
|
||||||
|
JSON.stringify(skola24Response)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('does not store in cache if fake', async () => {
|
it('does not store in cache if fake', async () => {
|
||||||
|
@ -164,7 +187,9 @@ describe('useChildList()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -172,8 +197,12 @@ describe('useChildList()', () => {
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(result.current.status).toEqual('loaded')
|
expect(result.current.status).toEqual('loaded')
|
||||||
expect(storage.cache['123_etjanst_children']).toEqual(JSON.stringify(echildrenCache))
|
expect(storage.cache['123_etjanst_children']).toEqual(
|
||||||
expect(storage.cache['123_skola24_children']).toEqual(JSON.stringify(skola24Cache))
|
JSON.stringify(echildrenCache)
|
||||||
|
)
|
||||||
|
expect(storage.cache['123_skola24_children']).toEqual(
|
||||||
|
JSON.stringify(skola24Cache)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('retries if etjanst-api fails', async () => {
|
it('retries if etjanst-api fails', async () => {
|
||||||
|
@ -182,7 +211,9 @@ describe('useChildList()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -202,13 +233,15 @@ describe('useChildList()', () => {
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
|
||||||
expect(result.current.status).toEqual('loaded')
|
expect(result.current.status).toEqual('loaded')
|
||||||
expect(result.current.data).toEqual([{
|
expect(result.current.data).toEqual([
|
||||||
id: 1,
|
{
|
||||||
name: 'Uwe Übrink (elev)',
|
id: 1,
|
||||||
personGuid: '1',
|
name: 'Uwe Übrink (elev)',
|
||||||
firstName: 'Uwe',
|
personGuid: '1',
|
||||||
lastName: 'Vredstein Übrink',
|
firstName: 'Uwe',
|
||||||
}])
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('gives up after 3 retries', async () => {
|
it('gives up after 3 retries', async () => {
|
||||||
|
@ -219,7 +252,9 @@ describe('useChildList()', () => {
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -240,13 +275,15 @@ describe('useChildList()', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
expect(result.current.status).toEqual('error')
|
expect(result.current.status).toEqual('error')
|
||||||
expect(result.current.data).toEqual([{
|
expect(result.current.data).toEqual([
|
||||||
id: 2,
|
{
|
||||||
name: 'Uwe Übrink (elev)',
|
id: 2,
|
||||||
personGuid: '1',
|
name: 'Uwe Übrink (elev)',
|
||||||
firstName: 'Uwe',
|
personGuid: '1',
|
||||||
lastName: 'Vredstein Übrink',
|
firstName: 'Uwe',
|
||||||
}])
|
lastName: 'Vredstein Übrink',
|
||||||
|
},
|
||||||
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('reports if api fails', async () => {
|
it('reports if api fails', async () => {
|
||||||
|
@ -255,7 +292,9 @@ describe('useChildList()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useChildList(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useChildList(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -263,7 +302,10 @@ describe('useChildList()', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting ETJANST_CHILDREN from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting ETJANST_CHILDREN from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,11 +15,7 @@ describe('useClassmates(child)', () => {
|
||||||
let response
|
let response
|
||||||
let child
|
let child
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -27,14 +23,18 @@ describe('useClassmates(child)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getClassmates.mockImplementation(() => (
|
api.getClassmates.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_classmates_10': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_classmates_10': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -51,7 +51,9 @@ describe('useClassmates(child)', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useClassmates(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -63,7 +65,9 @@ describe('useClassmates(child)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useClassmates(child), { wrapper })
|
renderHook(() => useClassmates(child), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useClassmates(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useClassmates(child), { wrapper })
|
renderHook(() => useClassmates(child), { wrapper })
|
||||||
|
@ -80,7 +84,10 @@ describe('useClassmates(child)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -91,7 +98,10 @@ describe('useClassmates(child)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -102,7 +112,10 @@ describe('useClassmates(child)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -116,7 +129,9 @@ describe('useClassmates(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useClassmates(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -131,7 +146,9 @@ describe('useClassmates(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useClassmates(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -146,7 +163,10 @@ describe('useClassmates(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getClassmates.mockRejectedValueOnce(error)
|
api.getClassmates.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -174,7 +194,10 @@ describe('useClassmates(child)', () => {
|
||||||
api.getClassmates.mockRejectedValueOnce(error)
|
api.getClassmates.mockRejectedValueOnce(error)
|
||||||
api.getClassmates.mockRejectedValueOnce(error)
|
api.getClassmates.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -201,7 +224,10 @@ describe('useClassmates(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getClassmates.mockRejectedValueOnce(error)
|
api.getClassmates.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useClassmates(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useClassmates(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -209,7 +235,10 @@ describe('useClassmates(child)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting CLASSMATES from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting CLASSMATES from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,11 +14,7 @@ describe('useEtjanstChildren()', () => {
|
||||||
let storage
|
let storage
|
||||||
let response
|
let response
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -26,14 +22,18 @@ describe('useEtjanstChildren()', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getChildren.mockImplementation(() => (
|
api.getChildren.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_etjanst_children': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_etjanst_children': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -49,7 +49,9 @@ describe('useEtjanstChildren()', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -61,7 +63,9 @@ describe('useEtjanstChildren()', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useEtjanstChildren(), { wrapper })
|
renderHook(() => useEtjanstChildren(), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useEtjanstChildren(), { wrapper })
|
renderHook(() => useEtjanstChildren(), { wrapper })
|
||||||
|
@ -78,7 +82,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -89,7 +96,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -100,7 +110,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -114,7 +127,9 @@ describe('useEtjanstChildren()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -129,7 +144,9 @@ describe('useEtjanstChildren()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useEtjanstChildren(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -144,7 +161,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -172,7 +192,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -199,7 +222,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getChildren.mockRejectedValueOnce(error)
|
api.getChildren.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useEtjanstChildren(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useEtjanstChildren(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -207,7 +233,10 @@ describe('useEtjanstChildren()', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting ETJANST_CHILDREN from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting ETJANST_CHILDREN from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,11 +15,7 @@ describe('useMenu(child)', () => {
|
||||||
let response
|
let response
|
||||||
let child
|
let child
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -27,14 +23,18 @@ describe('useMenu(child)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getMenu.mockImplementation(() => (
|
api.getMenu.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_menu_10': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_menu_10': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -51,7 +51,9 @@ describe('useMenu(child)', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -63,7 +65,9 @@ describe('useMenu(child)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useMenu(child), { wrapper })
|
renderHook(() => useMenu(child), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useMenu(child), { wrapper })
|
renderHook(() => useMenu(child), { wrapper })
|
||||||
|
@ -80,7 +84,9 @@ describe('useMenu(child)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -91,7 +97,9 @@ describe('useMenu(child)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -102,7 +110,9 @@ describe('useMenu(child)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -116,7 +126,9 @@ describe('useMenu(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -131,7 +143,9 @@ describe('useMenu(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -146,7 +160,9 @@ describe('useMenu(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getMenu.mockRejectedValueOnce(error)
|
api.getMenu.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -174,7 +190,9 @@ describe('useMenu(child)', () => {
|
||||||
api.getMenu.mockRejectedValueOnce(error)
|
api.getMenu.mockRejectedValueOnce(error)
|
||||||
api.getMenu.mockRejectedValueOnce(error)
|
api.getMenu.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -201,7 +219,9 @@ describe('useMenu(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getMenu.mockRejectedValueOnce(error)
|
api.getMenu.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useMenu(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -209,7 +229,10 @@ describe('useMenu(child)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting MENU from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting MENU from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,11 +15,7 @@ describe('useNews(child)', () => {
|
||||||
let response
|
let response
|
||||||
let child
|
let child
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -27,14 +23,18 @@ describe('useNews(child)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getNews.mockImplementation(() => (
|
api.getNews.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_news_10': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_news_10': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -51,7 +51,9 @@ describe('useNews(child)', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -63,7 +65,9 @@ describe('useNews(child)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useNews(child), { wrapper })
|
renderHook(() => useNews(child), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useNews(child), { wrapper })
|
renderHook(() => useNews(child), { wrapper })
|
||||||
|
@ -80,7 +84,9 @@ describe('useNews(child)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -91,7 +97,9 @@ describe('useNews(child)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -102,7 +110,9 @@ describe('useNews(child)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -116,7 +126,9 @@ describe('useNews(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -131,7 +143,9 @@ describe('useNews(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -146,7 +160,9 @@ describe('useNews(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNews.mockRejectedValueOnce(error)
|
api.getNews.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -174,7 +190,9 @@ describe('useNews(child)', () => {
|
||||||
api.getNews.mockRejectedValueOnce(error)
|
api.getNews.mockRejectedValueOnce(error)
|
||||||
api.getNews.mockRejectedValueOnce(error)
|
api.getNews.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -201,7 +219,9 @@ describe('useNews(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNews.mockRejectedValueOnce(error)
|
api.getNews.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNews(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useNews(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -209,7 +229,10 @@ describe('useNews(child)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting NEWS from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting NEWS from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,11 +17,7 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
let child
|
let child
|
||||||
let newsItem
|
let newsItem
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -30,14 +26,18 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
response = { id: '1337', modified: 'now', body: 'rich and new' }
|
response = { id: '1337', modified: 'now', body: 'rich and new' }
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getNewsDetails.mockImplementation(() => (
|
api.getNewsDetails.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_news_details_1337': { ...cached },
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_news_details_1337': { ...cached },
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
newsItem = { id: '1337', modified: 'now', body: 'simple' }
|
newsItem = { id: '1337', modified: 'now', body: 'simple' }
|
||||||
})
|
})
|
||||||
|
@ -48,14 +48,19 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('returns correct initial value', () => {
|
it('returns correct initial value', () => {
|
||||||
const { result } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result } = renderHook(() => useNewsDetails(child, newsItem), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
expect(result.current.status).toEqual('pending')
|
expect(result.current.status).toEqual('pending')
|
||||||
})
|
})
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -67,7 +72,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
||||||
|
@ -75,7 +83,9 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
|
||||||
const { result } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result } = renderHook(() => useNewsDetails(child, newsItem), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
expect(api.getNewsDetails).toHaveBeenCalledTimes(1)
|
expect(api.getNewsDetails).toHaveBeenCalledTimes(1)
|
||||||
expect(result.current.status).toEqual('loaded')
|
expect(result.current.status).toEqual('loaded')
|
||||||
|
@ -84,7 +94,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -95,7 +108,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -106,7 +122,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -120,14 +139,19 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_news_details_1337']).toEqual(JSON.stringify(response))
|
expect(storage.cache['123_news_details_1337']).toEqual(
|
||||||
|
JSON.stringify(response)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('does not store in cache if fake', async () => {
|
it('does not store in cache if fake', async () => {
|
||||||
|
@ -135,13 +159,18 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_news_details_1337']).toEqual(JSON.stringify(cached))
|
expect(storage.cache['123_news_details_1337']).toEqual(
|
||||||
|
JSON.stringify(cached)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('retries if api fails', async () => {
|
it('retries if api fails', async () => {
|
||||||
|
@ -150,7 +179,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNewsDetails.mockRejectedValueOnce(error)
|
api.getNewsDetails.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -178,7 +210,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
api.getNewsDetails.mockRejectedValueOnce(error)
|
api.getNewsDetails.mockRejectedValueOnce(error)
|
||||||
api.getNewsDetails.mockRejectedValueOnce(error)
|
api.getNewsDetails.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -205,7 +240,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNewsDetails.mockRejectedValueOnce(error)
|
api.getNewsDetails.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNewsDetails(child, newsItem), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNewsDetails(child, newsItem),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -213,7 +251,10 @@ describe('useNewsDetails(child, newsItem)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting NEWS_DETAILS from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting NEWS_DETAILS from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,11 +15,7 @@ describe('useNotifications(child)', () => {
|
||||||
let response
|
let response
|
||||||
let child
|
let child
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -27,14 +23,18 @@ describe('useNotifications(child)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getNotifications.mockImplementation(() => (
|
api.getNotifications.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_notifications_10': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_notifications_10': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -51,7 +51,9 @@ describe('useNotifications(child)', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNotifications(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -63,7 +65,9 @@ describe('useNotifications(child)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useNotifications(child), { wrapper })
|
renderHook(() => useNotifications(child), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNotifications(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useNotifications(child), { wrapper })
|
renderHook(() => useNotifications(child), { wrapper })
|
||||||
|
@ -80,7 +84,10 @@ describe('useNotifications(child)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -91,7 +98,10 @@ describe('useNotifications(child)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -102,7 +112,10 @@ describe('useNotifications(child)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -116,7 +129,9 @@ describe('useNotifications(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNotifications(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -131,7 +146,9 @@ describe('useNotifications(child)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useNotifications(child), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -146,7 +163,10 @@ describe('useNotifications(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNotifications.mockRejectedValueOnce(error)
|
api.getNotifications.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -174,7 +194,10 @@ describe('useNotifications(child)', () => {
|
||||||
api.getNotifications.mockRejectedValueOnce(error)
|
api.getNotifications.mockRejectedValueOnce(error)
|
||||||
api.getNotifications.mockRejectedValueOnce(error)
|
api.getNotifications.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -201,7 +224,10 @@ describe('useNotifications(child)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getNotifications.mockRejectedValueOnce(error)
|
api.getNotifications.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useNotifications(child), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useNotifications(child),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -209,7 +235,10 @@ describe('useNotifications(child)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting NOTIFICATIONS from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting NOTIFICATIONS from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,11 +17,7 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
let from
|
let from
|
||||||
let to
|
let to
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -29,14 +25,18 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getSchedule.mockImplementation(() => (
|
api.getSchedule.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_schedule_10_2021-01-01_2021-01-08': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_schedule_10_2021-01-01_2021-01-08': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { id: 10 }
|
child = { id: 10 }
|
||||||
from = '2021-01-01'
|
from = '2021-01-01'
|
||||||
to = '2021-01-08'
|
to = '2021-01-08'
|
||||||
|
@ -48,14 +48,19 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('returns correct initial value', () => {
|
it('returns correct initial value', () => {
|
||||||
const { result } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result } = renderHook(() => useSchedule(child, from, to), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
expect(result.current.status).toEqual('pending')
|
expect(result.current.status).toEqual('pending')
|
||||||
})
|
})
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -67,7 +72,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useSchedule(child, from, to), { wrapper })
|
renderHook(() => useSchedule(child, from, to), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useSchedule(child, from, to), { wrapper })
|
renderHook(() => useSchedule(child, from, to), { wrapper })
|
||||||
|
@ -75,7 +83,9 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
renderHook(() => useSchedule(child, from, to), { wrapper })
|
renderHook(() => useSchedule(child, from, to), { wrapper })
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
|
||||||
const { result } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result } = renderHook(() => useSchedule(child, from, to), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
expect(api.getSchedule).toHaveBeenCalledTimes(1)
|
expect(api.getSchedule).toHaveBeenCalledTimes(1)
|
||||||
expect(result.current.status).toEqual('loaded')
|
expect(result.current.status).toEqual('loaded')
|
||||||
|
@ -84,7 +94,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -95,7 +108,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -106,7 +122,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -120,14 +139,19 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_schedule_10_2021-01-01_2021-01-08']).toEqual('[{"id":1}]')
|
expect(storage.cache['123_schedule_10_2021-01-01_2021-01-08']).toEqual(
|
||||||
|
'[{"id":1}]'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('does not store in cache if fake', async () => {
|
it('does not store in cache if fake', async () => {
|
||||||
|
@ -135,13 +159,18 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_schedule_10_2021-01-01_2021-01-08']).toEqual('[{"id":2}]')
|
expect(storage.cache['123_schedule_10_2021-01-01_2021-01-08']).toEqual(
|
||||||
|
'[{"id":2}]'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('retries if api fails', async () => {
|
it('retries if api fails', async () => {
|
||||||
|
@ -150,7 +179,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getSchedule.mockRejectedValueOnce(error)
|
api.getSchedule.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -178,7 +210,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
api.getSchedule.mockRejectedValueOnce(error)
|
api.getSchedule.mockRejectedValueOnce(error)
|
||||||
api.getSchedule.mockRejectedValueOnce(error)
|
api.getSchedule.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -205,7 +240,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getSchedule.mockRejectedValueOnce(error)
|
api.getSchedule.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSchedule(child, from, to), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSchedule(child, from, to),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -213,7 +251,10 @@ describe('useSchedule(child, from, to)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting SCHEDULE from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting SCHEDULE from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,11 +14,7 @@ describe('useSkola24Children()', () => {
|
||||||
let storage
|
let storage
|
||||||
let response
|
let response
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -26,14 +22,18 @@ describe('useSkola24Children()', () => {
|
||||||
response = [{ personGuid: '1' }]
|
response = [{ personGuid: '1' }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getSkola24Children.mockImplementation(() => (
|
api.getSkola24Children.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_skola24_children': [{ personGuid: '2' }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_skola24_children': [{ personGuid: '2' }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -49,7 +49,9 @@ describe('useSkola24Children()', () => {
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -61,7 +63,9 @@ describe('useSkola24Children()', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useSkola24Children(), { wrapper })
|
renderHook(() => useSkola24Children(), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useSkola24Children(), { wrapper })
|
renderHook(() => useSkola24Children(), { wrapper })
|
||||||
|
@ -78,7 +82,10 @@ describe('useSkola24Children()', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -89,7 +96,10 @@ describe('useSkola24Children()', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -100,7 +110,10 @@ describe('useSkola24Children()', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -114,14 +127,18 @@ describe('useSkola24Children()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_skola24_children']).toEqual('[{"personGuid":"1"}]')
|
expect(storage.cache['123_skola24_children']).toEqual(
|
||||||
|
'[{"personGuid":"1"}]'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('does not store in cache if fake', async () => {
|
it('does not store in cache if fake', async () => {
|
||||||
|
@ -129,13 +146,17 @@ describe('useSkola24Children()', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { waitForNextUpdate } = renderHook(() => useSkola24Children(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await pause(20)
|
await pause(20)
|
||||||
|
|
||||||
expect(storage.cache['123_skola24_children']).toEqual('[{"personGuid":"2"}]')
|
expect(storage.cache['123_skola24_children']).toEqual(
|
||||||
|
'[{"personGuid":"2"}]'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('retries if api fails', async () => {
|
it('retries if api fails', async () => {
|
||||||
|
@ -144,7 +165,10 @@ describe('useSkola24Children()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getSkola24Children.mockRejectedValueOnce(error)
|
api.getSkola24Children.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -172,7 +196,10 @@ describe('useSkola24Children()', () => {
|
||||||
api.getSkola24Children.mockRejectedValueOnce(error)
|
api.getSkola24Children.mockRejectedValueOnce(error)
|
||||||
api.getSkola24Children.mockRejectedValueOnce(error)
|
api.getSkola24Children.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -199,7 +226,10 @@ describe('useSkola24Children()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getSkola24Children.mockRejectedValueOnce(error)
|
api.getSkola24Children.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useSkola24Children(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useSkola24Children(),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -207,7 +237,10 @@ describe('useSkola24Children()', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting SKOLA24_CHILDREN from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting SKOLA24_CHILDREN from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -18,11 +18,7 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
let year
|
let year
|
||||||
let lang
|
let lang
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -30,14 +26,18 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
response = [{ id: 1 }]
|
response = [{ id: 1 }]
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getTimetable.mockImplementation(() => (
|
api.getTimetable.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_timetable_10_15_2021_sv': [{ id: 2 }],
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_timetable_10_15_2021_sv': [{ id: 2 }],
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
child = { personGuid: '10' }
|
child = { personGuid: '10' }
|
||||||
week = 15
|
week = 15
|
||||||
year = 2021
|
year = 2021
|
||||||
|
@ -50,14 +50,19 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it('returns correct initial value', () => {
|
it('returns correct initial value', () => {
|
||||||
const { result } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result } = renderHook(() => useTimetable(child, week, year, lang), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
expect(result.current.status).toEqual('pending')
|
expect(result.current.status).toEqual('pending')
|
||||||
})
|
})
|
||||||
it('calls api', async () => {
|
it('calls api', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -69,7 +74,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
||||||
const { waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
||||||
|
@ -77,7 +85,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
|
||||||
const { result } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
expect(api.getTimetable).toHaveBeenCalledTimes(1)
|
expect(api.getTimetable).toHaveBeenCalledTimes(1)
|
||||||
expect(result.current.status).toEqual('loaded')
|
expect(result.current.status).toEqual('loaded')
|
||||||
|
@ -86,7 +97,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -97,7 +111,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -108,7 +125,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -122,7 +142,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = false
|
api.isFake = false
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -137,7 +160,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
api.isFake = true
|
api.isFake = true
|
||||||
|
|
||||||
const { waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -152,7 +178,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getTimetable.mockRejectedValueOnce(error)
|
api.getTimetable.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -180,7 +209,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
api.getTimetable.mockRejectedValueOnce(error)
|
api.getTimetable.mockRejectedValueOnce(error)
|
||||||
api.getTimetable.mockRejectedValueOnce(error)
|
api.getTimetable.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -207,7 +239,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getTimetable.mockRejectedValueOnce(error)
|
api.getTimetable.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useTimetable(child, week, year, lang), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(
|
||||||
|
() => useTimetable(child, week, year, lang),
|
||||||
|
{ wrapper }
|
||||||
|
)
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -215,7 +250,10 @@ describe('useTimetable(child, week, year, lang)', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting TIMETABLE from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting TIMETABLE from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,11 +14,7 @@ describe('useUser()', () => {
|
||||||
let storage
|
let storage
|
||||||
let response
|
let response
|
||||||
const wrapper = ({ children }) => (
|
const wrapper = ({ children }) => (
|
||||||
<ApiProvider
|
<ApiProvider api={api} storage={storage} reporter={reporter}>
|
||||||
api={api}
|
|
||||||
storage={storage}
|
|
||||||
reporter={reporter}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</ApiProvider>
|
</ApiProvider>
|
||||||
)
|
)
|
||||||
|
@ -26,14 +22,18 @@ describe('useUser()', () => {
|
||||||
response = { id: 1 }
|
response = { id: 1 }
|
||||||
api = init()
|
api = init()
|
||||||
api.getPersonalNumber.mockReturnValue('123')
|
api.getPersonalNumber.mockReturnValue('123')
|
||||||
api.getUser.mockImplementation(() => (
|
api.getUser.mockImplementation(
|
||||||
new Promise((res) => {
|
() =>
|
||||||
setTimeout(() => res(response), 50)
|
new Promise((res) => {
|
||||||
})
|
setTimeout(() => res(response), 50)
|
||||||
))
|
})
|
||||||
storage = createStorage({
|
)
|
||||||
'123_user': { id: 2 },
|
storage = createStorage(
|
||||||
}, 2)
|
{
|
||||||
|
'123_user': { id: 2 },
|
||||||
|
},
|
||||||
|
2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
@ -78,7 +78,9 @@ describe('useUser()', () => {
|
||||||
it('calls cache', async () => {
|
it('calls cache', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -89,7 +91,9 @@ describe('useUser()', () => {
|
||||||
it('updates status to loading', async () => {
|
it('updates status to loading', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -100,7 +104,9 @@ describe('useUser()', () => {
|
||||||
it('updates status to loaded', async () => {
|
it('updates status to loaded', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -144,7 +150,9 @@ describe('useUser()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getUser.mockRejectedValueOnce(error)
|
api.getUser.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -172,7 +180,9 @@ describe('useUser()', () => {
|
||||||
api.getUser.mockRejectedValueOnce(error)
|
api.getUser.mockRejectedValueOnce(error)
|
||||||
api.getUser.mockRejectedValueOnce(error)
|
api.getUser.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -199,7 +209,9 @@ describe('useUser()', () => {
|
||||||
const error = new Error('fail')
|
const error = new Error('fail')
|
||||||
api.getUser.mockRejectedValueOnce(error)
|
api.getUser.mockRejectedValueOnce(error)
|
||||||
|
|
||||||
const { result, waitForNextUpdate } = renderHook(() => useUser(), { wrapper })
|
const { result, waitForNextUpdate } = renderHook(() => useUser(), {
|
||||||
|
wrapper,
|
||||||
|
})
|
||||||
|
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
await waitForNextUpdate()
|
await waitForNextUpdate()
|
||||||
|
@ -207,7 +219,10 @@ describe('useUser()', () => {
|
||||||
|
|
||||||
expect(result.current.error).toEqual(error)
|
expect(result.current.error).toEqual(error)
|
||||||
|
|
||||||
expect(reporter.error).toHaveBeenCalledWith(error, 'Error getting USER from API')
|
expect(reporter.error).toHaveBeenCalledWith(
|
||||||
|
error,
|
||||||
|
'Error getting USER from API'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -83,6 +83,7 @@
|
||||||
"@react-native-community/cli": "6.0.0",
|
"@react-native-community/cli": "6.0.0",
|
||||||
"@react-native-community/cli-platform-android": "6.0.0",
|
"@react-native-community/cli-platform-android": "6.0.0",
|
||||||
"@react-native-community/cli-platform-ios": "6.0.0",
|
"@react-native-community/cli-platform-ios": "6.0.0",
|
||||||
|
"@react-native-community/eslint-config": "^3.0.1",
|
||||||
"@testing-library/jest-dom": "5.14.1",
|
"@testing-library/jest-dom": "5.14.1",
|
||||||
"@testing-library/jest-native": "4.0.2",
|
"@testing-library/jest-native": "4.0.2",
|
||||||
"@testing-library/react": "11.2.6",
|
"@testing-library/react": "11.2.6",
|
||||||
|
@ -91,6 +92,7 @@
|
||||||
"@types/base-64": "^1.0.0",
|
"@types/base-64": "^1.0.0",
|
||||||
"@types/detox": "17.14.2",
|
"@types/detox": "17.14.2",
|
||||||
"@types/he": "^1.1.1",
|
"@types/he": "^1.1.1",
|
||||||
|
"@types/i18n-js": "^3.8.2",
|
||||||
"@types/jest": "26.0.24",
|
"@types/jest": "26.0.24",
|
||||||
"@types/luxon": "^1.26.4",
|
"@types/luxon": "^1.26.4",
|
||||||
"@types/node": "14.14.33",
|
"@types/node": "14.14.33",
|
||||||
|
@ -110,6 +112,7 @@
|
||||||
"eslint-plugin-jsx-a11y": "6.4.1",
|
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||||
"eslint-plugin-react": "7.23.1",
|
"eslint-plugin-react": "7.23.1",
|
||||||
"eslint-plugin-react-hooks": "4.2.0",
|
"eslint-plugin-react-hooks": "4.2.0",
|
||||||
|
"eslint-plugin-react-native-a11y": "^2.0.4",
|
||||||
"fetch-cookie": "^0.11.0",
|
"fetch-cookie": "^0.11.0",
|
||||||
"https-proxy-agent": "^5.0.0",
|
"https-proxy-agent": "^5.0.0",
|
||||||
"jest": "27.0.3",
|
"jest": "27.0.3",
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
|
"strict": true,
|
||||||
"lib": ["es2017", "dom"],
|
"lib": ["es2017", "dom"],
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"skipDefaultLibCheck": true,
|
"skipDefaultLibCheck": true,
|
||||||
|
|
Loading…
Reference in New Issue