This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
vue
macro to ComponentAttributeBag
- Loading branch information
1 parent
49fef2d
commit 6b31fa7
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Illuminate\View\ComponentAttributeBag; | ||
use Tests\TestCase; | ||
|
||
class ComponentAttributeBagTest extends TestCase | ||
{ | ||
private function attr($attribute, $value = null, bool $omitBlankValue = true, bool $escape = true): string | ||
{ | ||
return (new ComponentAttributeBag) | ||
->vue($attribute, $value, $omitBlankValue, $escape) | ||
->toHtml(); | ||
} | ||
|
||
/** @test */ | ||
public function it_omits_blank_values_by_default() | ||
{ | ||
$this->assertEmpty($this->attr('animation', '')); | ||
$this->assertEmpty($this->attr('animation', null)); | ||
$this->assertEmpty($this->attr('animation', [])); | ||
} | ||
|
||
/** @test */ | ||
public function it_doesnt_affect_non_vue_attributes() | ||
{ | ||
$this->assertEquals('animation="default"', $this->attr('animation', 'default')); | ||
} | ||
|
||
/** @test */ | ||
public function it_rewrites_a_vue_event_shortcut_to_the_full_notation() | ||
{ | ||
$this->assertEquals('v-on:click="doSomething"', $this->attr('@click', 'doSomething')); | ||
$this->assertEquals('v-on:click="doSomething"', $this->attr('v-on:click', 'doSomething')); | ||
} | ||
|
||
/** @test */ | ||
public function it_rewrites_a_vue_binding_shortcut_to_the_full_notation() | ||
{ | ||
$this->assertEquals('v-bind:animation="default"', $this->attr(':animation', 'default')); | ||
$this->assertEquals('v-bind:animation="default"', $this->attr('v-bind:animation', 'default')); | ||
} | ||
|
||
/** @test */ | ||
public function it_rewrites_a_boolean_value_to_a_string() | ||
{ | ||
$this->assertEquals('v-bind:animation="true"', $this->attr(':animation', true)); | ||
$this->assertEquals('v-bind:animation="false"', $this->attr(':animation', false)); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_bind_arrays() | ||
{ | ||
$this->assertEquals('v-bind:animation="JSON.parse('[1,2,3]')"', $this->attr(':animation', [1, 2, 3])); | ||
$this->assertEquals('v-bind:animation="JSON.parse('[true,false]')"', $this->attr(':animation', [true, false])); | ||
$this->assertEquals('v-bind:animation="JSON.parse('[\u0022a\u0022,\u0022b\u0022]')"', $this->attr(':animation', ['a', 'b'])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters