#23 - collective editing vacation days (#26)

* #23 - wip

* #23 - wip

* #23 - wip

* #23 - wip

* #23 - fix

* #23 - ecs fix

* #23 - fix

* #23 - fix

* #23 - cr fix
This commit is contained in:
Adrian Hopek
2022-01-24 11:28:00 +01:00
committed by GitHub
parent 652587dbf1
commit e147d24365
35 changed files with 1000 additions and 41 deletions

View File

@@ -5,10 +5,10 @@ declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
use Tests\FeatureTestCase;
use Toby\Models\User;
class AuthenticationTest extends TestCase
class AuthenticationTest extends FeatureTestCase
{
use DatabaseMigrations;

View File

@@ -6,10 +6,10 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
use Tests\FeatureTestCase;
use Toby\Models\User;
class InertiaTest extends TestCase
class InertiaTest extends FeatureTestCase
{
use DatabaseMigrations;

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Tests\FeatureTestCase;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\User;
class SelectYearPeriodTest extends FeatureTestCase
{
use DatabaseMigrations;
protected YearPeriodRetriever $yearPeriodRetriever;
protected function setUp(): void
{
parent::setUp();
$this->yearPeriodRetriever = $this->app->make(YearPeriodRetriever::class);
}
public function testUserCanSelectNextYearPeriod(): void
{
$nextYearPeriod = $this->createYearPeriod(Carbon::now()->year + 1);
$user = User::factory()->create();
$this->actingAs($user)
->post("/year-periods/{$nextYearPeriod->id}/select")
->assertRedirect();
$this->assertSame($nextYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
public function testUserCannotSelectNextYearPeriodIfDoesntExist(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post("/year-periods/25/select")
->assertNotFound();
}
public function testIfUserDoesntSelectAnyYearPeriodCurrentActsAsSelected(): void
{
$currentYearPeriod = $this->yearPeriodRetriever->current();
$this->assertSame($currentYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
}

View File

@@ -6,23 +6,15 @@ namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
use Tests\FeatureTestCase;
use Toby\Enums\EmploymentForm;
use Toby\Models\User;
class UserTest extends TestCase
class UserTest extends FeatureTestCase
{
use DatabaseMigrations;
protected function setUp(): void
{
parent::setUp();
Storage::fake();
}
public function testAdminCanSeeUsersList(): void
{
User::factory()->count(10)->create();

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\FeatureTestCase;
use Toby\Models\User;
use Toby\Models\VacationLimit;
class VacationLimitTest extends FeatureTestCase
{
use DatabaseMigrations;
public function testAdminCanSeeVacationLimits(): void
{
$admin = User::factory()->createQuietly();
User::factory(10)->create();
$this->actingAs($admin)
->get("/vacation-limits")
->assertOk()
->assertInertia(
fn(Assert $page) => $page
->component("VacationLimits")
->has("limits.data", 10),
);
}
public function testAdminCanUpdateVacationLimits(): void
{
$admin = User::factory()->createQuietly();
User::factory(3)->create();
[$limit1, $limit2, $limit3] = VacationLimit::all();
$data = [
[
"id" => $limit1->id,
"days" => 25,
],
[
"id" => $limit2->id,
"days" => null,
],
[
"id" => $limit3->id,
"days" => 20,
],
];
$this->actingAs($admin)
->put("/vacation-limits", [
"items" => $data,
])
->assertRedirect();
$this->assertDatabaseHas("vacation_limits", [
"id" => $limit1->id,
"days" => 25,
]);
$this->assertDatabaseHas("vacation_limits", [
"id" => $limit2->id,
"days" => null,
]);
$this->assertDatabaseHas("vacation_limits", [
"id" => $limit3->id,
"days" => 20,
]);
}
}