generated from nunomaduro/skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
5 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,52 @@ | ||
<?php | ||
|
||
use Axis\Attributes\Axis; | ||
use Axis\Chart; | ||
use Axis\Charts\ChartJs; | ||
use Livewire\Component; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
test('it should return chartjs instance with proper props', function () { | ||
$config = [ | ||
'type' => 'bar', | ||
'data' => [ | ||
'labels' => ['a', 'b', 'c'], | ||
'datasets' => [ | ||
['label' => 'dataset a', 'data' => [1, 2, 3], 'borderColor' => 'red'], | ||
['label' => 'dataset b', 'data' => [2, 3, 5], 'borderColor' => 'green'], | ||
['label' => 'dataset c', 'data' => [6, 4, 9], 'borderColor' => 'yellow'], | ||
], | ||
'options' => [ | ||
'responsive' => true, | ||
], | ||
], | ||
]; | ||
|
||
$chart = Chart::chartjs($config); | ||
|
||
expect(invade($chart, 'config'))->toBe($config); | ||
}); | ||
|
||
test('it should properly set axis attribute when called on livewire context for chartjs', function () { | ||
$component = new class extends Component | ||
{ | ||
#[Axis] | ||
public function chartjs(): ChartJs | ||
{ | ||
return Chart::chartjs([]); | ||
} | ||
|
||
public function render(): string | ||
{ | ||
return '<div></div>'; | ||
} | ||
}; | ||
|
||
$component = livewire($component::class); | ||
|
||
$chartjs = $component->get('chartjs'); | ||
|
||
expect(invade($chartjs, 'attribute'))->toBeInstanceOf(Axis::class); | ||
expect(invade($chartjs, 'component'))->toBeInstanceOf(Component::class); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
<?php | ||
|
||
use Axis\Traits\ParsesJs; | ||
|
||
beforeEach(function () { | ||
$this->class = new class | ||
{ | ||
use ParsesJs { | ||
js as traitJs; | ||
minify as traitMinify; | ||
} | ||
|
||
public function js(mixed $data): string | ||
{ | ||
return $this->traitJs($data); | ||
} | ||
|
||
public function minify(string $data): string | ||
{ | ||
return $this->traitMinify($data); | ||
} | ||
}; | ||
}); | ||
|
||
test('it should minify string', function () { | ||
$string = <<<'JS' | ||
const foo = 'bar'; | ||
const bar = 'foo'; | ||
if (foo !== bar) { | ||
console.log('foo is not bar'); | ||
} | ||
JS; | ||
|
||
expect($this->class->minify($string)) | ||
->toBe("const foo = 'bar';const bar = 'foo';if (foo !== bar) {console.log('foo is not bar');}"); | ||
}); | ||
|
||
test('it should parse data into minified js', function () { | ||
$data = [ | ||
'foo' => 'bar', | ||
'bar' => 'foo', | ||
'foobar' => 'barfoo', | ||
]; | ||
|
||
expect($this->class->js($data)) | ||
->toBe("JSON.parse('{\u0022foo\u0022:\u0022bar\u0022,\u0022bar\u0022:\u0022foo\u0022,\u0022foobar\u0022:\u0022barfoo\u0022}')"); | ||
}); |