-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 Code cleanup, refactoring, linting and tests
I know this should be a fix but whatever...
- Loading branch information
1 parent
3d59035
commit d0a0314
Showing
13 changed files
with
238 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
module.exports = { | ||
extends: ['airbnb-typescript'], | ||
extends: [ | ||
'airbnb-typescript', | ||
'plugin:jest/recommended' | ||
], | ||
parserOptions: { | ||
project: `./tsconfig.json` | ||
project: `./tsconfig.json`, | ||
}, | ||
rules: { | ||
'@typescript-eslint/semi': ['error', 'never'] | ||
} | ||
'@typescript-eslint/semi': ['error', 'never'], | ||
'jest/no-mocks-import': [0], | ||
'max-len': [1, 110], | ||
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react' | ||
import { act, renderHook } from '@testing-library/react-hooks' | ||
import { ApiProvider } from '.' | ||
import createStorage from './__mocks__/AsyncStorage' | ||
import { | ||
useCalendar, | ||
useChildList, | ||
useClassmates, | ||
useMenu, | ||
useNews, | ||
useNotifications, | ||
useSchedule, | ||
useUser, | ||
} from './hooks' | ||
|
||
const { default: init } = jest.requireActual('@skolplattformen/embedded-api') | ||
|
||
describe('hooks with fake data', () => { | ||
let api | ||
let storage | ||
const wrapper = ({ children }) => ( | ||
<ApiProvider api={api} storage={storage}>{children}</ApiProvider> | ||
) | ||
beforeEach(async () => { | ||
api = init(() => { }, () => { }) | ||
await api.login('121212121212') | ||
|
||
storage = createStorage({}) | ||
}) | ||
it('returns user', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useUser(), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data).toEqual({ | ||
firstName: 'Namn', | ||
lastName: 'Namnsson', | ||
}) | ||
}) | ||
}) | ||
it('returns child list', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useChildList(), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data).toHaveLength(2) | ||
}) | ||
}) | ||
describe('data belonging to one child', () => { | ||
let child | ||
beforeAll(async () => { | ||
[child] = await api.getChildren() | ||
}) | ||
it('returns calendar', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useCalendar(child), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data.length).toBeGreaterThan(1) | ||
}) | ||
}) | ||
it('returns classmates', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useClassmates(child), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data.length).toBeGreaterThan(1) | ||
}) | ||
}) | ||
it('returns menu', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useMenu(child), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data.length).toBeGreaterThan(1) | ||
}) | ||
}) | ||
it('returns news', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useNews(child), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data.length).toBeGreaterThan(1) | ||
}) | ||
}) | ||
it('returns notifications', async () => { | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useNotifications(child), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
expect(result.current.data.length).toBeGreaterThan(1) | ||
}) | ||
}) | ||
it('returns schedule', async () => { | ||
const from = '2021-01-01' | ||
const to = '2021-01-08' | ||
await act(async () => { | ||
const { | ||
result, | ||
waitForNextUpdate, | ||
} = renderHook(() => useSchedule(child, from, to), { wrapper }) | ||
|
||
await waitForNextUpdate() | ||
await waitForNextUpdate() | ||
|
||
// No fake schedule in embedded-api yet | ||
expect(result.current.data.length).not.toBeGreaterThan(1) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.