-
Notifications
You must be signed in to change notification settings - Fork 69
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
Make DOJO exercises not nullable and fix React key bug #2336
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,10 +64,11 @@ describe('Exercises page', () => { | |
// Previous button is not in the document on the first exercise. | ||
expect(queryByRole('button', { name: 'PREVIOUS' })).not.toBeInTheDocument() | ||
|
||
const skipButton = getByRole('button', { name: 'SKIP' }) | ||
let skipButton = getByRole('button', { name: 'SKIP' }) | ||
fireEvent.click(skipButton) | ||
expect(queryByRole('button', { name: 'PREVIOUS' })).toBeInTheDocument() | ||
|
||
skipButton = getByRole('button', { name: 'SKIP' }) | ||
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. The reason why we need to reassign |
||
fireEvent.click(skipButton) | ||
// Skip button should not be in the document because we're on the last exercise now. | ||
expect(queryByRole('button', { name: 'SKIP' })).not.toBeInTheDocument() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,10 +54,10 @@ const Exercises: React.FC<QueryDataProps<GetExercisesQuery>> = ({ | |
const currentExercises = exercises | ||
.filter(exercise => exercise?.module.lesson.slug === slug) | ||
.map(exercise => ({ | ||
challengeName: exercise?.module.name!, | ||
problem: exercise?.description!, | ||
answer: exercise?.answer!, | ||
explanation: exercise?.explanation! | ||
challengeName: exercise.module.name, | ||
problem: exercise.description, | ||
answer: exercise.answer, | ||
explanation: exercise.explanation || '' | ||
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. Exercise explanations are nullable so we have to handle it here by defauting to an empty string, which works fine and looks good (see pull request description for a picture of what it looks like). |
||
})) | ||
|
||
const exercise = currentExercises[exerciseIndex] | ||
|
@@ -66,6 +66,7 @@ const Exercises: React.FC<QueryDataProps<GetExercisesQuery>> = ({ | |
<Layout title={currentLesson.title}> | ||
{exercise ? ( | ||
<Exercise | ||
key={exerciseIndex} | ||
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. This line fixes a small React key bug which previously would make it possible to press "Show Answer" (to show the current exercise answer) then "Skip" (to skip to the next exercise) which caused the next exercise's answer to be shown. |
||
exercise={exercise} | ||
setExerciseIndex={setExerciseIndex} | ||
lessonTitle={currentLesson.title} | ||
|
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.
Adding a null exercise explanation to the mock exercise data so we can get full test coverage.