Skip to content

Commit

Permalink
Add ColorColumnTests
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Nov 20, 2024
1 parent 3036190 commit eeff29d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Unit/Views/Columns/ColorColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function test_can_get_the_column_view(): void

}


public function test_can_infer_field_name_from_title_if_no_from(): void
{
$column = ColorColumn::make('Favorite Color');
Expand Down Expand Up @@ -176,4 +177,32 @@ function ($row) {
$this->assertSame('#008000', $column->getColor($rows->slice(2, 1)->first()));

}

public function test_can_get_column_get_contents_from_color(): void
{
$column = ColorColumn::make('Species Color')->color(
function ($row) {
if ($row->species_id == 1) {
return '#ff0000';
} elseif ($row->species_id == 2) {
return '#008000';
} else {
return '#ffa500';
}

}
);
$rows = $this->basicTable->setAdditionalSelects(['pets.species_id as species_id'])->getRows();

$contents1 = $column->getContents($rows->first());
$this->assertSame($contents1['color'], '#ff0000');
$this->assertSame($contents1['isTailwind'], true);
$this->assertSame($contents1['isBootstrap'], false);

$contents2 = $column->getContents($rows->last());
$this->assertSame($contents2['color'], '#ffa500');
$this->assertSame($contents2['isTailwind'], true);
$this->assertSame($contents2['isBootstrap'], false);

}
}

0 comments on commit eeff29d

Please sign in to comment.