forked from kolplattformen/skolplattformen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 Timetables (kolplattformen#12)
* feat: 🎸 Upgraded to api v4 * change: Changed hook from useChildlist to useEtjanstChild * feat: 🎸 Added useSkola24Children * feat: 🎸 Added useTimetable * feat: 🎸 Added back hook for useChildList This hook wraps useEtjanstChildren and useSkola24Children and merges the results
- Loading branch information
1 parent
83a4737
commit 2ae212d
Showing
15 changed files
with
1,276 additions
and
201 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
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,66 @@ | ||
import { merge } from './childlists' | ||
|
||
describe('childlists', () => { | ||
describe('merge', () => { | ||
it('works with empty skola24children list', () => { | ||
const etjanstChildren = [ | ||
{ name: 'Uwe Übrink (elev)' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
const skola24Children = [] | ||
|
||
const children = [ | ||
{ name: 'Uwe Übrink (elev)' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
expect(merge(etjanstChildren, skola24Children)).toEqual(children) | ||
}) | ||
it('works with same length skola24children list', () => { | ||
const etjanstChildren = [ | ||
{ name: 'Uwe Übrink (elev)' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
const skola24Children = [ | ||
{ firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
{ firstName: 'Cassius', lastName: 'Vredstein Übrink' }, | ||
] | ||
|
||
const children = [ | ||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
{ name: 'Cassius Übrink (elev)', firstName: 'Cassius', lastName: 'Vredstein Übrink' }, | ||
] | ||
expect(merge(etjanstChildren, skola24Children)).toEqual(children) | ||
}) | ||
it('works with different length skola24children list', () => { | ||
const etjanstChildren = [ | ||
{ name: 'Uwe Übrink (elev)' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
const skola24Children = [ | ||
{ firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
] | ||
|
||
const children = [ | ||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
expect(merge(etjanstChildren, skola24Children)).toEqual(children) | ||
}) | ||
it('works with non matching skola24children list', () => { | ||
const etjanstChildren = [ | ||
{ name: 'Uwe Übrink (elev)' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
const skola24Children = [ | ||
{ firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
{ firstName: 'Rolph', lastName: 'Gögendorff Bröök' }, | ||
] | ||
|
||
const children = [ | ||
{ name: 'Uwe Übrink (elev)', firstName: 'Uwe', lastName: 'Vredstein Übrink' }, | ||
{ name: 'Cassius Übrink (elev)' }, | ||
] | ||
expect(merge(etjanstChildren, skola24Children)).toEqual(children) | ||
}) | ||
}) | ||
}) |
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,15 @@ | ||
import { Child, EtjanstChild, Skola24Child } from '@skolplattformen/embedded-api' | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const merge = (etjanstChildren: EtjanstChild[], skola24Children: Skola24Child[]): Child[] => ( | ||
etjanstChildren.map((etjanstChild) => { | ||
const skola24Child: Skola24Child = ( | ||
skola24Children.find((s24c) => s24c.firstName && etjanstChild.name.startsWith(s24c.firstName)) || {} | ||
) | ||
const child: Child = { | ||
...etjanstChild, | ||
...skola24Child, | ||
} | ||
return child | ||
}) | ||
) |
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
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.