From a53c9b0a6786e819ffb9d3f2f9d499549489fa41 Mon Sep 17 00:00:00 2001 From: kusaljayawardhana Date: Mon, 21 Oct 2024 17:33:39 +0530 Subject: [PATCH] Update for Course tests --- tests/Feature/Backend/Courses/CourseTest.php | 110 ++++++++++++++----- 1 file changed, 82 insertions(+), 28 deletions(-) diff --git a/tests/Feature/Backend/Courses/CourseTest.php b/tests/Feature/Backend/Courses/CourseTest.php index 414c019..bef773e 100644 --- a/tests/Feature/Backend/Courses/CourseTest.php +++ b/tests/Feature/Backend/Courses/CourseTest.php @@ -32,60 +32,114 @@ public function a_course_manager_can_access_the_create_course_page() /** @test */ public function a_course_can_be_created_via_livewire() { - $this->loginAsCourseManager(); - - $semester = Semester::factory()->create(); - - Livewire::test(\App\Http\Livewire\Backend\CreateCourses::class) - ->set('academicProgram', 'undergraduate') - ->set('semester', (string) $semester->id) - ->set('version', '1') - ->set('type', 'Core') - ->set('code', 'CS101') - ->set('name', 'Introduction to Computer Science') - ->set('credits', 3) - ->set('content', 'Basic concepts of computer science.') - ->set('objectives', 'Learn the basics of computer science') - ->set('time_allocation', ['lecture' => 3, 'tutorial' => 1, 'practical' => 1]) - ->set('marks_allocation', ['practicals' => 20, 'mid_exam' => 30, 'end_exam' => 50]) - ->set('ilos', ['knowledge' => ['Understand basic algorithms'], 'skills' => ['Implement basic programs']]) - ->set('references', ['Introduction to Algorithms']) - ->call('submit') - ->assertHasNoErrors(); + $this->loginAsCourseManager(); + + $semester = Semester::factory()->create([ + 'academic_program' => 'undergraduate', + 'version' => '1', + ]); + + Livewire::test(\App\Http\Livewire\Backend\CreateCourses::class) + + ->set('academicProgram', 'undergraduate') + ->set('version', '1') + ->set('semester', (string) $semester->id) + ->set('type', 'Core') + ->set('code', 'CL101') + ->set('name', 'Introduction to Computer Science') + ->set('credits', 3) + ->set('content', 'Basic concepts of computer science.') + ->set('teaching_methods', 'Lecture and practical') + ->set('time_allocation', ['lecture' => 3, 'tutorial' => 1, 'practical' => 1]) + ->set('marks_allocation', ['practicals' => 20, 'mid_exam' => 30, 'end_exam' => 50]) + ->call('next') + ->assertHasNoErrors() + + ->set('objectives', 'Learn the basics of computer science') + ->set('ilos', [ + 'knowledge' => ['Understand basic algorithms'], + 'skills' => ['Implement basic programs'] + ]) + ->call('next') + ->assertHasNoErrors() + + ->set('references', ['Introduction to Algorithms']) + ->set('modules', [ + [ + 'name' => 'Module 1', + 'description' => 'Introduction to programming', + 'time_allocation' => ['lectures' => 2, 'tutorials' => 1, 'practicals' => 1] + ] + ]) + ->call('submit') + ->assertHasNoErrors(); $this->assertDatabaseHas('courses', [ - 'code' => 'CS101', + 'code' => 'CL101', 'name' => 'Introduction to Computer Science', + 'credits' => 3, + 'type' => 'Core', ]); } + /** @test */ public function a_course_can_be_updated_via_livewire() { $this->loginAsCourseManager(); - $course = Course::factory()->create(); - Livewire::test(\App\Http\Livewire\Backend\EditCourses::class) - ->set('course', $course) + $course = Course::factory()->create([ + 'academic_program' => 'undergraduate', + 'version' => '1', + 'type' => 'Core', + ]); + + $semester = Semester::factory()->create([ + 'academic_program' => 'undergraduate', + 'version' => '1', + ]); + + Livewire::test(\App\Http\Livewire\Backend\EditCourses::class, ['course' => $course]) ->set('academicProgram', $course->academic_program) - ->set('semester', (string) $course->semester_id) ->set('version', (string) $course->version) + ->set('semester', (string) $semester->id) ->set('type', $course->type) ->set('code', 'CS102') ->set('name', 'Advanced Computer Science') ->set('credits', 3) ->set('content', 'Advanced topics in computer science.') - ->set('objectives', 'Learn advanced topics') + ->set('teaching_methods', 'Lecture and practical') ->set('time_allocation', ['lecture' => 3, 'tutorial' => 1, 'practical' => 2]) ->set('marks_allocation', ['practicals' => 30, 'mid_exam' => 20, 'end_exam' => 50]) - ->set('ilos', ['knowledge' => ['Understand advanced algorithms']]) + ->call('next') + ->assertHasNoErrors() + + ->set('objectives', 'Learn advanced topics') + ->set('ilos', [ + 'knowledge' => ['Understand advanced algorithms'], + 'skills' => ['Implement advanced programs'] + ]) + ->call('next') + ->assertHasNoErrors() + ->set('references', ['Advanced Algorithms']) - ->call('submit') + ->set('modules', [ + [ + 'name' => 'Module 1', + 'description' => 'Advanced programming concepts', + 'time_allocation' => ['lectures' => 2, 'tutorials' => 1, 'practicals' => 2] + ] + ]) + ->call('update') ->assertHasNoErrors(); $this->assertDatabaseHas('courses', [ + 'id' => $course->id, 'code' => 'CS102', 'name' => 'Advanced Computer Science', + 'credits' => 3, + 'type' => 'Core', + 'content' => 'Advanced topics in computer science.', ]); }