Skip to content

Commit

Permalink
Merge pull request #2336 from bryanjenningz/make-dojo-exercises-not-n…
Browse files Browse the repository at this point in the history
…ullable

Make DOJO exercises not nullable and fix React key bug
  • Loading branch information
bryanjenningz authored Sep 21, 2022
2 parents 27b9d46 + 3a6f6a6 commit c066f24
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion __dummy__/getExercisesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const getExercisesData: GetExercisesQuery = {
},
description: '```\nlet a = 1\na -= 2\n// what is a?\n```',
answer: '-1',
explanation: '`a -= 2` is a shorter way to write `a = a - 2`'
explanation: null
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion __tests__/pages/exercises/[lessonSlug].test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
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()
Expand Down
8 changes: 4 additions & 4 deletions graphql/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export type Query = {
__typename?: 'Query'
alerts: Array<Alert>
allUsers?: Maybe<Array<Maybe<User>>>
exercises: Array<Maybe<Exercise>>
exercises: Array<Exercise>
getLessonMentors?: Maybe<Array<Maybe<User>>>
getPreviousSubmissions?: Maybe<Array<Submission>>
isTokenValid: Scalars['Boolean']
Expand Down Expand Up @@ -838,7 +838,7 @@ export type GetExercisesQuery = {
name: string
lesson: { __typename?: 'Lesson'; slug: string }
}
} | null>
}>
}

export type GetFlaggedExercisesQueryVariables = Exact<{ [key: string]: never }>
Expand All @@ -852,7 +852,7 @@ export type GetFlaggedExercisesQuery = {
__typename?: 'Module'
lesson: { __typename?: 'Lesson'; title: string }
}
} | null>
}>
}

export type LessonMentorsQueryVariables = Exact<{
Expand Down Expand Up @@ -1780,7 +1780,7 @@ export type QueryResolvers<
ContextType
>
exercises?: Resolver<
Array<Maybe<ResolversTypes['Exercise']>>,
Array<ResolversTypes['Exercise']>,
ParentType,
ContextType
>
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default gql`
session: Session!
allUsers: [User]
modules: [Module]!
exercises: [Exercise]!
exercises: [Exercise!]!
getLessonMentors(lessonId: Int!): [User]
userInfo(username: String!): Session
isTokenValid(cliToken: String!): Boolean!
Expand Down
9 changes: 5 additions & 4 deletions pages/exercises/[lessonSlug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
}))

const exercise = currentExercises[exerciseIndex]
Expand All @@ -66,6 +66,7 @@ const Exercises: React.FC<QueryDataProps<GetExercisesQuery>> = ({
<Layout title={currentLesson.title}>
{exercise ? (
<Exercise
key={exerciseIndex}
exercise={exercise}
setExerciseIndex={setExerciseIndex}
lessonTitle={currentLesson.title}
Expand Down

1 comment on commit c066f24

@vercel
Copy link

@vercel vercel bot commented on c066f24 Sep 21, 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.