Skip to content
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

Finished exercises message #2391

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/pages/exercises/[lessonSlug].test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ describe('Exercises page', () => {
expect(incorrectExercisePreviews).toHaveLength(1)
})

test('Renders a finished all exercises message when the user finished all the exercises', async () => {
const mocks = [
{
request: { query: GET_EXERCISES },
result: {
data: {
...getExercisesData,
// Make it so the user answered all of the exercises correctly
exerciseSubmissions: getExercisesData.exercises.map(exercise => ({
exerciseId: exercise.id,
userAnswer: exercise.answer
}))
}
}
}
]

const { findByLabelText, findAllByText, findByText } = render(
<MockedProvider mocks={mocks} addTypename={false}>
<Exercises />
</MockedProvider>
)

const exercisePreviews = await findAllByText('Problem')
expect(exercisePreviews).toHaveLength(3)

const checkbox = await findByLabelText('Show incomplete exercises only')
fireEvent.click(checkbox)

await findByText(
'🎉 Congratulations! You finished all the exercises for this lesson! 🥳'
)
})

test('Should not render lessons nav card tab if lesson docUrl is null', async () => {
const mocks = [
{
Expand Down
30 changes: 18 additions & 12 deletions pages/exercises/[lessonSlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,24 @@ const ExerciseList = ({
</div>
)}
</div>
<div className={styles.exerciseList__container}>
{exercises.map((exercise, i) => (
<ExercisePreviewCard
key={i}
moduleName={exercise.moduleName}
state={exercise.state}
problem={exercise.problem}
/>
))}
<div />
<div />
</div>
{exercises.length > 0 ? (
<div className={styles.exerciseList__container}>
{exercises.map((exercise, i) => (
<ExercisePreviewCard
key={i}
moduleName={exercise.moduleName}
state={exercise.state}
problem={exercise.problem}
/>
))}
<div />
<div />
</div>
) : (
<p className="fs-5 text-center">
🎉 Congratulations! You finished all the exercises for this lesson! 🥳
</p>
)}
</>
)
}
Expand Down