generated from KTH/node-web
-
Notifications
You must be signed in to change notification settings - Fork 1
KUI-2067: map to syllabusValid object (undefined showing in header) #447
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
Open
axelbjo
wants to merge
9
commits into
master
Choose a base branch
from
issues/KUI-2067-undefined-shown-in-header
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+717
−36
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f120a14
fix(KUI-2067): added mapping and helper function for syllabusValid ob…
axelbjo affc563
fix(KUI-2067): requested changes
axelbjo 2cda744
fix(KUI-2067): more null checking
axelbjo 4b77587
fix(KUI-2067): requested changes
axelbjo 34c5a50
test(KUI-2067): added test for parseLadokSemester
axelbjo 5c1d1b7
fix(KUI-2067): requested changes
axelbjo b1621d1
chore(KUI-2067): cleanup
axelbjo ae67642
chore(KUI-2067): cleanup
axelbjo bdbf78f
fix(KUI-2067): fixed incorrect extraction of object values
axelbjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
belanglos marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,52 @@ | ||
| const { | ||
| calcPreviousSemester, | ||
| parseSemesterIntoYearSemesterNumber, | ||
| SemesterNumber, | ||
| LadokSemesterPrefix, | ||
| } = require('../../shared/semesterUtils') | ||
|
|
||
| const sortSyllabusesByGiltigFrom = syllabuses => | ||
| syllabuses.sort((a, b) => { | ||
| const { year: yearA, semesterNumber: semesterNumberA } = parseSemesterIntoYearSemesterNumber(a.kursplan?.giltigfrom) | ||
|
|
||
| const { year: yearB, semesterNumber: semesterNumberB } = parseSemesterIntoYearSemesterNumber(b.kursplan?.giltigfrom) | ||
|
|
||
| // First sort by year, then by termOrder | ||
| if (yearA !== yearB) return yearA - yearB | ||
| return semesterNumberA - semesterNumberB | ||
| }) | ||
|
|
||
| const getValidUntilTerm = (syllabuses, currentSyllabus) => { | ||
| // Sort syllabuses by semester in ascending order | ||
| if (!Array.isArray(syllabuses) || syllabuses.length === 0 || !currentSyllabus) { | ||
| return undefined | ||
| } | ||
| const syllabusesSortedByGiltigFrom = sortSyllabusesByGiltigFrom(syllabuses) | ||
| // Prevent duplicates | ||
| const seen = new Set() | ||
| const syllabusesUniqueGiltigFrom = syllabusesSortedByGiltigFrom.filter(item => { | ||
| const key = item.kursplan.giltigfrom | ||
| if (seen.has(key)) return false | ||
| seen.add(key) | ||
| return true | ||
| }) | ||
|
|
||
| const index = syllabusesUniqueGiltigFrom.indexOf( | ||
| syllabusesUniqueGiltigFrom.find(syllabus => syllabus.kursplan.giltigfrom === currentSyllabus.kursplan.giltigfrom) | ||
| ) | ||
| // validUntilTerm will be the term/semester before the next syllabus validFromTerm semester | ||
| if (index !== -1 && index < syllabusesUniqueGiltigFrom.length - 1) { | ||
| const nextSyllabusValidFrom = syllabusesUniqueGiltigFrom[index + 1].kursplan.giltigfrom | ||
| const semester = parseSemesterIntoYearSemesterNumber(nextSyllabusValidFrom) | ||
| return semester.semesterNumber === SemesterNumber.Autumn | ||
| ? LadokSemesterPrefix.Spring + semester.year | ||
| : LadokSemesterPrefix.Autumn + calcPreviousSemester(semester).year | ||
| } else { | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| getValidUntilTerm, | ||
| sortSyllabusesByGiltigFrom, | ||
| } |
belanglos marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,40 @@ | ||
| const { getValidUntilTerm, sortSyllabusesByGiltigFrom } = require('../utils/getValidUntilTerm') | ||
|
|
||
| describe('getValidUntilTerm', () => { | ||
| const make = term => ({ kursplan: { giltigfrom: term } }) | ||
|
|
||
| it('returns the term before the next syllabus validFrom date', () => { | ||
| const syllabuses = [make('HT2018'), make('VT2020'), make('HT2022'), make('VT2023')] | ||
| const result = getValidUntilTerm(syllabuses, make('HT2018')) | ||
| expect(result).toBe('HT2019') | ||
| }) | ||
|
|
||
| it('deduplicates by giltigfrom', () => { | ||
| const syllabuses = [make('HT2018'), make('HT2018'), make('VT2019'), make('VT2019'), make('HT2019')] | ||
|
|
||
| const result = getValidUntilTerm(syllabuses, make('HT2018')) | ||
| expect(result).toBe('HT2018') // Next unique is VT2019 | ||
| }) | ||
|
|
||
| it('should return undefined if no other syllabuses are present', () => { | ||
| const syllabuses = [make('HT2018')] | ||
| const result = getValidUntilTerm(syllabuses, make('HT2018')) | ||
| expect(result).toBe(undefined) | ||
| }) | ||
| it('should return undefined if syllabuses array is empty', () => { | ||
| const syllabuses = [] | ||
| const result = getValidUntilTerm(syllabuses, make('HT2018')) | ||
| expect(result).toBe(undefined) | ||
| }) | ||
| it('should sort syllabuses correctly', () => { | ||
| const syllabuses = [make('HT2023'), make('VT2021'), make('VT2019'), make('VT2019'), make('HT2020')] | ||
| const result = sortSyllabusesByGiltigFrom(syllabuses) | ||
| expect(result).toStrictEqual([ | ||
| { kursplan: { giltigfrom: 'VT2019' } }, | ||
| { kursplan: { giltigfrom: 'VT2019' } }, | ||
| { kursplan: { giltigfrom: 'HT2020' } }, | ||
| { kursplan: { giltigfrom: 'VT2021' } }, | ||
| { kursplan: { giltigfrom: 'HT2023' } }, | ||
| ]) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.