diff --git a/resources/views/livewire/customer/course.blade.php b/resources/views/livewire/customer/course.blade.php index 55f2e7689..304440490 100644 --- a/resources/views/livewire/customer/course.blade.php +++ b/resources/views/livewire/customer/course.blade.php @@ -80,8 +80,7 @@ class="h-2 rounded-full bg-emerald-500 transition-all" @if ($isDraft) Coming Soon - @endif - @if ($lesson->duration_in_seconds) + @elseif ($lesson->duration_in_seconds) {{ gmdate('i:s', $lesson->duration_in_seconds) }} @endif @@ -299,8 +298,7 @@ class="cursor-help text-zinc-400 dark:text-zinc-500" @if ($isUnreleased) Coming Soon - @endif - @if ($lesson->duration_in_seconds) + @elseif ($lesson->duration_in_seconds) {{ gmdate('i:s', $lesson->duration_in_seconds) }} @endif diff --git a/resources/views/livewire/customer/course/lesson-show.blade.php b/resources/views/livewire/customer/course/lesson-show.blade.php index 3fc949a97..26c5b4f56 100644 --- a/resources/views/livewire/customer/course/lesson-show.blade.php +++ b/resources/views/livewire/customer/course/lesson-show.blade.php @@ -116,8 +116,7 @@ class="flex items-center gap-3 px-4 py-2 text-sm transition-colors {{ $isCurrent {{ $outlineLesson->title }} @if ($isDraft) Coming Soon - @endif - @if ($outlineLesson->duration_in_seconds) + @elseif ($outlineLesson->duration_in_seconds) {{ gmdate('i:s', $outlineLesson->duration_in_seconds) }} @endif diff --git a/tests/Feature/CourseContentTest.php b/tests/Feature/CourseContentTest.php index 62b5be455..2ae07e1c9 100644 --- a/tests/Feature/CourseContentTest.php +++ b/tests/Feature/CourseContentTest.php @@ -377,7 +377,70 @@ public function unreleased_lessons_are_not_shown_as_locked(): void } /** - * The markup for a single lesson row in the pre-purchase outline. + * An unreleased lesson may already have a duration set, but it shouldn't be + * shown until the lesson is out — the Coming Soon badge takes its place. + */ + #[Test] + public function owners_do_not_see_the_duration_of_unreleased_lessons(): void + { + $user = User::factory()->create(); + $product = Product::where('slug', 'nativephp-masterclass')->first(); + ProductLicense::factory()->create([ + 'user_id' => $user->id, + 'product_id' => $product->id, + ]); + + $course = Course::factory()->published()->create(); + $module = CourseModule::factory()->published()->create(['course_id' => $course->id]); + CourseLesson::factory()->published()->create([ + 'course_module_id' => $module->id, + 'title' => 'Released Lesson', + 'duration_in_seconds' => 125, + 'sort_order' => 1, + ]); + CourseLesson::factory()->create([ + 'course_module_id' => $module->id, + 'title' => 'Unreleased Lesson', + 'duration_in_seconds' => 278, + 'sort_order' => 2, + ]); + + Livewire::actingAs($user) + ->test(Index::class) + ->assertSeeInOrder(['Released Lesson', '02:05']) + ->assertSeeInOrder(['Unreleased Lesson', 'Coming Soon']) + ->assertDontSee('04:38'); + } + + #[Test] + public function the_curriculum_outline_does_not_show_the_duration_of_unreleased_lessons(): void + { + $user = User::factory()->create(); + + $course = Course::factory()->published()->create(); + $module = CourseModule::factory()->published()->create(['course_id' => $course->id]); + $released = CourseLesson::factory()->published()->create([ + 'course_module_id' => $module->id, + 'duration_in_seconds' => 125, + 'sort_order' => 1, + ]); + $unreleased = CourseLesson::factory()->create([ + 'course_module_id' => $module->id, + 'duration_in_seconds' => 278, + 'sort_order' => 2, + ]); + + $html = Livewire::actingAs($user)->test(Index::class)->html(); + + $unreleasedRow = $this->outlineRowFor($html, $unreleased->id); + + $this->assertStringContainsString('02:05', $this->outlineRowFor($html, $released->id)); + $this->assertStringContainsString('Coming Soon', $unreleasedRow); + $this->assertStringNotContainsString('04:38', $unreleasedRow); + } + + /** + * The markup for a single lesson row in a course outline. */ private function outlineRowFor(string $html, int $lessonId): string { @@ -1095,6 +1158,36 @@ public function draft_lessons_are_clickable_in_the_outline_for_admins(): void ->assertSee(route('customer.course.lesson', $draftLesson), false); } + #[Test] + public function the_lesson_sidebar_does_not_show_the_duration_of_draft_lessons_to_admins(): void + { + config(['filament.users' => ['admin@test.com']]); + $admin = User::factory()->create(['email' => 'admin@test.com']); + + $course = Course::factory()->published()->create(); + $module = CourseModule::factory()->published()->create(['course_id' => $course->id]); + $currentLesson = CourseLesson::factory()->published()->create([ + 'course_module_id' => $module->id, + 'duration_in_seconds' => 125, + 'sort_order' => 1, + ]); + $draftLesson = CourseLesson::factory()->create([ + 'course_module_id' => $module->id, + 'duration_in_seconds' => 278, + 'sort_order' => 2, + ]); + + $html = Livewire::actingAs($admin) + ->test(LessonShow::class, ['lesson' => $currentLesson]) + ->html(); + + $draftRow = $this->outlineRowFor($html, $draftLesson->id); + + $this->assertStringContainsString('02:05', $this->outlineRowFor($html, $currentLesson->id)); + $this->assertStringContainsString('Coming Soon', $draftRow); + $this->assertStringNotContainsString('04:38', $draftRow); + } + #[Test] public function draft_video_lessons_do_not_hide_the_coming_soon_banner_for_non_admins(): void {