Skip to content

Commit

Permalink
more tests/coverage for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Dec 22, 2023
1 parent f9043ef commit 466f1bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/attributes/Alignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace markhuot\keystone\attributes;

use craft\web\View;
use Illuminate\Support\Collection;
use markhuot\keystone\base\Attribute;

Expand All @@ -17,7 +18,7 @@ public function getInputHtml(): string
return \Craft::$app->getView()->renderTemplate('keystone/attributes/alignment', [
'name' => get_class($this),
'value' => $this->value,
]);
], View::TEMPLATE_MODE_CP);
}

public function getCssRules(): Collection
Expand Down
3 changes: 2 additions & 1 deletion src/attributes/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Craft;
use craft\elements\Asset;
use craft\web\View;
use Illuminate\Support\Collection;
use markhuot\keystone\base\Attribute;

Expand All @@ -20,7 +21,7 @@ public function getInputHtml(): string
'label' => 'Background',
'name' => get_class($this),
'value' => $this->value ?? null,
]);
], View::TEMPLATE_MODE_CP);
}

public function getCssRules(): Collection
Expand Down
13 changes: 13 additions & 0 deletions tests/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@

expect($component->getAttributeBag()->toArray())->class->toBe('');
});

it('renders attributes', function ($attrName, $props, $rules=null) {
$attr = new $attrName($props);
$output = $attr->getInputHtml();
expect($output)->toContainEach(array_keys($props));
$computedRules = $attr->getCssRules();
expect($computedRules->toArray())->toEqualCanonicalizing($rules ?? $props);
})->with([
[\markhuot\keystone\attributes\Alignment::class, ['justify-content' => 'center', 'align-items' => 'center']],
[\markhuot\keystone\attributes\Background::class, ['color' => '000'], ['color' => '#000']],
[\markhuot\keystone\attributes\Background::class, ['repeat' => false], ['background-repeat' => 'no-repeat']],
[\markhuot\keystone\attributes\Background::class, ['size' => 'contain'], ['background-size' => 'contain']],
]);
6 changes: 4 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
|
*/

expect()->extend('toBeOne', function () {
return $this->toBe(1);
expect()->extend('toContainEach', function (iterable $items) {
foreach ($items as $item) {
$this->toContain($item);
}
});

/*
Expand Down

0 comments on commit 466f1bd

Please sign in to comment.