From 0f18a7c62ed573f581918cd6176d9d4694fdaca9 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 7 Jul 2024 19:33:52 -0500 Subject: [PATCH] Select audition and generate forms for setting and removing no_show flags --- .runParalellTestsAll/tests - paralell.run.xml | 11 ++++ .../Tabulation/EntryFlagController.php | 41 ++++++++++++ app/Http/Middleware/CheckIfCanTab.php | 2 +- .../views/tabulation/choose_entry.blade.php | 2 +- .../tabulation/no_show_confirm.blade.php | 19 ++++++ routes/tabulation.php | 7 ++ .../Pages/Tabulation/noShowConfirmTest.php | 66 +++++++++++++++++++ .../Pages/Tabulation/noShowSelectTest.php | 41 ++++++++++++ 8 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 .runParalellTestsAll/tests - paralell.run.xml create mode 100644 app/Http/Controllers/Tabulation/EntryFlagController.php create mode 100644 resources/views/tabulation/no_show_confirm.blade.php create mode 100644 tests/Feature/Pages/Tabulation/noShowConfirmTest.php create mode 100644 tests/Feature/Pages/Tabulation/noShowSelectTest.php diff --git a/.runParalellTestsAll/tests - paralell.run.xml b/.runParalellTestsAll/tests - paralell.run.xml new file mode 100644 index 0000000..06e48dc --- /dev/null +++ b/.runParalellTestsAll/tests - paralell.run.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/app/Http/Controllers/Tabulation/EntryFlagController.php b/app/Http/Controllers/Tabulation/EntryFlagController.php new file mode 100644 index 0000000..0c3ef77 --- /dev/null +++ b/app/Http/Controllers/Tabulation/EntryFlagController.php @@ -0,0 +1,41 @@ +validate([ + 'entry_id' => 'required|exists:entries,id', + ]); + $entry = Entry::with('flags')->find($validData['entry_id']); + + if ($entry->hasFlag('no_show')) { + $formId = 'no-show-cancellation-form'; + $buttonName = 'Remove No Show'; + $submitRouteName = 'entry-flags.enterNoShow'; + $cardHeading = 'Undo No Show'; + } else { + $formId = 'no-show-confirmation-form'; + $buttonName = 'Confirm No Show'; + $submitRouteName = 'entry-flags.enterNoShow'; + $cardHeading = 'Confirm No Show'; + } + + return view('tabulation.no_show_confirm', + compact('entry', 'formId', 'buttonName', 'submitRouteName', 'cardHeading')); + } +} diff --git a/app/Http/Middleware/CheckIfCanTab.php b/app/Http/Middleware/CheckIfCanTab.php index 7d28c2c..67b0513 100644 --- a/app/Http/Middleware/CheckIfCanTab.php +++ b/app/Http/Middleware/CheckIfCanTab.php @@ -25,7 +25,7 @@ class CheckIfCanTab return $next($request); } - return redirect('/')->with('error', 'You do not have access to score tabulation.'); + return redirect('dashboard')->with('error', 'You are not authorized to perform this action'); } } diff --git a/resources/views/tabulation/choose_entry.blade.php b/resources/views/tabulation/choose_entry.blade.php index 65b8585..2f4c01a 100644 --- a/resources/views/tabulation/choose_entry.blade.php +++ b/resources/views/tabulation/choose_entry.blade.php @@ -10,7 +10,7 @@ Choose Entry
- + Select diff --git a/resources/views/tabulation/no_show_confirm.blade.php b/resources/views/tabulation/no_show_confirm.blade.php new file mode 100644 index 0000000..95becb9 --- /dev/null +++ b/resources/views/tabulation/no_show_confirm.blade.php @@ -0,0 +1,19 @@ + + + {{ $cardHeading }} + + + {{ $entry->student->full_name() }} + {{$entry->school->name}} + + + {{ $entry->audition->name }} #{{ $entry->draw_number ?? ' no draw number' }} + + + + + {{ $buttonName }} + + + + diff --git a/routes/tabulation.php b/routes/tabulation.php index b2523cf..c9d6e18 100644 --- a/routes/tabulation.php +++ b/routes/tabulation.php @@ -14,6 +14,13 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function () Route::delete('/{score}', [\App\Http\Controllers\Tabulation\ScoreController::class, 'destroyScore'])->name('scores.destroy'); }); + // Entry Flagging + Route::prefix('entry-flags/')->controller(\App\Http\Controllers\Tabulation\EntryFlagController::class)->group(function () { + Route::get('/choose_no_show', 'noShowSelect')->name('entry-flags.noShowSelect'); + Route::get('/propose-no-show', 'noShowConfirm')->name('entry-flags.confirmNoShow'); + Route::post('/no-show/{entry}', 'enterNoShow')->name('entry-flags.enterNoShow'); + }); + // Generic Tabulation Routes Route::prefix('tabulation/')->controller(\App\Http\Controllers\Tabulation\TabulationController::class)->group(function () { Route::get('/status', 'status')->name('tabulation.status'); diff --git a/tests/Feature/Pages/Tabulation/noShowConfirmTest.php b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php new file mode 100644 index 0000000..4bfb895 --- /dev/null +++ b/tests/Feature/Pages/Tabulation/noShowConfirmTest.php @@ -0,0 +1,66 @@ +create(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertRedirect(route('home')); + actAsNormal(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); + actAsTab(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertOk(); + actAsAdmin(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertOk(); +}); +it('has information for the requested entry', function () { + // Arrange + $entry = Entry::factory()->create(); + // Act & Assert + actAsTab(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertOk() + ->assertSee($entry->student->full_name()) + ->assertSee($entry->audition->name) + ->assertSee($entry->student->school->name) + ->assertSee($entry->draw_number); +}); +it('posts to entry-flags.enterNoShow and has a submit button', function () { + // Arrange + $entry = Entry::factory()->create(); + // Act & Assert + actAsTab(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertOk() + ->assertFormExists('#no-show-confirmation-form', function (AssertForm $form) use ($entry) { + $form->hasMethod('POST') + ->hasAction(route('entry-flags.enterNoShow', ['entry' => $entry->id])) + ->contains('button', ['type' => 'submit']) + ->hasCSRF(); + }); +}); +it('posts to entry-flags.undoNoShow and has a remove button if the entry is already a noshow', function () { + // Arrange + $entry = Entry::factory()->create(); + $entry->addFlag('no_show'); + // Act & Assert + actAsTab(); + get(route('entry-flags.confirmNoShow', ['entry_id' => $entry->id])) + ->assertOk() + ->assertFormExists('#no-show-cancellation-form', function (AssertForm $form) use ($entry) { + $form->hasMethod('POST') + ->hasAction(route('entry-flags.undoNoShow', ['entry' => $entry->id])) + ->contains('button', ['type' => 'submit']) + ->hasCSRF(); + }); +}); diff --git a/tests/Feature/Pages/Tabulation/noShowSelectTest.php b/tests/Feature/Pages/Tabulation/noShowSelectTest.php new file mode 100644 index 0000000..e898ad8 --- /dev/null +++ b/tests/Feature/Pages/Tabulation/noShowSelectTest.php @@ -0,0 +1,41 @@ +assertRedirect(route('home')); + actAsAdmin(); + get(route('entry-flags.noShowSelect')) + ->assertOk(); + actAsTab(); + get(route('entry-flags.noShowSelect')) + ->assertOk(); + actAsNormal(); + get(route('entry-flags.noShowSelect')) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); +}); +it('has an input for entry_id', function () { + actAsAdmin(); + get(route('entry-flags.noShowSelect')) + ->assertOk() + ->assertElementExists('#entry_id', function (AssertElement $element) { + $element->is('input'); + }); +}); +it('submits to entry-flags.confirmNoShow', function () { + actAsAdmin(); + get(route('entry-flags.noShowSelect')) + ->assertOk() + ->assertFormExists('#entry-select-form', function (AssertForm $form) { + $form->hasMethod('GET') + ->hasAction(route('entry-flags.confirmNoShow')); + }); +});