Write tests - Write tests for what was done to this point that will be kept #11

Merged
okorpheus merged 61 commits from write-tests into master 2024-07-05 21:21:32 +00:00
2 changed files with 111 additions and 1 deletions
Showing only changes of commit 6b983cc075 - Show all commits

View File

@ -20,7 +20,7 @@
@foreach($entries as $entry)
<tr>
<x-table.td>
<a href="/judging/entry/{{$entry->id}}">
<a href="{{ route('judging.entryScoreSheet',$entry) }}">
{{ $audition->name }} {{ $entry->draw_number }}
</a>
</x-table.td>

View File

@ -0,0 +1,110 @@
<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Room;
use App\Models\ScoreSheet;
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;
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',
]);
});