auditionadmin/tests/Feature/Pages/JudgingAudtionEntryListTest...

131 lines
5.0 KiB
PHP

<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\SubscoreDefinition;
use App\Models\User;
use App\Settings;
use Database\Seeders\ScoreAllAuditions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\Feature\Models\ScoreSheet;
use function Pest\Laravel\actingAs;
uses(RefreshDatabase::class);
beforeEach(function () {
Settings::set('judging_enabled', true);
Settings::set('advanceTo', 'OMEA');
$scoringGuide = ScoringGuide::factory()->create();
SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $scoringGuide->id]);
$this->user = User::factory()->create();
$this->room = Room::factory()->create();
$this->room->addJudge($this->user->id);
$this->audition = Audition::factory()->create([
'room_id' => $this->room->id,
'scoring_guide_id' => $scoringGuide->id,
]);
$this->entries = Entry::factory()->count(35)->create(['audition_id' => $this->audition->id]);
$n = 1;
foreach ($this->entries as $entry) {
$entry->draw_number = $n++;
$entry->save();
}
});
test('responds favorably to a user assigned to judge this audition', function () {
$this->actingAs($this->user);
$this->get(route('judging.auditionEntryList', $this->audition->id))
->assertOK();
});
test('redirects a user that is not assigned to judge this audition', function () {
$user = User::factory()->create();
$this->actingAs($user);
$this->get(route('judging.auditionEntryList', $this->audition->id))
->assertRedirect(route('dashboard'));
});
test('redirects a guest', function () {
$this->get(route('judging.auditionEntryList', $this->audition->id))
->assertRedirect(route('home'));
});
it('redirects if judging is not enabled', function () {
// Arrange
Settings::set('judging_enabled', false);
// Act & Assert
$this->actingAs($this->user);
$this->get(route('judging.auditionEntryList', $this->audition->id))
->assertRedirect(route('dashboard'));
});
test('shows headings for each subscore', function () {
$this->actingAs($this->user);
$response = $this->get(route('judging.auditionEntryList', $this->audition->id));
foreach ($this->audition->scoringGuide->subscores as $subscore) {
$response->assertSeeInOrder(['th', $subscore->name, '/th']);
}
});
test('it shows each entry in the audition', function () {
$this->actingAs($this->user);
$response = $this->get(route('judging.auditionEntryList', $this->audition->id));
foreach ($this->entries as $entry) {
$response->assertSeeInOrder(['td', $entry->draw_number, '/td']);
}
});
test('it shows a working link to the score sheet for each entry in the audition', function () {
$this->actingAs($this->user);
$response = $this->get(route('judging.auditionEntryList', $this->audition->id));
foreach ($this->entries as $entry) {
$response->assertSee(route('judging.entryScoreSheet', $entry));
$this->get(route('judging.entryScoreSheet', $entry))
->assertOK();
}
});
test('it has a column for votes if advancement is enabled', function () {
Settings::set('advanceTo', 'OMEA');
$this->actingAs($this->user);
$response = $this->get(route('judging.auditionEntryList', $this->audition->id));
$response->assertSeeInOrder(['th', 'OMEA', '/th']);
});
test('it shows scores previously entered', function () {
$this->actingAs($this->user);
Artisan::call('db:seed', ['--class' => ScoreAllAuditions::class]);
$response = $this->get(route('judging.auditionEntryList', $this->audition->id));
$testEntry = $this->entries->first();
$testSubscores = ScoreSheet::where('entry_id', $testEntry->id)->first()->subscores;
$arrayToTest = [];
$orderedSubscores = $this->audition->scoringGuide->subscores()->orderBy('display_order')->get();
foreach ($orderedSubscores as $subscore) {
$arrayToTest[] = $testSubscores[$subscore->id]['score'];
}
$response->assertSeeInOrder([
'td', $arrayToTest[0], '/td',
'td', $arrayToTest[1], '/td',
'td', $arrayToTest[2], '/td',
'td', $arrayToTest[3], '/td',
'td', $arrayToTest[4], '/td',
]);
});
it('indicates when an audition has published seats or advancement', function () {
// Arrange
$this->audition->addFlag('seats_published');
actingAs($this->user);
// Act
$response = $this->get(route('judging.auditionEntryList', $this->audition));
// Assert
$response->assertOk()
->assertSee('Results are published. Scores cannot be changed.');
$this->audition->removeFlag('seats_published');
$response = $this->get(route('judging.auditionEntryList', $this->audition));
$response->assertOk()
->assertDontSee('Results are published. Scores cannot be changed.');
$this->audition->addFlag('advancement_published');
$response = $this->get(route('judging.auditionEntryList', $this->audition));
$response->assertOk()
->assertSee('Results are published. Scores cannot be changed.');
});