admin entry pages tests done
This commit is contained in:
parent
8d9bbf31d5
commit
e3f102d6bd
|
|
@ -76,11 +76,12 @@ class EntryController extends Controller
|
||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) {
|
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
$auditions = Audition::orderBy('score_order')->get();
|
$auditionsRaw = Audition::with('flags')->orderBy('score_order')->get();
|
||||||
|
|
||||||
|
$auditions = $auditionsRaw->reject(function ($audition) {
|
||||||
|
return $audition->hasFlag('seats_published') || $audition->hasFlag('advancement_published');
|
||||||
|
});
|
||||||
|
|
||||||
return view('admin.entries.create', ['students' => $students, 'auditions' => $auditions]);
|
return view('admin.entries.create', ['students' => $students, 'auditions' => $auditions]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ class AuditionFactory extends Factory
|
||||||
'maximum_grade' => $this->faker->numberBetween(8, 12),
|
'maximum_grade' => $this->faker->numberBetween(8, 12),
|
||||||
'for_seating' => 1,
|
'for_seating' => 1,
|
||||||
'for_advancement' => 1,
|
'for_advancement' => 1,
|
||||||
|
'room_id' => null,
|
||||||
|
'order_in_room' => 0,
|
||||||
|
'scoring_guide_id' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class EntryFactory extends Factory
|
||||||
'draw_number' => null,
|
'draw_number' => null,
|
||||||
'for_seating' => 1,
|
'for_seating' => 1,
|
||||||
'for_advancement' => 1,
|
'for_advancement' => 1,
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-card.card class="mx-auto max-w-2xl">
|
<x-card.card class="mx-auto max-w-2xl">
|
||||||
<x-card.heading>Create Entry</x-card.heading>
|
<x-card.heading>Create Entry</x-card.heading>
|
||||||
<x-form.form method="POST" action="/admin/entries">
|
<x-form.form id='createEntryForm' method="POST" action="/admin/entries">
|
||||||
<x-form.body-grid columns="3" x-data="studentAuditionFilter()">
|
<x-form.body-grid columns="3" x-data="studentAuditionFilter()">
|
||||||
|
|
||||||
<x-form.select name="student_id" colspan="2" x-model="selectedStudentId" @change="filterAuditions">
|
<x-form.select name="student_id" colspan="2" x-model="selectedStudentId" @change="filterAuditions">
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
<input type="hidden" name="for_seating" value="on">
|
<input type="hidden" name="for_seating" value="on">
|
||||||
@endif
|
@endif
|
||||||
</x-form.body-grid>
|
</x-form.body-grid>
|
||||||
<x-form.footer>
|
<x-form.footer class="mb-5">
|
||||||
<x-form.button>Create Entry</x-form.button>
|
<x-form.button>Create Entry</x-form.button>
|
||||||
</x-form.footer>
|
</x-form.footer>
|
||||||
</x-form.form>
|
</x-form.form>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\Student;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
use function Pest\Laravel\get;
|
||||||
|
use function PHPUnit\Framework\assertEquals;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('does not respond to an ordinary user', function () {
|
||||||
|
actAsNormal();
|
||||||
|
get(route('admin.entries.create'))
|
||||||
|
->assertRedirect(route('dashboard'));
|
||||||
|
});
|
||||||
|
it('does not respond to a guest', function () {
|
||||||
|
// Act & Assert
|
||||||
|
get(route('admin.entries.create'))
|
||||||
|
->assertRedirect(route('home'));
|
||||||
|
});
|
||||||
|
it('passes a collection of all students with thier schools to the view', function () {
|
||||||
|
// Arrange
|
||||||
|
Student::factory()->count(8)->create();
|
||||||
|
$students = Student::with('school')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
|
actAsAdmin();
|
||||||
|
// Act & Assert
|
||||||
|
get(route('admin.entries.create'))
|
||||||
|
->assertViewHas('students', $students);
|
||||||
|
});
|
||||||
|
it('passes a collection of available auditions to the view', function () {
|
||||||
|
// Arrange
|
||||||
|
for ($i = 3; $i < 9; $i++) {
|
||||||
|
Audition::factory()->create(['score_order' => $i]);
|
||||||
|
}
|
||||||
|
Audition::factory()->count(5)->create();
|
||||||
|
$auditions = Audition::with('flags')->orderBy('score_order')->get();
|
||||||
|
$auditions = $auditions->toArray();
|
||||||
|
$seatedAudition = Audition::factory()->create(['score_order' => 1]);
|
||||||
|
$seatedAudition->addFlag('seats_published');
|
||||||
|
$advancedAudition = Audition::factory()->create(['score_order' => 2]);
|
||||||
|
$advancedAudition->addFlag('advancement_published');
|
||||||
|
actAsAdmin();
|
||||||
|
// Act & Assert
|
||||||
|
$response = get(route('admin.entries.create'));
|
||||||
|
$viewAuditions = $response->viewData('auditions')->toArray();
|
||||||
|
$response->assertOk();
|
||||||
|
assertEquals(array_values($auditions), array_values($viewAuditions));
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue