Skip to content

Commit

Permalink
Merge pull request #2391 from bryanjenningz/finished-exercises-message
Browse files Browse the repository at this point in the history
Finished exercises message
  • Loading branch information
bryanjenningz authored Oct 3, 2022
2 parents 961e306 + 3447dcb commit 4281a5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
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

1 comment on commit 4281a5c

@vercel
Copy link

@vercel vercel bot commented on 4281a5c Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.