From 71b4c245f977c4c9e12e7cfd2d30c2a71b15b44c Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 2 Jul 2024 15:44:43 -0500 Subject: [PATCH] AdminSchoolsIndex test --- resources/views/admin/schools/index.blade.php | 4 +- .../Feature/Pages/Admin/SchoolsIndexTest.php | 112 ++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Pages/Admin/SchoolsIndexTest.php diff --git a/resources/views/admin/schools/index.blade.php b/resources/views/admin/schools/index.blade.php index 9ffc01e..e025c45 100644 --- a/resources/views/admin/schools/index.blade.php +++ b/resources/views/admin/schools/index.blade.php @@ -22,9 +22,9 @@ @foreach($schools as $school) - {{ $school->name }} + {{ $school->name }} - + ${{ number_format($schoolTotalFees[$school->id],2) }} diff --git a/tests/Feature/Pages/Admin/SchoolsIndexTest.php b/tests/Feature/Pages/Admin/SchoolsIndexTest.php new file mode 100644 index 0000000..9e455b3 --- /dev/null +++ b/tests/Feature/Pages/Admin/SchoolsIndexTest.php @@ -0,0 +1,112 @@ +adminUser = User::factory()->admin()->create(); + $this->nonAdminUser = User::factory()->create(); + $this->tabUser = User::factory()->tab()->create(); + $this->schools = School::factory()->count(5)->create(); + $n = 10; + $this->students = []; + foreach ($this->schools as $school) { + $newStus = Student::factory()->count($n)->create(['school_id' => $school->id]); + foreach ($newStus as $student) { + $this->students[] = $student; + } + $n = $n + 3; + } + $n = 0; + foreach ($this->students as $student) { + Entry::factory()->create(['student_id' => $student->id]); + $n++; + if ($n === 10) { + Entry::factory()->create(['student_id' => $student->id]); + $n = 0; + } + } + +}); + +it('only shows for an admin user', function () { + // Act & Assert + $checkRoute = 'admin.schools.index'; + get(route($checkRoute))->assertRedirect(route('home')); + actingAs($this->adminUser); + get(route($checkRoute))->assertOk(); + actingAs($this->nonAdminUser); + get(route($checkRoute))->assertRedirect(route('dashboard')); +}); +it('has a new school link', function () { + // Arrange + actingAs($this->adminUser); + // Act & Assert + get(route('admin.schools.index')) + ->assertOk() + ->assertSeeInOrder([ + 'href=', + route('admin.schools.create'), + 'New School', + '/a', + ]); +}); +it('shows school data', function () { + // Arrange + $invoiceDataService = new App\Services\Invoice\InvoiceOneFeePerEntry(new App\Services\EntryService(new App\Services\AuditionService())); + Settings::set('school_fees', 1000); + Settings::set('late_fee', 2500); + actingAs($this->adminUser); + $this->schools->loadCount(['users', 'students', 'entries']); + // Act & Assert + $response = get(route('admin.schools.index')); + $response->assertOk(); + foreach ($this->schools as $school) { + $response->assertSeeInOrder([ + 'td', + $school->name, + '/td', + 'td', + $invoiceDataService->getGrandTotal($school->id), + '/td', + 'td', + $school->users_count, + '/td', + 'td', + $school->students_count, + '/td', + 'td', + $school->entries_count, + '/td', + ], false); + } +}); +it('has an edit link for each school', function () { + // Arrange + actingAs($this->adminUser); + // Act & Assert + $response = get(route('admin.schools.index')); + $response->assertOk(); + foreach ($this->schools as $school) { + $response->assertSee(route('admin.schools.edit', $school)); + } +}); +it('has an invoice link for each school', function () { + // Arrange + actingAs($this->adminUser); + // Act & Assert + $response = get(route('admin.schools.index')); + $response->assertOk(); + foreach ($this->schools as $school) { + $response->assertSee(route('admin.schools.invoice', $school)); + } +});