AdminRooms Page Tests
This commit is contained in:
parent
d21324b71b
commit
cde4925368
|
|
@ -100,7 +100,7 @@ class RoomController extends Controller
|
||||||
$room->description = $validData['description'];
|
$room->description = $validData['description'];
|
||||||
$room->save();
|
$room->save();
|
||||||
|
|
||||||
return redirect()->route('admin.rooms.index')->with('success', 'Room updated.');
|
return redirect()->route('admin.rooms.index')->with('success', 'Room updated successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Room $room)
|
public function destroy(Room $room)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
<x-card.card x-data="{ showModal: false }" class="relative">
|
<x-card.card x-data="{ showModal: false }" class="relative">
|
||||||
@include('admin.rooms.index-edit-room-modal')
|
@if($room->id != '0')
|
||||||
|
@include('admin.rooms.index-edit-room-modal')
|
||||||
|
@endif
|
||||||
<x-card.heading @click=" showModal = ! showModal">
|
<x-card.heading @click=" showModal = ! showModal">
|
||||||
{{ $room->name }}
|
{{ $room->name }}
|
||||||
<x-slot:subheading>{{ $room->description }}</x-slot:subheading>
|
<x-slot:subheading>{{ $room->description }}</x-slot:subheading>
|
||||||
<x-slot:right_side>
|
<x-slot:right_side>
|
||||||
@if($room->entries->count() === 0 and $room->id != '0')
|
@if($room->auditions->count() === 0 and $room->id != '0')
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-end">
|
||||||
<x-form.form method="DELETE"
|
<x-form.form method="DELETE"
|
||||||
action="{{ route('admin.rooms.destroy', ['room'=>$room->id]) }}"
|
action="{{ route('admin.rooms.destroy', ['room'=>$room->id]) }}"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Rooms</x-slot:page_title>
|
<x-slot:page_title>Rooms</x-slot:page_title>
|
||||||
<x-slot:title_bar_right><x-form.button href="/admin/rooms/create">New Room</x-form.button></x-slot:title_bar_right>
|
<x-slot:title_bar_right><x-form.button href="{{route('admin.rooms.create')}}">New Room</x-form.button></x-slot:title_bar_right>
|
||||||
<!--suppress JSUnresolvedReference -->
|
<!--suppress JSUnresolvedReference -->
|
||||||
<div class="grid md:grid-cols-4 gap-5" x-data="roomManager()">
|
<div class="grid md:grid-cols-4 gap-5" x-data="roomManager()">
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
use function Pest\Laravel\get;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
function roomTestSetup(): void
|
||||||
|
{
|
||||||
|
$rooms = Room::factory()->count(3)->create();
|
||||||
|
foreach ($rooms as $room) {
|
||||||
|
Audition::factory()->count(3)->create(['room_id' => $room->id]);
|
||||||
|
}
|
||||||
|
$auditions = Audition::all();
|
||||||
|
foreach ($auditions as $audition) {
|
||||||
|
$n = fake()->numberBetween(1, 4);
|
||||||
|
Entry::factory()->count($n)->create(['audition_id' => $audition->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it('only allows an admin to manage rooms', function () {
|
||||||
|
get(route('admin.rooms.index'))
|
||||||
|
->assertRedirect(route('home'));
|
||||||
|
actAsNormal();
|
||||||
|
get(route('admin.rooms.index'))
|
||||||
|
->assertRedirect(route('dashboard'))
|
||||||
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
||||||
|
actAsAdmin();
|
||||||
|
get(route('admin.rooms.index'))
|
||||||
|
->assertOk();
|
||||||
|
});
|
||||||
|
it('has a link to create a new room', function () {
|
||||||
|
actAsAdmin();
|
||||||
|
get(route('admin.rooms.index'))
|
||||||
|
->assertSee('New Room')
|
||||||
|
->assertSee(route('admin.rooms.create'));
|
||||||
|
});
|
||||||
|
it('has a card for each room, including the total number of entries in that room', function () {
|
||||||
|
// Arrange
|
||||||
|
roomTestSetup();
|
||||||
|
// Act & Assert
|
||||||
|
actAsAdmin();
|
||||||
|
$response = get(route('admin.rooms.index'));
|
||||||
|
$response->assertOk();
|
||||||
|
foreach (Room::all() as $room) {
|
||||||
|
$roomEntryCount = $room->entries()->count();
|
||||||
|
$response->assertSeeInOrder(['<h3', e($room->name), '</h3>', $roomEntryCount], false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('has a form for editing each room', function () {
|
||||||
|
// Arrange
|
||||||
|
roomTestSetup();
|
||||||
|
// Act & Assert
|
||||||
|
actAsAdmin();
|
||||||
|
$response = get(route('admin.rooms.index'));
|
||||||
|
$response->assertOk();
|
||||||
|
foreach (Room::all() as $room) {
|
||||||
|
if ($room->id === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$response->assertSeeInOrder([
|
||||||
|
route('admin.rooms.update', $room),
|
||||||
|
'<input',
|
||||||
|
'name=', 'name',
|
||||||
|
'<input',
|
||||||
|
'name=',
|
||||||
|
'description',
|
||||||
|
], false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it('can edit a room', function () {
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
$formData = [
|
||||||
|
'name' => 'New Room Name',
|
||||||
|
'description' => 'New Room Description',
|
||||||
|
];
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->patch(route('admin.rooms.update', $room), $formData);
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.index'))
|
||||||
|
->assertSessionHas('success', 'Room updated successfully')
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
$this->assertDatabaseHas('rooms', $formData);
|
||||||
|
});
|
||||||
|
it('can create a room', function () {
|
||||||
|
$formData = [
|
||||||
|
'name' => 'New Room Name',
|
||||||
|
'description' => 'New Room Description',
|
||||||
|
];
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->post(route('admin.rooms.store'), $formData);
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.index'))
|
||||||
|
->assertSessionHas('success', 'Room created.')
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
$this->assertDatabaseHas('rooms', $formData);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can delete a room', function () {
|
||||||
|
// Arrange
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
// Act & Assert
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->delete(route('admin.rooms.destroy', $room));
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.index'))
|
||||||
|
->assertSessionHas('success', 'Room deleted.')
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
$this->assertDatabaseMissing('rooms', ['id' => $room->id]);
|
||||||
|
});
|
||||||
|
it('will not delete a room with auditions', function () {
|
||||||
|
$room = Room::factory()->create();
|
||||||
|
Audition::factory()->create(['room_id' => $room->id]);
|
||||||
|
actAsAdmin();
|
||||||
|
$response = $this->delete(route('admin.rooms.destroy', $room));
|
||||||
|
/** @noinspection PhpUnhandledExceptionInspection */
|
||||||
|
$response->assertRedirect(route('admin.rooms.index'))
|
||||||
|
->assertSessionHas('error',
|
||||||
|
'Cannot delete room with auditions. First move the auditions to unassigned or another room')
|
||||||
|
->assertSessionHasNoErrors();
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue