-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dispaly skills in course header (#239)
- Loading branch information
1 parent
de8f173
commit d4bc1c6
Showing
7 changed files
with
144 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { useContext, useState } from 'react'; | ||
import { Badge, Button } from '@edx/paragon'; | ||
|
||
import { CourseContext } from './CourseContextProvider'; | ||
import { SKILLS_BUTTON_LABEL } from './data/constants'; | ||
|
||
export const MAX_VISIBLE_SKILLS = 5; | ||
|
||
export default function CourseSkills() { | ||
const { state } = useContext(CourseContext); | ||
const { skillNames } = state.course; | ||
const [showMore, setShowMore] = useState(false); | ||
const skillsButtonLabel = showMore ? SKILLS_BUTTON_LABEL.SHOW_LESS : SKILLS_BUTTON_LABEL.SHOW_MORE; | ||
|
||
return ( | ||
<div className="mb-4"> | ||
<h6> Skills you'll gain</h6> | ||
<div> | ||
{skillNames.map((skill, index) => ( | ||
<Badge | ||
key={skill.id} | ||
className="course-skill" | ||
variant="light" | ||
style={{ display: ((index < MAX_VISIBLE_SKILLS) || showMore) ? 'inline-block' : 'none' }} | ||
> | ||
{ skill } | ||
</Badge> | ||
))} | ||
{skillNames.length > MAX_VISIBLE_SKILLS && ( | ||
<Button className="d-inline-block" variant="link" onClick={() => { setShowMore(!showMore); }}> | ||
{ skillsButtonLabel } | ||
</Button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
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,7 @@ | ||
.course-skill { | ||
padding: 6px; | ||
margin-right: 7px; | ||
margin-top: 8px; | ||
font-size: 12.5px; | ||
font-weight: normal; | ||
} |
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,79 @@ | ||
import React from 'react'; | ||
import { AppContext } from '@edx/frontend-platform/react'; | ||
import { screen, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
import { CourseContextProvider } from '../CourseContextProvider'; | ||
import CourseSkills, { MAX_VISIBLE_SKILLS } from '../CourseSkills'; | ||
|
||
import { SKILLS_BUTTON_LABEL } from '../data/constants'; | ||
|
||
/* eslint-disable react/prop-types */ | ||
const CourseSkillsWithContext = ({ | ||
initialAppState = {}, | ||
initialCourseState = {}, | ||
}) => ( | ||
<AppContext.Provider value={initialAppState}> | ||
<CourseContextProvider initialState={initialCourseState}> | ||
<CourseSkills /> | ||
</CourseContextProvider> | ||
</AppContext.Provider> | ||
); | ||
/* eslint-enable react/prop-types */ | ||
|
||
describe('<CourseSkills />', () => { | ||
const initialAppState = { | ||
enterpriseConfig: { | ||
slug: 'test-enterprise-slug', | ||
}, | ||
}; | ||
const initialCourseState = { | ||
course: { | ||
skillNames: ['test-skill1', 'test-skill2', 'test-skill3', 'test-skill4'], | ||
}, | ||
}; | ||
|
||
test('renders course skills less than limit', () => { | ||
render( | ||
<CourseSkillsWithContext | ||
initialAppState={initialAppState} | ||
initialCourseState={initialCourseState} | ||
/>, | ||
); | ||
initialCourseState.course.skillNames.forEach((skill) => { | ||
expect(screen.queryByText(skill)).toBeVisible(); | ||
}); | ||
}); | ||
|
||
test('renders course skills greater than limit', () => { | ||
const skillGreaterThanLimit = ['test-skill1', 'test-skill2', 'test-skill3', 'test-skill4', 'test-skill5', 'test-skill6']; | ||
const courseState = { | ||
...initialCourseState, | ||
course: { | ||
...initialCourseState.course, | ||
skillNames: skillGreaterThanLimit, | ||
}, | ||
}; | ||
render( | ||
<CourseSkillsWithContext | ||
initialAppState={initialAppState} | ||
initialCourseState={courseState} | ||
/>, | ||
); | ||
|
||
const shownSkills = initialCourseState.course.skillNames.slice(0, MAX_VISIBLE_SKILLS); | ||
const hiddenSkills = initialCourseState.course.skillNames.slice(MAX_VISIBLE_SKILLS, skillGreaterThanLimit.length); | ||
|
||
shownSkills.forEach((skill) => { | ||
expect(screen.queryByText(skill)).toBeVisible(); | ||
}); | ||
|
||
// do not display skills greater than limit | ||
hiddenSkills.forEach((skill) => { | ||
expect(screen.queryByText(skill)).not.toBeVisible(); | ||
}); | ||
|
||
// display show more inline link when skills count is greater than limit | ||
expect(screen.queryByText(SKILLS_BUTTON_LABEL.SHOW_MORE)).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