diff --git a/tests/Feature/Pages/JudgingEntryScoreSheetTest.php b/tests/Feature/Pages/JudgingEntryScoreSheetTest.php new file mode 100644 index 0000000..990c674 --- /dev/null +++ b/tests/Feature/Pages/JudgingEntryScoreSheetTest.php @@ -0,0 +1,120 @@ +scoringGuide = ScoringGuide::factory()->create(); + SubscoreDefinition::factory()->count(5)->create(['scoring_guide_id' => $this->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' => $this->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(); + } + +}); + +it('responds favorably to a user assigned to judge this audition', function () { + $this->actingAs($this->user); + $this->get(route('judging.entryScoreSheet', $this->entries->first())) + ->assertOK(); +}); +it('redirects a user that is not assigned to judge this audition', function () { + $user = User::factory()->create(); + $this->actingAs($user); + $this->get(route('judging.entryScoreSheet', $this->entries->first())) + ->assertRedirect(route('dashboard')); +}); +it('redirects a guest', function () { + $this->get(route('judging.entryScoreSheet', $this->entries->first())) + ->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.entryScoreSheet', $this->entries->first())) + ->assertRedirect(route('dashboard')); +}); +it('has a field label for each subscore', function () { + // Arrange + $this->actingAs($this->user); + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + // Act & Assert + foreach ($this->scoringGuide->subscores as $subscore) { + $response->assertSeeInOrder(['label', $subscore->name, '/label']); + } +}); +it('has an input field for each subscore', function () { + // Arrange + $this->actingAs($this->user); + // Act & Assert + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + foreach ($this->scoringGuide->subscores as $subscore) { + $response->assertSeeInOrder(['input', 'name=', 'score['.$subscore->id.']']); + } +}); +it('shows advancement votes if advancement is enabled', function () { + // Arrange + Settings::set('advanceTo', 'OMEA'); + $this->actingAs($this->user); + // Act & Assert + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + $response + ->assertSee(auditionSetting('advanceTo').' Advancement') + ->assertSeeInOrder(['Yes', 'No', 'DQ']); + + Settings::set('advanceTo', null); + $response = $this->get(route('judging.entryScoreSheet', $this->entries->first())); + $response + ->assertDontSee([auditionSetting('advanceTo').' Advancement', 'Yes', 'DQ']); +}); +it('allows an assigned judge to enter scores', function () { + // Arrange + $this->actingAs($this->user); + $score = []; + foreach ($this->scoringGuide->subscores as $subscore) { + $score[$subscore->id] = mt_rand(0, 100); + } + // Act & Assert + $this->post(route('judging.saveScoreSheet', $this->entries->first()), + ['advancement-vote' => 'yes', 'score' => $score]) + ->assertSessionHasNoErrors() + ->assertRedirect(route('judging.auditionEntryList', $this->entries->first()->audition)) + ->assertSessionHas('success', + 'Entered scores for '.$this->entries->first()->audition->name.' '.$this->entries->first()->draw_number); + + $arrayToTest = []; + $orderedSubscores = $this->audition->scoringGuide->subscores()->orderBy('display_order')->get(); + foreach ($orderedSubscores as $subscore) { + $arrayToTest[] = $score[$subscore->id]; + } + $this->get(route('judging.auditionEntryList', $this->entries->first()->audition)) + ->assertOk() + ->assertSeeInOrder([ + 'td', $arrayToTest[0], '/td', + 'td', $arrayToTest[1], '/td', + 'td', $arrayToTest[2], '/td', + 'td', $arrayToTest[3], '/td', + 'td', $arrayToTest[4], '/td', + ]); +});