From 735d79210c603d3190011e6edb9624a63415d3ff Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 4 Jul 2024 15:48:32 -0500 Subject: [PATCH] Test Audition Settings Page --- .../Controllers/Admin/AuditionSettings.php | 3 +- .../views/admin/audition-settings.blade.php | 11 +- tests/Feature/Pages/Setup/SettingsTest.php | 139 ++++++++++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Pages/Setup/SettingsTest.php diff --git a/app/Http/Controllers/Admin/AuditionSettings.php b/app/Http/Controllers/Admin/AuditionSettings.php index 6083f20..f879ea8 100644 --- a/app/Http/Controllers/Admin/AuditionSettings.php +++ b/app/Http/Controllers/Admin/AuditionSettings.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Settings; use Illuminate\Http\Request; +use function to_route; class AuditionSettings extends Controller { @@ -35,6 +36,6 @@ class AuditionSettings extends Controller Settings::set($key, $value); } - return view('admin.audition-settings')->with('success', 'Settings Saved'); + return to_route('audition-settings')->with('success', 'Settings Saved'); } } diff --git a/resources/views/admin/audition-settings.blade.php b/resources/views/admin/audition-settings.blade.php index c32ad8a..17cbcf9 100644 --- a/resources/views/admin/audition-settings.blade.php +++ b/resources/views/admin/audition-settings.blade.php @@ -1,7 +1,7 @@ Audition Settings - + Group Information @@ -60,6 +60,15 @@ + + Payment Address + + + + + + +
diff --git a/tests/Feature/Pages/Setup/SettingsTest.php b/tests/Feature/Pages/Setup/SettingsTest.php new file mode 100644 index 0000000..e53e89c --- /dev/null +++ b/tests/Feature/Pages/Setup/SettingsTest.php @@ -0,0 +1,139 @@ +assertOk() + ->assertViewIs('admin.audition-settings'); +}); +it('does not allow normal users to access the settings page', function () { + // Arrange + actAsNormal(); + // Act & Assert + get(route('audition-settings')) + ->assertSessionHas('error', 'You are not authorized to perform this action') + ->assertRedirect(route('dashboard')); +}); +it('does not allow guests to access the settings page', function () { + // Act & Assert + get(route('audition-settings')) + ->assertRedirect(route('home')); +}); +it('has a field with forms for each audition setting', function () { + // Arrange + actAsAdmin(); + // Act + $response = get(route('audition-settings')); + // Assert + $response->assertOk(); + $response->assertFormExists('#settingsForm', function (AssertForm $form) { + $form->hasMethod('POST') + ->hasAction(route('audition-settings-save')) + ->hasCSRF() + ->containsInput([ + 'name' => 'auditionName', + 'value' => auditionSetting('auditionName'), + ]) + ->containsInput([ + 'name' => 'auditionAbbreviation', + 'value' => auditionSetting('auditionAbbreviation'), + ]) + ->containsInput([ + 'name' => 'registrationCode', + 'value' => auditionSetting('registrationCode'), + ]) + ->containsInput([ + 'name' => 'advanceTo', + 'value' => auditionSetting('advanceTo'), + ]) + ->containsInput([ + 'name' => 'organizerName', + 'value' => auditionSetting('organizerName'), + ]) + ->containsInput([ + 'name' => 'organizerEmail', + 'value' => auditionSetting('organizerEmail'), + ]) + ->containsInput([ + 'name' => 'late_fee', + 'value' => number_format(auditionSetting('late_fee')/100, 2), + ]) + ->containsInput([ + 'name' => 'school_fee', + 'value' => number_format(auditionSetting('school_fee')/100, 2), + ]) + ->containsInput([ + 'name' => 'payment_address', + 'value' => auditionSetting('payment_address'), + ]) + ->containsInput([ + 'name' => 'payment_city', + 'value' => auditionSetting('payment_city'), + ]) + ->containsInput([ + 'name' => 'payment_state', + 'value' => auditionSetting('payment_state'), + ]) + ->containsInput([ + 'name' => 'payment_zip', + 'value' => auditionSetting('payment_zip'), + 'type' => 'number', + ]) + ->containsInput([ + 'name' => 'olympic_scoring', + 'type' => 'checkbox', + // TODO how can I test if it is checked when necessary + ]) + ->containsInput([ + 'name' => 'judging_enabled', + 'type' => 'checkbox', + // TODO how can I test if it is checked when necessary + ]) + ->findSelect('#fee_structure', function(AssertSelect $select) { + $select->containsOption([ + 'value' => 'oneFeePerEntry', + 'text'=> 'One fee per entry', + ]) + ->containsOption([ + 'value' => 'oneFeePerStudent', + 'text' => 'One fee per student - one late fee per student if any of their entries are late', + ]); + }); + }); +}); +it('can update audition settings', function () { + // Arrange + actAsAdmin(); + $newData = [ + 'auditionName' => 'New Audition Name', + 'auditionAbbreviation' => 'NAN', + 'registrationCode' => 'NEWCODE', + 'advanceTo' => 'next', + 'organizerName' => 'New Organizer Name', + 'organizerEmail' => 'newemail@new.com', + 'late_fee' => 150.00, + 'school_fee' => 200.00, + 'payment_address' => '123 New St', + 'payment_city' => 'New City', + 'payment_state' => 'NS', + 'payment_zip' => 12345, + 'fee_structure' => 'oneFeePerEntry' + ]; + // Act + $response = post(route('audition-settings-save'), $newData); + // Act & Assert + $response->assertRedirect(route('audition-settings')) + ->assertSessionHasNoErrors() + ->assertSessionHas('success', 'Settings Saved'); +});