AdminStudentIndex Tests

This commit is contained in:
Matt Young 2024-07-03 02:03:33 -05:00
parent 75ce5043c2
commit 2ae6ecd8ca
3 changed files with 76 additions and 7 deletions

View File

@ -6,7 +6,7 @@
<x-slot:title class="ml-3">Students</x-slot:title> <x-slot:title class="ml-3">Students</x-slot:title>
<x-slot:subtitle class="ml-3">Click name to edit</x-slot:subtitle> <x-slot:subtitle class="ml-3">Click name to edit</x-slot:subtitle>
<x-slot:title_block_right class="mr-3"> <x-slot:title_block_right class="mr-3">
<x-form.button href="/admin/students/create">New Student</x-form.button> <x-form.button href="{{ route('admin.students.create') }}">New Student</x-form.button>
</x-slot:title_block_right> </x-slot:title_block_right>
<thead> <thead>
@ -20,7 +20,7 @@
<x-table.body> <x-table.body>
@foreach($students as $student) @foreach($students as $student)
<tr> <tr>
<x-table.td><a href="/admin/students/{{ $student->id }}/edit">{{ $student->full_name(true) }}</a></x-table.td> <x-table.td><a href="{{ route('admin.students.edit',$student) }}">{{ $student->full_name(true) }}</a></x-table.td>
<x-table.td>{{ $student->school->name }}</x-table.td> <x-table.td>{{ $student->school->name }}</x-table.td>
<x-table.td>{{ $student->grade }}</x-table.td> <x-table.td>{{ $student->grade }}</x-table.td>
<x-table.td>{{ $student->entries->count() }}</x-table.td> <x-table.td>{{ $student->entries->count() }}</x-table.td>

View File

@ -0,0 +1,69 @@
<?php
use App\Models\Student;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->adminUser = User::factory()->admin()->create();
$this->normalUser = User::factory()->create();
$this->students = Student::factory()->count(5)->create();
});
it('is available to admin users', function () {
$user = User::factory()->admin()->create();
$response = $this->actingAs($user)->get(route('admin.students.index'));
$response->assertOk();
});
it('is not available to normal users', function () {
$response = $this->actingAs($this->normalUser)->get(route('admin.students.index'));
$response->assertRedirect(route('dashboard'));
});
it('has a new student button', function () {
$response = $this->actingAs($this->adminUser)->get(route('admin.students.index'));
$response
->assertSee('New Student')
->assertSeeInOrder([
'a href=',
route('admin.students.create'),
'New Student',
'/a',
], false);
});
it('shows info for each student', function () {
// Arrange
$response = $this->actingAs($this->adminUser)->get(route('admin.students.index'));
// Act & Assert
$response->assertOk();
foreach ($this->students as $student) {
$response->assertSeeInOrder([
'td',
$student->full_name(true),
'/td',
'td',
$student->school->name,
'/td',
'td',
$student->grade,
'/td',
'td',
$student->entries->count(),
'/td',
]);
}
});
it('shows a link to edit each student', function () {
// Arrange
$response = $this->actingAs($this->adminUser)->get(route('admin.students.index'));
// Act & Assert
foreach ($this->students as $student) {
$response->assertSee(route('admin.students.edit', $student));
}
});