86 lines
3.3 KiB
PHP
86 lines
3.3 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\ScoringGuide;
|
|
use App\Models\SubscoreDefinition;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertElement;
|
|
|
|
use function Pest\Laravel\get;
|
|
use function Pest\Laravel\post;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('shows a scoring guide management page only to administrators', function () {
|
|
get(route('admin.scoring.index'))
|
|
->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
get(route('admin.scoring.index'))
|
|
->assertRedirect(route('dashboard'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
actAsAdmin();
|
|
get(route('admin.scoring.index'))
|
|
->assertOk()
|
|
->assertViewIs('admin.scoring.index');
|
|
});
|
|
it('shows a list of scoring guides and their count of subscores', function () {
|
|
$scoringGuide = ScoringGuide::factory()->create();
|
|
SubscoreDefinition::factory()->count(3)->create(['scoring_guide_id' => $scoringGuide->id]);
|
|
Audition::factory()->count(3)->create(['scoring_guide_id' => $scoringGuide->id]);
|
|
actAsAdmin();
|
|
$response = get(route('admin.scoring.index'));
|
|
$response->assertOk()
|
|
->assertSeeInOrder(['<td', $scoringGuide->name, $scoringGuide->subscores()->count()], false);
|
|
});
|
|
it('shows a link to edit each scoring guide', function () {
|
|
$scoringGuide = ScoringGuide::factory()->create();
|
|
actAsAdmin();
|
|
$response = get(route('admin.scoring.index'));
|
|
$response->assertOk()
|
|
->assertSee(route('admin.scoring.edit', $scoringGuide));
|
|
});
|
|
it('shows auditions in groups with their scoring guide', function () {
|
|
$guides = ScoringGuide::factory()->count(2)->create();
|
|
foreach ($guides as $guide) {
|
|
Audition::factory()->count(3)->create(['scoring_guide_id' => $guide->id]);
|
|
}
|
|
actAsAdmin();
|
|
$response = get(route('admin.scoring.index'));
|
|
$response->assertOk();
|
|
foreach (Audition::all() as $audition) {
|
|
$guide = $audition->scoringGuide;
|
|
$response->assertElementExists('#guide-'.$guide->id, function (AssertElement $element) use ($audition) {
|
|
$element->containsText($audition->name);
|
|
});
|
|
}
|
|
});
|
|
it('has a form for a new scoring guide', function () {
|
|
actAsAdmin();
|
|
$response = get(route('admin.scoring.index'));
|
|
$response->assertOk()
|
|
->assertSeeInOrder(['<input', 'name=', 'name'], false)
|
|
->assertSee(route('admin.scoring.store'));
|
|
});
|
|
it('creates a new scoring guide', function () {
|
|
$formData = ['name' => 'New Scoring Guide'];
|
|
actAsAdmin();
|
|
$response = post(route('admin.scoring.store'), $formData);
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
$response
|
|
->assertSessionHasNoErrors()
|
|
->assertRedirect(route('admin.scoring.index'))
|
|
->assertSessionHas('success', 'Scoring guide created');
|
|
$this->assertDatabaseHas('scoring_guides', $formData);
|
|
});
|
|
it('only allows an admin to create a new scoring guide', function () {
|
|
// Arrange
|
|
$formData = ['name' => 'New Scoring Guide'];
|
|
// Act & Assert
|
|
$response = post(route('admin.scoring.store'), $formData);
|
|
$response->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$response = post(route('admin.scoring.store'), $formData);
|
|
$response->assertRedirect(route('dashboard'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action');
|
|
});
|