Write tests - Write tests for what was done to this point that will be kept #11
|
|
@ -24,9 +24,6 @@ class RoomController extends Controller
|
||||||
|
|
||||||
public function judgingAssignment() // Show form for assigning judges
|
public function judgingAssignment() // Show form for assigning judges
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) {
|
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
$usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
$usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
$usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
$usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get();
|
||||||
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
$rooms = Room::with(['judges.school', 'auditions'])->get();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
@if($room->id == 0)
|
@if($room->id == 0)
|
||||||
@continue
|
@continue
|
||||||
@endif
|
@endif
|
||||||
<li class=" rounded-xl border border-gray-200 bg-gray-50 "> {{-- card wrapper --}}
|
<li id="room-{{$room->id}}-card" class=" rounded-xl border border-gray-200 bg-gray-50 "> {{-- card wrapper --}}
|
||||||
<div class="flex items-center gap-x-4 border-b border-gray-900/5 bg-white pt-2 pb-6 px-6"> {{-- card header --}}
|
<div class="flex items-center gap-x-4 border-b border-gray-900/5 bg-white pt-2 pb-6 px-6"> {{-- card header --}}
|
||||||
<div class="text-sm font-medium leading-6 text-gray-900">
|
<div class="text-sm font-medium leading-6 text-gray-900">
|
||||||
<p class="text-sm font-medium leading-6 text-gray-900">{{ $room->name }}</p>
|
<p class="text-sm font-medium leading-6 text-gray-900">{{ $room->name }}</p>
|
||||||
|
|
@ -60,8 +60,8 @@
|
||||||
<div class="flex justify-between items-center gap-x-4 py-1"> {{-- Judge Line --}}
|
<div class="flex justify-between items-center gap-x-4 py-1"> {{-- Judge Line --}}
|
||||||
<dt>
|
<dt>
|
||||||
<p>
|
<p>
|
||||||
<span class="text-gray-700">{{ $judge->full_name() }}, </span>
|
<span class="text-gray-700">{{ $judge->full_name() }} </span>
|
||||||
<span class="text-gray-500 text-xs">{{ $judge->school->name }}</span>
|
<span class="text-gray-500 text-xs">{{ $judge->school->name ?? '' }}</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-500 text-xs">{{ $judge->judging_preference }}</p>
|
<p class="text-gray-500 text-xs">{{ $judge->judging_preference }}</p>
|
||||||
</dt>
|
</dt>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Sinnbeck\DomAssertions\Asserts\AssertElement;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('only allows admin users to manage judging assignments', function () {
|
||||||
|
$this->get(route('admin.rooms.judgingAssignment'))
|
||||||
|
->assertRedirect(route('home'));
|
||||||
|
actAsNormal();
|
||||||
|
$this->get(route('admin.rooms.judgingAssignment'))
|
||||||
|
->assertRedirect(route('dashboard'))
|
||||||
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||||
|
actAsAdmin();
|
||||||
|
$this->get(route('admin.rooms.judgingAssignment'))
|
||||||
|
->assertOk();
|
||||||
|
});
|
||||||
|
it('shows a card for each room with its judges', function () {
|
||||||
|
// Arrange
|
||||||
|
$rooms = Room::factory()->count(3)->create();
|
||||||
|
foreach ($rooms as $room) {
|
||||||
|
$users = User::factory()->count(3)->create();
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$room->addJudge($user->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Act & Assert
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->get(route('admin.rooms.judgingAssignment'));
|
||||||
|
$response->assertOk();
|
||||||
|
foreach ($rooms as $room) {
|
||||||
|
$response->assertElementExists('#room-'.$room->id.'-card', function (AssertElement $element) use ($room) {
|
||||||
|
$element->is('li');
|
||||||
|
$element->containsText($room->name);
|
||||||
|
foreach ($room->judges as $judge) {
|
||||||
|
$element->containsText($judge->full_name());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('can assign a judge', function () {
|
||||||
|
// Arrange
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
// Act & Assert
|
||||||
|
expect($room->judges->contains($judge))->toBeFalse();
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->post(route('admin.rooms.updateJudgeAssignment', $room), ['judge' => $judge->id]);
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.judgingAssignment'))
|
||||||
|
->assertSessionHas('success', 'Assigned '.$judge->full_name().' to '.$room->name)
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
$checkRoom = Room::find($room->id);
|
||||||
|
expect($checkRoom->judges->contains($judge))->toBeTrue();
|
||||||
|
});
|
||||||
|
it('can remove a judge', function () {
|
||||||
|
// Arrange
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
$judge = User::factory()->create();
|
||||||
|
$room->addJudge($judge->id);
|
||||||
|
expect($room->judges->contains($judge))->toBeTrue();
|
||||||
|
actAsAdmin();
|
||||||
|
// Act & Assert
|
||||||
|
$response = $this->delete(route('admin.rooms.updateJudgeAssignment', $room), ['judge' => $judge->id]);
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.judgingAssignment'))
|
||||||
|
->assertSessionHas('success', 'Removed '.$judge->full_name().' from '.$room->name)
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
$checkRoom = Room::find($room->id);
|
||||||
|
expect($checkRoom->judges->contains($judge))->toBeFalse();
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue