154 lines
5.4 KiB
PHP
154 lines
5.4 KiB
PHP
<?php
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Event;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertElement;
|
|
use Sinnbeck\DomAssertions\Asserts\AssertForm;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('only allows admin users to manage the draw', function () {
|
|
// Act & Assert
|
|
$this->get(route('admin.draw.index'))->assertRedirect(route('home'));
|
|
actAsNormal();
|
|
$this->get(route('admin.draw.index'))
|
|
->assertSessionHas('error', 'You are not authorized to perform this action')
|
|
->assertRedirect(route('dashboard'));
|
|
|
|
});
|
|
it('returns the view admin.draw.index', function () {
|
|
actAsAdmin();
|
|
$response = $this->get(route('admin.draw.index'));
|
|
$response->assertViewIs('admin.draw.index');
|
|
});
|
|
it('has a section for each event that has auditions', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(3)->create();
|
|
Audition::factory()->create(['event_id' => $events[0]->id]);
|
|
Audition::factory()->create(['event_id' => $events[1]->id]);
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
// Assert
|
|
foreach ($events as $event) {
|
|
if ($event->auditions->count() > 0) {
|
|
$response->assertElementExists('#event-section-'.$event->id);
|
|
} else {
|
|
$response->assertDontSee('id="event-section-'.$event->id, false);
|
|
}
|
|
}
|
|
});
|
|
it('lists auditions in each section', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(2)->create();
|
|
foreach ($events as $event) {
|
|
Audition::factory()->count(5)->create(['event_id' => $event->id]);
|
|
}
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
// Assert
|
|
foreach ($events as $event) {
|
|
$response->assertElementExists('#event-section-'.$event->id, function (AssertElement $element) use ($event) {
|
|
foreach ($event->auditions as $audition) {
|
|
$element->contains('#auditiongroup-'.$audition->id);
|
|
$element->containsText($audition->name);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
it('each audition has a checkbox with its name', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(2)->create();
|
|
foreach ($events as $event) {
|
|
Audition::factory()->count(5)->create(['event_id' => $event->id]);
|
|
}
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
$response->assertOk();
|
|
// Assert
|
|
foreach ($events as $event) {
|
|
$response->assertElementExists('#event-section-'.$event->id, function (AssertElement $element) use ($event) {
|
|
foreach ($event->auditions as $audition) {
|
|
$element->contains('#auditiongroup-'.$audition->id, function (AssertElement $element) use ($audition) {
|
|
$element->containsText($audition->name);
|
|
});
|
|
$element->contains('#auditionCheckbox-'.$audition->id);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
it('lists auditions in score order', function () {
|
|
// Arrange
|
|
$event = Event::factory()->create();
|
|
$third = Audition::factory()->create(['event_id' => $event->id, 'score_order' => 3]);
|
|
$first = Audition::factory()->create(['event_id' => $event->id, 'score_order' => 1]);
|
|
$fourth = Audition::factory()->create(['event_id' => $event->id, 'score_order' => 4]);
|
|
$second = Audition::factory()->create(['event_id' => $event->id, 'score_order' => 2]);
|
|
actAsAdmin();
|
|
// Act & Assert
|
|
$response = $this->get(route('admin.draw.index'));
|
|
$response->assertOk();
|
|
$response->assertSeeInOrder([
|
|
e($first->name),
|
|
e($second->name),
|
|
e($third->name),
|
|
e($fourth->name),
|
|
], false);
|
|
});
|
|
it('has a form wrapping all event sections', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(2)->create();
|
|
foreach ($events as $event) {
|
|
Audition::factory()->count(5)->create(['event_id' => $event->id]);
|
|
}
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
// Assert
|
|
$response
|
|
->assertOk()
|
|
->assertElementExists('#draw-form', function (AssertElement $element) use ($events) {
|
|
foreach ($events as $event) {
|
|
$element->contains('#event-section-'.$event->id);
|
|
}
|
|
});
|
|
|
|
});
|
|
it('has a submit button in each event section', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(3)->create();
|
|
Audition::factory()->create(['event_id' => $events[0]->id]);
|
|
Audition::factory()->create(['event_id' => $events[1]->id]);
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
// Assert
|
|
foreach ($events as $event) {
|
|
if ($event->auditions->count() > 0) {
|
|
$response->assertElementExists('#event-section-'.$event->id, function (AssertElement $element) {
|
|
$element->contains('button[type="submit"]');
|
|
});
|
|
}
|
|
}
|
|
});
|
|
it('submits to the route admin.draw.store and has CSRF protection', function () {
|
|
// Arrange
|
|
$events = Event::factory()->count(3)->create();
|
|
foreach ($events as $event) {
|
|
Audition::factory()->create(['event_id' => $event->id]);
|
|
}
|
|
actAsAdmin();
|
|
// Act
|
|
$response = $this->get(route('admin.draw.index'));
|
|
// Assert
|
|
$response
|
|
->assertOk()
|
|
->assertFormExists('#draw-form', function (AssertForm $form) {
|
|
$form->hasAction(route('admin.draw.store'));
|
|
$form->hasCSRF();
|
|
});
|
|
});
|