-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(KUI-1135): add fallback without link when SU is course department #278
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { buildCourseDepartmentLink } = require('../courseDepartmentUtils') | ||
const { INFORM_IF_IMPORTANT_INFO_IS_MISSING } = require('../constants') | ||
|
||
function htmlStringToElement(html) { | ||
const template = document.createElement('template') | ||
template.innerHTML = html | ||
const htmlElement = template.content.children[0] | ||
return htmlElement | ||
} | ||
|
||
describe('course department link utils', () => { | ||
test('returns department link', () => { | ||
const department = { code: 'JH', name: 'EECS/Datavetenskap' } | ||
const result = buildCourseDepartmentLink(department, 'en') | ||
expect(result).toBeDefined() | ||
|
||
const element = htmlStringToElement(result) | ||
expect(element.href).toBe('/eecs/') | ||
expect(element.innerHTML).toBe('EECS/Datavetenskap') | ||
}) | ||
|
||
test('returns undefined for Stockholm university as department', () => { | ||
const department = { code: 'UL', name: 'Stockholms universitet' } | ||
|
||
const result = buildCourseDepartmentLink(department, 'en') | ||
expect(result).not.toBeDefined() | ||
}) | ||
|
||
test.each([undefined, { name: undefined }])('returns fallback text if department is %p', department => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥇 I had no idea this was possible \o/ |
||
const resultSv = buildCourseDepartmentLink(department, 'sv') | ||
expect(resultSv).toBe(INFORM_IF_IMPORTANT_INFO_IS_MISSING['sv']) | ||
|
||
const resultEn = buildCourseDepartmentLink(department, 'en') | ||
expect(resultEn).toBe(INFORM_IF_IMPORTANT_INFO_IS_MISSING['en']) | ||
}) | ||
}) |
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,19 +1,21 @@ | ||
const PROGRAMME_URL = '/student/kurser/program' | ||
const INFORM_IF_IMPORTANT_INFO_IS_MISSING = { | ||
en: '<i>No information inserted</i>', | ||
sv: '<i>Ingen information tillagd</i>' | ||
sv: '<i>Ingen information tillagd</i>', | ||
} | ||
const INFORM_IF_IMPORTANT_INFO_IS_MISSING_ABOUT_MIN_FIELD_OF_STUDY = { | ||
en: 'This course does not belong to any Main field of study.', | ||
sv: 'Denna kurs tillhör inget huvudområde.' | ||
sv: 'Denna kurs tillhör inget huvudområde.', | ||
} | ||
const MAX_1_MONTH = 3 | ||
const MAX_2_MONTH = 9 | ||
const DEPARTMENT_CODE_STOCKHOLM_UNIVERSITY = 'UL' | ||
|
||
module.exports = { | ||
PROGRAMME_URL, | ||
INFORM_IF_IMPORTANT_INFO_IS_MISSING, | ||
INFORM_IF_IMPORTANT_INFO_IS_MISSING_ABOUT_MIN_FIELD_OF_STUDY, | ||
MAX_1_MONTH, | ||
MAX_2_MONTH | ||
MAX_2_MONTH, | ||
DEPARTMENT_CODE_STOCKHOLM_UNIVERSITY, | ||
} |
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,22 @@ | ||
const { INFORM_IF_IMPORTANT_INFO_IS_MISSING, DEPARTMENT_CODE_STOCKHOLM_UNIVERSITY } = require('./constants') | ||
|
||
function isDepartmentStockholmUniversity(courseDepartment) { | ||
return courseDepartment.code === DEPARTMENT_CODE_STOCKHOLM_UNIVERSITY | ||
} | ||
|
||
function buildCourseDepartmentLink(courseDepartment, language) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much more readable! |
||
if (!courseDepartment?.name) { | ||
return INFORM_IF_IMPORTANT_INFO_IS_MISSING[language] | ||
} | ||
|
||
if (isDepartmentStockholmUniversity(courseDepartment)) { | ||
return undefined | ||
} | ||
|
||
const departmentLinkPart = courseDepartment.name.split('/')[0].toLowerCase() | ||
return `<a href="/${departmentLinkPart}/" target="blank">${courseDepartment.name}</a>` | ||
} | ||
|
||
module.exports = { | ||
buildCourseDepartmentLink, | ||
} |
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.
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.
💯