-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(KUI-1176): creation of syllabusName
- Loading branch information
Showing
10 changed files
with
102 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,35 @@ | ||
import React from 'react' | ||
import { Col } from 'reactstrap' | ||
import { FaAsterisk } from 'react-icons/fa' | ||
import { useLanguage } from '../hooks/useLanguage' | ||
|
||
const SyllabusInformation = ({ context = {}, syllabus = {}, hasSyllabus, translation = {} }) => { | ||
const { courseCode } = context | ||
const ActualSyllabusInformation = ({ syllabusName }) => { | ||
const { translation } = useLanguage() | ||
|
||
const { courseLabels, courseInformation } = translation | ||
const { | ||
label_course_syllabus_source: labelCourseSyllabusSource, | ||
label_course_syllabus_denoted: labelCourseSyllabusDenoted, | ||
syllabus_marker_aria_label: labelCourseSyllabusAsterisk, | ||
} = courseLabels | ||
const { course_short_semester: courseShortSemester } = courseInformation | ||
|
||
const { course_valid_from: courseValidFrom = ['', ''], course_valid_to: courseValidTo = ['', ''] } = syllabus | ||
const courseValidFromLabel = `${courseShortSemester[courseValidFrom[1]]}${courseValidFrom[0]}` | ||
const courseValidToLabel = courseValidTo.length ? courseShortSemester[courseValidTo[1]] + '' + courseValidTo[0] : '' | ||
const courseValidRangeLabel = `(${courseValidFromLabel}\u2013${courseValidToLabel})` | ||
|
||
const syllabusText = `${labelCourseSyllabusSource} ${courseCode} ${courseValidRangeLabel} ${labelCourseSyllabusDenoted}` | ||
} = translation.courseLabels | ||
|
||
return ( | ||
<Col sm="12"> | ||
<div> | ||
{hasSyllabus && ( | ||
<span> | ||
{syllabusText} | ||
{' ( '} | ||
<FaAsterisk className="syllabus-marker-icon-small" aria-label={labelCourseSyllabusAsterisk} /> | ||
{' )'} | ||
</span> | ||
)} | ||
<span> | ||
{`${labelCourseSyllabusSource} ${syllabusName} ${labelCourseSyllabusDenoted}`} | ||
{' ( '} | ||
<FaAsterisk className="syllabus-marker-icon-small" aria-label={labelCourseSyllabusAsterisk} /> | ||
{' )'} | ||
</span> | ||
</div> | ||
</Col> | ||
) | ||
} | ||
|
||
export default SyllabusInformation | ||
const SyllabusInformationOrNull = ({ syllabusName }) => { | ||
if (!syllabusName) return null | ||
|
||
return <ActualSyllabusInformation syllabusName={syllabusName} /> | ||
} | ||
|
||
export { SyllabusInformationOrNull as SyllabusInformation } |
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
39 changes: 29 additions & 10 deletions
39
public/js/app/components/__tests__/SyllabusInformation.test.js
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,16 +1,35 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import { render, screen } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
|
||
import SyllabusInformation from '../SyllabusInformation' | ||
import i18n from '../../../../../i18n' | ||
|
||
const [translationEN, translationSV] = i18n.messages | ||
import { SyllabusInformation } from '../SyllabusInformation' | ||
import { WebContextProvider } from '../../context/WebContext' | ||
|
||
describe('Component <SyllabusInformation>', () => { | ||
test('renders syllabus information in English', () => { | ||
render(<SyllabusInformation translation={translationEN} />) | ||
}) | ||
test('renders syllabus information in Swedish', () => { | ||
render(<SyllabusInformation translation={translationSV} />) | ||
test.each(['AF1745 (Spring 2023–)', 'SH2020 (Autumn 2022-Spring 2024'])( | ||
`renders syllabus information if SyllabusName "%s" is given`, | ||
syllabusName => { | ||
render( | ||
<WebContextProvider configIn={{ lang: 'en' }}> | ||
<SyllabusInformation syllabusName={syllabusName} /> | ||
</WebContextProvider> | ||
) | ||
|
||
expect( | ||
screen.getByText( | ||
`Headings with content from the Course syllabus ${syllabusName} are denoted with an asterisk ( )` | ||
) | ||
).toBeInTheDocument() | ||
} | ||
) | ||
|
||
test('does not render syllabus information if no syllabusName is given', () => { | ||
render( | ||
<WebContextProvider configIn={{ lang: 'en' }}> | ||
<SyllabusInformation syllabusName={''} /> | ||
</WebContextProvider> | ||
) | ||
|
||
expect(screen.queryByText(`Headings with content from the Course syllabus`)).not.toBeInTheDocument() | ||
}) | ||
}) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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