-
Notifications
You must be signed in to change notification settings - Fork 1
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
KUI-1523: fix 'undefined' course title in sub header #394
Conversation
axelbjo
commented
Oct 30, 2024
- Handled correct mapping of credits and title for course title
- Updated tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I agree with Karl comments as well
I've tested this and noticed that we made mistakes regarding languages earlier in the We need to use memo language and user language in the correct places. First I noticed that the language of the title of the memo always will be created based on user language and not memo as in ref (might be introduced in this PR or earlier). And then I noticed that some content has incorrect language as well (not introduced in this PR). Feels like the code is very confusing about this from before, so my suggestion is that we look at this with together next week and try fix it and refactor it to make it more clear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above
Made it so that memo language is always used for fetching data. That seems to give the correct behaviour when I test it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a bug where a memo get wrong language, see my new comment in ladokApi.js.
I have not looked into the tests in details, but as I wrote in the other PR they needs to be fixed (or removed if not useful anymore)
// test('combine course name for an object from a course rounds information endpoint in Swedish', () => { | ||
// const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'sv') | ||
// expect(courseTitle).toBe('ALLLLL Tillämpad programmering och datalogi 9.0 hp') | ||
// }) | ||
|
||
test('combine course name for an object from a course rounds endpoint in English', () => { | ||
const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'en') | ||
expect(courseTitle).toBe('ALLLLL Applied Programming and Computer Science 9.0 credits') | ||
}) | ||
// test('combine course name for an object from a course rounds endpoint in English', () => { | ||
// const courseTitle = combinedCourseName('ALLLLL', courseTypeTwo.course, 'en') | ||
// expect(courseTitle).toBe('ALLLLL Applied Programming and Computer Science 9.0 credits') | ||
// }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix test?
server/ladokApi.js
Outdated
sv: round.undervisningssprak ? round.undervisningssprak.name : '', | ||
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '', | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My memo gets wrong language if I create a new memo for a course in Swedish using English as user language.
The reason is that in _roundsCommonLanguages we are checking if language.en
is "Swedish" to determine with memoLang to create the memo with (but it will be "Svenska" now).
To fix this with current setup, you could to something like this:
language: {
sv: (lang === 'sv' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
en: (lang === 'en' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '',
},
BUT I think it would be better to just set the language abbrev/code as property here instead, and then just use that one as is in the frontend to avoid these problem. Not sure, but maybe you still need to language string as well in other places? But I would suggestion moving from comparing with name anyway.
Note that the code in Ladok and our code isn't the same format ("sv" vs "SWE").
sv: round.undervisningssprak ? round.undervisningssprak.name : '', | |
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '', | |
}, | |
code: round.undervisningssprak.code === 'SWE' ? 'sv' : 'en' | |
sv: (lang === 'sv' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '', | |
en: (lang === 'en' ? round.undervisningssprak?.name : round.undervisningssprak?.nameOther) ?? '', | |
}, |
Or maybe both language isn't needed, so that it could be like this?
sv: round.undervisningssprak ? round.undervisningssprak.name : '', | |
en: round.undervisningssprak ? round.undervisningssprak.nameOther : '', | |
}, | |
name: round.undervisningssprak?.name ?? '', | |
code: round.undervisningssprak.code === 'SWE' ? 'sv' : 'en' | |
}, |
test/unit/ChangePublished.test.js
Outdated
// TODO: this test currently fails because the ladok data already has the correct translation once it's fetched | ||
|
||
// test('renders main subheader, course name. English.', () => { | ||
// render(<ChangedPublishedEmpty langAbbr="en" langIndex={0} />) | ||
// const headers = getAllByRole('heading', { level: 1 }) | ||
// expect(headers.length).toBe(1) | ||
// expect(headers[0]).toHaveTextContent('Edit published course memoEF1111 Project in Plasma Physics 9.0 credits') | ||
// }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix test?
test/unit/CreateNewMemo.test.js
Outdated
// TODO: this test currently fails because the ladok data already has the correct translation once it's fetched | ||
|
||
// test('renders main subheader, course name. English.', () => { | ||
// render(<CreateNewMemoPage langAbbr="en" langIndex={0} />) | ||
// const headers = screen.getAllByRole('heading', { level: 1 }) | ||
// expect(headers.length).toBe(1) | ||
// expect(headers[0]).toHaveTextContent('EF1111 Project in Plasma Physics 9.0 credits') | ||
// }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix test?
server/ladokApi.js
Outdated
campus: { | ||
sv: round.studieort ? round.studieort.name : '', | ||
en: round.studieort ? round.studieort.nameOther : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing with language and "other" here, but I can't see that campus is used anywhere, so maybe it can be removed instead of fixed.