Skip to content

Commit 90ebe9e

Browse files
committed
fix: gate guide lesson advance on checkpoints
1 parent 93a6a99 commit 90ebe9e

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

apps/guide/__tests__/GuideHome_.test.res

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open Vitest
22

33
let firstLesson = GuideTestFixtures.firstLesson
44
let secondLesson = GuideTestFixtures.secondLesson
5+
let guideLessonsWithFinal = GuideTestFixtures.guideLessonsWithFinal
56
let renderGuideHome = GuideTestFixtures.renderGuideHome
67
let renderGuideHomeWithDocsIntroNavigation = GuideTestFixtures.renderGuideHomeWithDocsIntroNavigation
78
let renderGuideHomeInBrowser = GuideTestFixtures.renderGuideHomeInBrowser
@@ -124,6 +125,24 @@ test("enables Done on a completed final lesson", async () => {
124125
GuideLayout.clearExerciseCode(secondLesson.exercise.id)
125126
})
126127

128+
test("keeps Next disabled until the current checkpoint is complete", async () => {
129+
await viewport(1440, 900)
130+
GuideLayout.clearCompletedExercises()
131+
GuideLayout.clearExerciseCode(secondLesson.exercise.id)
132+
133+
let screen = await render(
134+
<ReactRouter.MemoryRouter initialEntries=["/#functions"]>
135+
<GuideHome lessons=guideLessonsWithFinal />
136+
</ReactRouter.MemoryRouter>,
137+
)
138+
let nextButton = await screen->getByText("Next")
139+
140+
await nextButton->element->toBeDisabled
141+
142+
GuideLayout.clearCompletedExercises()
143+
GuideLayout.clearExerciseCode(secondLesson.exercise.id)
144+
})
145+
127146
test("Done on a completed final lesson opens the ReScript docs intro", async () => {
128147
await viewport(1440, 900)
129148
GuideLayout.clearCompletedExercises()

apps/guide/__tests__/GuideTestFixtures.res

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,24 @@ let greeting = greet("ReScript")`,
3838
},
3939
}
4040

41+
let finalLesson: GuideLesson.t = {
42+
id: "final-check",
43+
position: 3,
44+
sourcePath: "app/lessons/03-final-check.mdx",
45+
missionLabel: "Mission 03",
46+
title: "Final Check",
47+
description: "Finish the guide.",
48+
content: `Complete the final checkpoint.`,
49+
exercise: {
50+
id: "final-check/done",
51+
title: "Finish",
52+
initialCode: `let done = true`,
53+
check: ExpectedOutput("true"),
54+
},
55+
}
56+
4157
let guideLessons = [firstLesson, secondLesson]
58+
let guideLessonsWithFinal = [firstLesson, secondLesson, finalLesson]
4259

4360
let renderGuideHome = (~initialEntries=["/"], ()) =>
4461
render(

apps/guide/app/GuideLessonNavigationHook.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let useLessonNavigation = (~lessons, ~goToDocsIntro): t => {
5858
let hasNextLesson = GuideLesson.hasNextLesson(~lessons, lessonIndex)
5959
let exercisePassed = GuideLesson.isExerciseComplete(~exercise, ~output)
6060
let checkpointComplete = exercisePassed || GuideLayout.isExerciseCompleted(exercise.id)
61-
let forwardActionEnabled = hasNextLesson || checkpointComplete
61+
let forwardActionEnabled = checkpointComplete
6262

6363
React.useEffect(() => {
6464
if exercisePassed {
@@ -75,7 +75,7 @@ let useLessonNavigation = (~lessons, ~goToDocsIntro): t => {
7575
}
7676

7777
let goToNextLesson = _event => {
78-
if hasNextLesson {
78+
if hasNextLesson && checkpointComplete {
7979
let nextLessonIndex = lessonIndex + 1
8080
navigateToLesson(~goToHash, ~setLessonIndex, ~setOutput, ~lessons, nextLessonIndex)
8181
} else if checkpointComplete {

0 commit comments

Comments
 (0)