From 8fac01bfa1a36989f621552fb2452a129b307d99 Mon Sep 17 00:00:00 2001 From: Bryan Jennings Date: Wed, 21 Sep 2022 03:18:31 -0700 Subject: [PATCH 1/2] Make DOJO exercises not nullable, fix React key bug --- graphql/index.tsx | 8 ++++---- graphql/typeDefs.ts | 2 +- pages/exercises/[lessonSlug].tsx | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/graphql/index.tsx b/graphql/index.tsx index b0ad6227e..6c1436690 100644 --- a/graphql/index.tsx +++ b/graphql/index.tsx @@ -315,7 +315,7 @@ export type Query = { __typename?: 'Query' alerts: Array allUsers?: Maybe>> - exercises: Array> + exercises: Array getLessonMentors?: Maybe>> getPreviousSubmissions?: Maybe> isTokenValid: Scalars['Boolean'] @@ -838,7 +838,7 @@ export type GetExercisesQuery = { name: string lesson: { __typename?: 'Lesson'; slug: string } } - } | null> + }> } export type GetFlaggedExercisesQueryVariables = Exact<{ [key: string]: never }> @@ -852,7 +852,7 @@ export type GetFlaggedExercisesQuery = { __typename?: 'Module' lesson: { __typename?: 'Lesson'; title: string } } - } | null> + }> } export type LessonMentorsQueryVariables = Exact<{ @@ -1780,7 +1780,7 @@ export type QueryResolvers< ContextType > exercises?: Resolver< - Array>, + Array, ParentType, ContextType > diff --git a/graphql/typeDefs.ts b/graphql/typeDefs.ts index 26a9dc5b6..c02fb5d3e 100644 --- a/graphql/typeDefs.ts +++ b/graphql/typeDefs.ts @@ -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! diff --git a/pages/exercises/[lessonSlug].tsx b/pages/exercises/[lessonSlug].tsx index 2f507fbf8..6992d03b0 100644 --- a/pages/exercises/[lessonSlug].tsx +++ b/pages/exercises/[lessonSlug].tsx @@ -54,10 +54,10 @@ const Exercises: React.FC> = ({ 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] @@ -66,6 +66,7 @@ const Exercises: React.FC> = ({ {exercise ? ( Date: Wed, 21 Sep 2022 03:37:52 -0700 Subject: [PATCH 2/2] Make DOJO exercises tests pass after fixing React key bug --- __dummy__/getExercisesData.ts | 2 +- __tests__/pages/exercises/[lessonSlug].test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/__dummy__/getExercisesData.ts b/__dummy__/getExercisesData.ts index 4133d18ed..5f9c24e9c 100644 --- a/__dummy__/getExercisesData.ts +++ b/__dummy__/getExercisesData.ts @@ -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 } ] } diff --git a/__tests__/pages/exercises/[lessonSlug].test.js b/__tests__/pages/exercises/[lessonSlug].test.js index e00e1a890..95aac4afd 100644 --- a/__tests__/pages/exercises/[lessonSlug].test.js +++ b/__tests__/pages/exercises/[lessonSlug].test.js @@ -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()