#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

@@ -7,16 +7,19 @@ namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods;
use Toby\Models\User;
class AvatarTest extends TestCase
{
use DatabaseMigrations;
use InteractsWithYearPeriods;
protected function setUp(): void
{
parent::setUp();
$this->createCurrentYearPeriod();
Storage::fake();
}

View File

@@ -7,12 +7,13 @@ namespace Tests\Unit;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods;
use Toby\Jobs\CheckYearPeriod;
use Toby\Models\YearPeriod;
class CheckYearPeriodTest extends TestCase
{
use RefreshDatabase;
use InteractsWithYearPeriods;
public function testYearPeriodsAreCreatedWhenDontExist(): void
{
@@ -54,9 +55,7 @@ class CheckYearPeriodTest extends TestCase
$now = Carbon::now();
Carbon::setTestNow($now);
YearPeriod::factory([
"year" => $now->year,
]);
$this->createCurrentYearPeriod();
$this->assertDatabaseMissing("year_periods", [
"year" => $now->year + 1,
@@ -74,12 +73,8 @@ class CheckYearPeriodTest extends TestCase
$now = Carbon::now();
Carbon::setTestNow($now);
YearPeriod::factory([
"year" => $now->year,
])->create();
YearPeriod::factory([
"year" => $now->year + 1,
])->create();
$this->createCurrentYearPeriod();
$this->createYearPeriod($now->year + 1);
$this->assertDatabaseCount("year_periods", 2);

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods;
use Toby\Models\User;
use Toby\Models\YearPeriod;
class VacationLimitTest extends TestCase
{
use DatabaseMigrations;
use InteractsWithYearPeriods;
protected function setUp(): void
{
parent::setUp();
$this->createCurrentYearPeriod();
}
public function testWhenUserIsCreatedThenVacationLimitIsCreatedForCurrentYearPeriod(): void
{
$this->assertDatabaseCount("vacation_limits", 0);
$currentYearPeriod = YearPeriod::current();
$user = User::factory()->create();
$this->assertDatabaseCount("vacation_limits", 1);
$this->assertDatabaseHas("vacation_limits", [
"user_id" => $user->id,
"year_period_id" => $currentYearPeriod->id,
]);
}
public function testWhenYearPeriodIsCreatedThenVacationLimitsForThisYearPeriodAreCreated(): void
{
$this->assertDatabaseCount("vacation_limits", 0);
User::factory(10)->createQuietly();
YearPeriod::factory()->create();
$this->assertDatabaseCount("vacation_limits", 10);
}
}

View File

@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);
namespace Tests\Unit;
use Illuminate\Foundation\Testing\Concerns\InteractsWithSession;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Tests\TestCase;
use Tests\Traits\InteractsWithYearPeriods;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\YearPeriod;
class YearPeriodRetrieverTest extends TestCase
{
use RefreshDatabase;
use InteractsWithSession;
use InteractsWithYearPeriods;
public Carbon $current;
public YearPeriod $previousYearPeriod;
public YearPeriod $currentYearPeriod;
public YearPeriod $nextYearPeriod;
public YearPeriodRetriever $yearPeriodRetriever;
protected function setUp(): void
{
parent::setUp();
$this->current = Carbon::now();
Carbon::setTestNow($this->current);
$this->yearPeriodRetriever = $this->app->make(YearPeriodRetriever::class);
$this->previousYearPeriod = $this->createYearPeriod($this->current->year - 1);
$this->currentYearPeriod = $this->createCurrentYearPeriod();
$this->nextYearPeriod = $this->createYearPeriod($this->current->year + 1);
}
public function testRetrievesCorrectCurrentYearPeriod(): void
{
$this->assertSame($this->currentYearPeriod->id, $this->yearPeriodRetriever->current()->id);
}
public function testRetrievesCurrentYearPeriodWhenNoneIsSelected(): void
{
$this->clearSelectedYearPeriod();
$this->assertSame($this->currentYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
public function testRetrievesCorrectYearPeriodWhenSelected(): void
{
$this->markYearPeriodAsSelected($this->nextYearPeriod);
$this->assertSame($this->nextYearPeriod->id, $this->yearPeriodRetriever->selected()->id);
}
public function testLinks(): void
{
$expected = [
"current" => $this->current->year,
"navigation" => [
[
"year" => $this->previousYearPeriod->year,
"link" => route("year-periods.select", $this->previousYearPeriod),
],
[
"year" => $this->currentYearPeriod->year,
"link" => route("year-periods.select", $this->currentYearPeriod),
],
[
"year" => $this->nextYearPeriod->year,
"link" => route("year-periods.select", $this->nextYearPeriod),
],
],
];
$this->assertSame($expected, $this->yearPeriodRetriever->links());
}
}