Skip to content

Commit

Permalink
Improve the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darrencoutts118 committed Dec 13, 2023
1 parent 5b79008 commit 4e660c4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tests/AttributeBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

uses(\AppKit\UI\Tests\TestCase::class);

beforeEach(function () {
$attributeBag = new ComponentAttributeBag();
function createAttributeBuilder($attributes = [], $options = [])
{
$attributeBag = new ComponentAttributeBag($attributes);

$this->attributeBuilder = new AttributeBuilder($attributeBag, collect());
});
return new AttributeBuilder($attributeBag, collect($options));
}

it('can be initialised with an empty attribute bag', function () {
expect($this->attributeBuilder->getAttributeBag()->jsonSerialize())->toBeEmpty();
expect(createAttributeBuilder()->getAttributes())->toBeEmpty();
});

it('can add classes in multiple ways', function (string $method, $data) {
$attributeBuilder = $this->attributeBuilder->addClass($data);
$attributeBuilder = createAttributeBuilder()->addClass($data);

expect($attributeBuilder->jsonSerialize())->toHaveKey('class', 'class-1 class-2 class-3 class-4 class-5');
expect($attributeBuilder->getAttributes())->toHaveKey('class', 'class-1 class-2 class-3 class-4 class-5');
})->with([
['as a single string', 'class-1 class-2 class-3 class-4 class-5'],
['as an array', ['class-1', 'class-2', 'class-3', 'class-4', 'class-5']],
Expand Down

0 comments on commit 4e660c4

Please sign in to comment.