Skip to content

Commit

Permalink
Add missing tests - correct attribute to respect defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
lrljoe committed Sep 12, 2024
1 parent 90900d8 commit 6cebc7f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Traits/Core/HasCustomAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getCustomAttributes(string $propertyName, bool $default = false,
return $vals;
}

return ['default' => true, 'default-colors' => true, 'default-styling' => true];
return ['default' => $default, 'default-colors' => $default, 'default-styling' => $default];
} else {
if ($this->hasCustomAttributes($propertyName)) {
$vals = array_merge(['default-colors' => $default, 'default-styling' => $default], $this->{$propertyName});
Expand All @@ -30,7 +30,7 @@ public function getCustomAttributes(string $propertyName, bool $default = false,
return $vals;
}

return ['default-colors' => true, 'default-styling' => true];
return ['default-colors' => $default, 'default-styling' => $default];

}
}
Expand Down
88 changes: 73 additions & 15 deletions tests/Traits/Core/CustomAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,99 @@
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Core;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;

final class CustomAttributesTest extends TestCase
{

public function test_can_get_custom_attribute_defaults_false_standard_mode(): void
{
$mock = new class extends PetsTable
{
public ?array $testAttributesArray;

public function configure(): void
{
$this->setDataTableFingerprint('test');
}
};

$mock->configure();
$mock->boot();


$this->assertSame([
'default' => false,
'default-colors' => true,
'default-styling' => true,
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, true));
'default' => false,
'default-colors' => false,
'default-styling' => false
], $mock->getCustomAttributes('testAttributesArray', false, true));
}

public function test_can_get_custom_attribute_defaults_false_classic_mode(): void
{
$mock = new class extends PetsTable
{
public ?array $testAttributesArray;

public function configure(): void
{
$this->setDataTableFingerprint('test');
}
};

$mock->configure();
$mock->boot();

$this->assertSame([
'default-colors' => true,
'default-styling' => true,
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, false));
'default-colors' => false,
'default-styling' => false
], $mock->getCustomAttributes('testAttributesArray', false, false));
}

public function test_can_get_custom_attribute_defaults_true_standard_mode(): void
{
$mock = new class extends PetsTable
{
public ?array $testAttributesArray;

public function configure(): void
{
$this->setDataTableFingerprint('test');
}
};

$mock->configure();
$mock->boot();

$this->assertSame([
'default' => true,
'default-colors' => true,
'default-styling' => true,
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, true));
'default' => true,
'default-colors' => true,
'default-styling' => true
], $mock->getCustomAttributes('testAttributesArray', true, true));
}

public function test_can_get_custom_attribute_defaults_true_classic_mode(): void
{
$mock = new class extends PetsTable
{
public ?array $testAttributesArray;

public function configure(): void
{
$this->setDataTableFingerprint('test');
}
};

$mock->configure();
$mock->boot();

$this->assertSame([
'default-colors' => true,
'default-styling' => true,
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, false));
'default-colors' => true,
'default-styling' => true
], $mock->getCustomAttributes('testAttributesArray', true, false));
}
}


}

0 comments on commit 6cebc7f

Please sign in to comment.