AdminStudentIndex Tests
This commit is contained in:
parent
75ce5043c2
commit
2ae6ecd8ca
|
|
@ -6,7 +6,7 @@
|
|||
<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: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>
|
||||
|
||||
<thead>
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
<x-table.body>
|
||||
@foreach($students as $student)
|
||||
<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->grade }}</x-table.td>
|
||||
<x-table.td>{{ $student->entries->count() }}</x-table.td>
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
});
|
||||
|
|
@ -10,13 +10,13 @@ use function Pest\Laravel\get;
|
|||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->adminUser = User::factory()->admin()->create();
|
||||
$this->adminUser = User::factory()->admin()->create();
|
||||
$this->nonAdminUser = User::factory()->create();
|
||||
$this->tabUser = User::factory()->tab()->create();
|
||||
$this->users = User::factory(3)->create();
|
||||
$this->schools = [];
|
||||
$this->tabUser = User::factory()->tab()->create();
|
||||
$this->users = User::factory(3)->create();
|
||||
$this->schools = [];
|
||||
foreach ($this->users as $user) {
|
||||
$school = School::factory()->create();
|
||||
$school = School::factory()->create();
|
||||
$user->school_id = $school->id;
|
||||
$user->save();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue