feat: redesign the timeline as day columns with a bar per placement
This commit is contained in:
1 parent
4e50f23558
commit
e976342c09
8 files changed
+413
-190
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service\Assignment;
|
||||
|
||||
use App\Config\HouseCatalog;
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
@@ -12,6 +13,7 @@ use App\Entity\JobProfile;
|
||||
use App\Entity\Teamer;
|
||||
use App\Model\TimelineItem;
|
||||
use App\Service\Assignment\TimelineService;
|
||||
use Carbon\CarbonPeriodImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TimelineServiceTest extends TestCase
|
||||
@@ -82,14 +84,58 @@ class TimelineServiceTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trips running into or out of the window are clipped to its columns.
|
||||
*/
|
||||
public function testItemsArePlacedOnTheDayColumnsAndClipped(): void
|
||||
{
|
||||
$inside = $this->assignment(1);
|
||||
$startsBefore = $this->assignment(1, '2026-11-28', '2026-12-03');
|
||||
$endsAfter = $this->assignment(1, '2027-01-28', '2027-02-03');
|
||||
|
||||
$columns = array_map(
|
||||
fn (Assignment $assignment) => [$this->items($assignment)[0]->getColumn(), $this->items($assignment)[0]->getSpan()],
|
||||
[$inside, $startsBefore, $endsAfter],
|
||||
);
|
||||
|
||||
// window 2026-12-01 to 2027-01-31: 5 December is column 5, eight days
|
||||
$this->assertSame([[5, 8], [1, 3], [59, 4]], $columns);
|
||||
}
|
||||
|
||||
public function testHousesCarryNameRowsAndOpenSlots(): void
|
||||
{
|
||||
$first = $this->assignment(2);
|
||||
$overlapping = $this->assignment(1, '2026-12-10', '2026-12-14');
|
||||
$overlapping->addApplication(new Application($overlapping, $this->teamer('Carla')));
|
||||
$other = $this->assignment(1);
|
||||
$other->getDestination()->setHotelCode('AGR02');
|
||||
|
||||
$houses = $this->service()->preprocess([$first, $overlapping, $other], $this->period());
|
||||
|
||||
// sorted by name: Rotbach (AGR) before Spinabad (DGS)
|
||||
$this->assertSame(['Rotbach', 'Spinabad'], array_map(fn ($house) => $house->getName(), $houses));
|
||||
$this->assertCount(3, $houses[1]->getRows());
|
||||
$this->assertSame(2, $houses[1]->getOpenSlots());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<TimelineItem>
|
||||
*/
|
||||
private function items(Assignment $assignment): array
|
||||
{
|
||||
$rows = (new TimelineService())->preprocess([$assignment]);
|
||||
$houses = $this->service()->preprocess([$assignment], $this->period());
|
||||
|
||||
return array_merge(...array_map('array_values', $rows['DGS']));
|
||||
return array_merge(...$houses[0]->getRows());
|
||||
}
|
||||
|
||||
private function service(): TimelineService
|
||||
{
|
||||
return new TimelineService(new HouseCatalog(['AGR' => 'Rotbach', 'DGS' => 'Spinabad']));
|
||||
}
|
||||
|
||||
private function period(): CarbonPeriodImmutable
|
||||
{
|
||||
return CarbonPeriodImmutable::create('2026-12-01', '2027-01-31');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,12 +150,12 @@ class TimelineServiceTest extends TestCase
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function assignment(int $slots): Assignment
|
||||
private function assignment(int $slots, string $from = '2026-12-05', string $to = '2026-12-12'): Assignment
|
||||
{
|
||||
$destination = (new Destination())
|
||||
->setHotelCode('DGS01')
|
||||
->setDateFrom(new \DateTimeImmutable('2026-12-05'))
|
||||
->setDateTo(new \DateTimeImmutable('2026-12-12'))
|
||||
->setDateFrom(new \DateTimeImmutable($from))
|
||||
->setDateTo(new \DateTimeImmutable($to))
|
||||
;
|
||||
|
||||
return (new Assignment())
|
||||
|
||||
Reference in new issue
Block a user