115 lines
4.0 KiB
PHP
115 lines
4.0 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Settings;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertElement;
|
|
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(RefreshDatabase::class);
|
|
beforeEach(function () {
|
|
|
|
$this->entry = Entry::factory()->create();
|
|
});
|
|
|
|
it('does not respond to an ordinary user', function () {
|
|
actAsNormal();
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertRedirect(route('dashboard'));
|
|
});
|
|
it('does not respond to a guest', function () {
|
|
// Act & Assert
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertRedirect(route('home'));
|
|
});
|
|
it('does not respond if the audition is published', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
$this->entry->audition->addFlag('seats_published');
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertRedirect(route('admin.entries.index'))
|
|
->assertSessionHas('error', 'Entries in auditions with seats published cannot be modified');
|
|
});
|
|
it('does not respond if advancement for the audition is published', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
$this->entry->audition->addFlag('advancement_published');
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertRedirect(route('admin.entries.index'))
|
|
->assertSessionHas('error', 'Entries in auditions with advancement results published cannot be modified');
|
|
});
|
|
it('has a delete link', function () {
|
|
// Arrange
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertSee('<input type="hidden" name="_method" value="DELETE">', false);
|
|
});
|
|
it('has a dropdown for all auditions', function () {
|
|
// Arrange
|
|
$auditions = Audition::factory()->count(5)->create();
|
|
actAsAdmin();
|
|
$response = get(route('admin.entries.edit', $this->entry));
|
|
foreach ($auditions as $audition) {
|
|
$response->assertSeeInOrder([
|
|
'option',
|
|
'value=',
|
|
$audition->id,
|
|
'option',
|
|
], false);
|
|
$response->assertSeeInOrder([
|
|
'option',
|
|
'value=',
|
|
$this->entry->audition->id,
|
|
'selected',
|
|
'option',
|
|
], false);
|
|
}
|
|
});
|
|
it('shows checkboxes for entry types only if advancement is enabled', function () {
|
|
actAsAdmin();
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertElementExists('#for_seating')
|
|
->assertElementExists('#for_advancement');
|
|
Settings::set('advanceTo', '');
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertDontSee('Enter for '.auditionSetting('auditionAbbreviation'))
|
|
->assertDontSee('Enter for '.auditionSetting('advanceTo'));
|
|
});
|
|
it('properly checks boxes based on entries settings', function () {
|
|
actAsAdmin();
|
|
get(route('admin.entries.edit', $this->entry))
|
|
->assertElementExists('#for_seating', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->has('checked');
|
|
})
|
|
->assertElementExists('#for_advancement', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->has('checked');
|
|
});
|
|
$entry2 = Entry::factory()->seatingOnly()->create();
|
|
get(route('admin.entries.edit', $entry2))
|
|
->assertElementExists('#for_seating', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->has('checked');
|
|
})
|
|
->assertElementExists('#for_advancement', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->doesntHave('checked');
|
|
});
|
|
$entry3 = Entry::factory()->advanceOnly()->create();
|
|
get(route('admin.entries.edit', $entry3))
|
|
->assertElementExists('#for_seating', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->doesntHave('checked');
|
|
})
|
|
->assertElementExists('#for_advancement', function (AssertElement $element) {
|
|
$element->is('input')
|
|
->has('checked');
|
|
});
|
|
|
|
});
|
|
// Submission tests
|