Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Reload anropar bara apiet om den inte redan laddar #9

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
"publish-package": "npm publish --access public"
},
"dependencies": {
"@skolplattformen/embedded-api": "^0.22.0",
"react-redux": "^7.2.2",
"redux": "^4.0.5"
},
"peerDependencies": {
"@skolplattformen/embedded-api": "^1.3.0",
"react": "^16.11.0"
},
"devDependencies": {
"@babel/preset-env": "^7.12.13",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.12.13",
"@skolplattformen/embedded-api": "^1.3.0",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@testing-library/react-hooks": "^5.0.3",
Expand Down
32 changes: 31 additions & 1 deletion src/fake.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useSchedule,
useUser,
} from './hooks'
import store from './store'

const { default: init } = jest.requireActual('@skolplattformen/embedded-api')

Expand All @@ -35,6 +36,7 @@ describe('hooks with fake data', () => {
waitForNextUpdate,
} = renderHook(() => useUser(), { wrapper })

await waitForNextUpdate()
await waitForNextUpdate()
await waitForNextUpdate()

Expand Down Expand Up @@ -67,6 +69,7 @@ describe('hooks with fake data', () => {
waitForNextUpdate,
} = renderHook(() => useChildList(), { wrapper })

await waitForNextUpdate()
await waitForNextUpdate()
await waitForNextUpdate()

Expand All @@ -75,7 +78,7 @@ describe('hooks with fake data', () => {
})
describe('data belonging to one child', () => {
let child
beforeAll(async () => {
beforeEach(async () => {
[child] = await api.getChildren()
})
it('returns calendar', async () => {
Expand Down Expand Up @@ -159,5 +162,32 @@ describe('hooks with fake data', () => {
expect(result.current.data.length).not.toBeGreaterThan(1)
})
})

})
it('handles reloads', async () => {
await act(async () => {
store.dispatch({ type: 'CLEAR' })

const [child] = await api.getChildren()

const {
result,
waitForNextUpdate,
} = renderHook(() => useNotifications(child), { wrapper })

await waitForNextUpdate()

result.current.reload()
await waitForNextUpdate()

result.current.reload()
result.current.reload()
await waitForNextUpdate()

result.current.reload()
await waitForNextUpdate()

expect(result.current.status).toEqual('loaded')
})
})
})
2 changes: 1 addition & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const hook = <T>(
const dispatch = useDispatch()

const load = (force = false) => {
if (isLoggedIn && (force || state.status === 'pending')) {
if (isLoggedIn && state.status !== 'loading' && (force || state.status === 'pending')) {
const extra: ExtraActionProps<T> = {
key,
defaultValue,
Expand Down
28 changes: 24 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1153,16 +1153,19 @@
dependencies:
"@sinonjs/commons" "^1.7.0"

"@skolplattformen/embedded-api@^0.22.0":
version "0.22.0"
resolved "https://registry.yarnpkg.com/@skolplattformen/embedded-api/-/embedded-api-0.22.0.tgz#e6e8cad49b6f266792b56e8153bae71d0ab2b604"
integrity sha512-MnJJsnKXsw/9ybq7fzXuDoO6EjIhf2Cm5TSXzK6WL8h9ZaG9ry5jAAYFXb5MR/Gyr76IFAbAj29Uy+/dXWT/Ew==
"@skolplattformen/embedded-api@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@skolplattformen/embedded-api/-/embedded-api-1.3.0.tgz#0e0b2d8a130fdd9b303084de924730c545064b35"
integrity sha512-3K4FswSgQbDP6Mxb4DQB9eYFlv4inWBJcz3D1D57HczlH5PopxIQNCltkKlqsFDUKSGlj1QLbfgbFfsIUu6ZOA==
dependencies:
"@types/he" "^1.1.1"
camelcase-keys "^6.2.2"
events "^3.2.0"
h2m "^0.7.0"
he "^1.2.0"
js-htmlencode "^0.3.0"
luxon "^1.25.0"
node-html-parser "^2.1.0"

"@testing-library/dom@^7.28.1":
version "7.29.4"
Expand Down Expand Up @@ -1257,6 +1260,11 @@
dependencies:
"@types/node" "*"

"@types/he@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/he/-/he-1.1.1.tgz#19e14033c4ee8f1a702c74dcc6182664839ac2b7"
integrity sha512-jpzrsR1ns0n3kyWt92QfOUQhIuJGQ9+QGa7M62rO6toe98woQjnsnzjdMtsQXCdvjjmqjS2ZBCC7xKw0cdzU+Q==

"@types/hoist-non-react-statics@^3.3.0":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz"
Expand Down Expand Up @@ -3150,6 +3158,11 @@ has@^1.0.3:
dependencies:
function-bind "^1.1.1"

[email protected], he@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz"
Expand Down Expand Up @@ -4314,6 +4327,13 @@ nice-try@^1.0.4:
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==

node-html-parser@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/node-html-parser/-/node-html-parser-2.1.0.tgz#36345804d743a5a1f672d4821a53f6b0e60629a9"
integrity sha512-kbCNfqjrwHAbG+mevL8aqjwVtF0Qv66XurWHoGLOc5G9rPR1L3k602jfeczAUUBldLNnCrdsDmO5G5nqAoMW+g==
dependencies:
he "1.2.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz"
Expand Down