Test Audition Settings Page
This commit is contained in:
parent
e3f102d6bd
commit
735d79210c
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Settings;
|
use App\Settings;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use function to_route;
|
||||||
|
|
||||||
class AuditionSettings extends Controller
|
class AuditionSettings extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -35,6 +36,6 @@ class AuditionSettings extends Controller
|
||||||
Settings::set($key, $value);
|
Settings::set($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.audition-settings')->with('success', 'Settings Saved');
|
return to_route('audition-settings')->with('success', 'Settings Saved');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Audition Settings</x-slot:page_title>
|
<x-slot:page_title>Audition Settings</x-slot:page_title>
|
||||||
<x-layout.page-section-container>
|
<x-layout.page-section-container>
|
||||||
<x-form.form method="POST" action="{{ route('audition-settings-save') }}">
|
<x-form.form id="settingsForm" method="POST" action="{{ route('audition-settings-save') }}">
|
||||||
|
|
||||||
<x-layout.page-section>
|
<x-layout.page-section>
|
||||||
<x-slot:section_name>Group Information</x-slot:section_name>
|
<x-slot:section_name>Group Information</x-slot:section_name>
|
||||||
|
|
@ -60,6 +60,15 @@
|
||||||
|
|
||||||
</x-form.body-grid>
|
</x-form.body-grid>
|
||||||
</x-layout.page-section>
|
</x-layout.page-section>
|
||||||
|
<x-layout.page-section>
|
||||||
|
<x-slot:section_name>Payment Address</x-slot:section_name>
|
||||||
|
<x-form.body-grid columns="12" class="m-3">
|
||||||
|
<x-form.field label_text="Payment Address" name="payment_address" colspan="5" :value="auditionSetting('payment_address')"/>
|
||||||
|
<x-form.field label_text="Payment City" name="payment_city" colspan="3" :value="auditionSetting('payment_city')"/>
|
||||||
|
<x-form.field label_text="Payment State" name="payment_state" colspan="2" :value="auditionSetting('payment_state')"/>
|
||||||
|
<x-form.field label_text="Payment Zip" type="number" name="payment_zip" colspan="2" :value="auditionSetting('payment_zip')"/>
|
||||||
|
</x-form.body-grid>
|
||||||
|
</x-layout.page-section>
|
||||||
|
|
||||||
<div class="grid grid-cols-12">
|
<div class="grid grid-cols-12">
|
||||||
<div class="col-span-2 col-start-11 my-5 mr-3">
|
<div class="col-span-2 col-start-11 my-5 mr-3">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection ALL */
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Sinnbeck\DomAssertions\Asserts\AssertForm;
|
||||||
|
|
||||||
|
use Sinnbeck\DomAssertions\Asserts\AssertSelect;
|
||||||
|
use function Pest\Laravel\get;
|
||||||
|
use function Pest\Laravel\post;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
it('allows administrators to access the settings page', function () {
|
||||||
|
actAsAdmin();
|
||||||
|
get(route('audition-settings'))
|
||||||
|
->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');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue