70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?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));
|
|
}
|
|
});
|