diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1a9aa64..90cd9bb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -8,21 +8,10 @@ jobs: strategy: matrix: os: [ubuntu-latest] - php: ['8.3', '8.2', '8.1', '8.0', '7.4'] - laravel: [8.*, 9.*, 10.*] + php: [8.3, 8.2, 8.1] + laravel: [10.*] dependency-version: [prefer-lowest, prefer-stable] - exclude: - - laravel: 10.* - php: 8.0 - - laravel: 10.* - php: 7.4 - - laravel: 9.* - php: 7.4 include: - - laravel: 8.* - testbench: ^6.23 - - laravel: 9.* - testbench: ^7.0 - laravel: 10.* testbench: ^8.0 diff --git a/composer.json b/composer.json index b05ceb2..5677f88 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,14 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.1", "consoletvs/charts": "^6.6.0", - "spatie/laravel-dashboard": "^2.1.4" + "spatie/laravel-dashboard": "^3.0" }, "require-dev": { "mockery/mockery": "^1.4", - "nunomaduro/laravel-mojito": "^0.2.6", - "orchestra/testbench": "^6.0|^7.0|^8.0", - "phpunit/phpunit": "^9.3", + "orchestra/testbench": "^8.0", + "phpunit/phpunit": "^9.6", "vimeo/psalm": "^4.3" }, "autoload": { diff --git a/resources/views/chart_refresh.blade.php b/resources/views/chart_refresh.blade.php index e1ec941..d7381db 100644 --- a/resources/views/chart_refresh.blade.php +++ b/resources/views/chart_refresh.blade.php @@ -4,12 +4,14 @@ @push('scripts') @endpush diff --git a/resources/views/tile.blade.php b/resources/views/tile.blade.php index 011ee08..c979350 100644 --- a/resources/views/tile.blade.php +++ b/resources/views/tile.blade.php @@ -8,5 +8,9 @@ @push('scripts') - {!! $chart->script() !!} + {!! str_replace( + '', + '', + str_replace('', '', $chart->script()), + ) !!} @endpush diff --git a/src/Components/ChartComponent.php b/src/Components/ChartComponent.php index bef5368..761f4a6 100644 --- a/src/Components/ChartComponent.php +++ b/src/Components/ChartComponent.php @@ -21,6 +21,8 @@ class ChartComponent extends Component public string $wireId; + public string $eventName; + public function mount( string $position = '', string $height = '100%', @@ -33,7 +35,8 @@ public function mount( $this->position = $position; $this->chartFactory = $chartFactory ?? DefaultChartFactory::class; $this->chartFilters = $chartFilters; - $this->wireId = $wireId ?? $this->id; + $this->wireId = $wireId ?? $this->getId(); + $this->eventName = 'chartDataRefreshed'.$this->wireId; $this->refreshIntervalInSeconds = $refreshIntervalInSeconds ?? config('dashboard.tiles.charts.refresh_interval_in_seconds', 300); @@ -61,6 +64,7 @@ protected function viewData(): array 'wireId' => $this->wireId, 'chart' => $this->chart(), 'chartFactory' => $this->chartFactory, + 'eventName' => $this->eventName, ]; } } diff --git a/src/Components/ChartRefreshComponent.php b/src/Components/ChartRefreshComponent.php index 974a1c0..6d3585c 100644 --- a/src/Components/ChartRefreshComponent.php +++ b/src/Components/ChartRefreshComponent.php @@ -15,7 +15,7 @@ protected function chart(): Chart { $chart = parent::chart(); - $this->emit('chartDataRefreshed'.$this->wireId, [ + $this->dispatch($this->eventName, [ 'labels' => $chart->labels, 'datasets' => $chart->formatDatasets(), 'options' => $chart->options, diff --git a/tests/TestCase.php b/tests/TestCase.php index e64e095..f9fd85c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,7 +5,6 @@ use ConsoleTVs\Charts\ChartsServiceProvider; use Fidum\ChartTile\ChartTileServiceProvider; use Livewire\LivewireServiceProvider; -use NunoMaduro\LaravelMojito\MojitoServiceProvider; use Orchestra\Testbench\TestCase as BaseTestCase; use Spatie\Dashboard\DashboardServiceProvider; @@ -21,10 +20,9 @@ protected function getEnvironmentSetUp($app): void protected function getPackageProviders($app): array { return [ - ChartsServiceProvider::class, - DashboardServiceProvider::class, LivewireServiceProvider::class, - MojitoServiceProvider::class, + DashboardServiceProvider::class, + ChartsServiceProvider::class, ChartTileServiceProvider::class, ]; } diff --git a/tests/Unit/Components/ChartComponentTest.php b/tests/Unit/Components/ChartComponentTest.php index 0e21568..0d2c399 100644 --- a/tests/Unit/Components/ChartComponentTest.php +++ b/tests/Unit/Components/ChartComponentTest.php @@ -7,59 +7,46 @@ use Fidum\ChartTile\Factories\DefaultChartFactory; use Fidum\ChartTile\Tests\TestCase; use Livewire\Livewire; -use Livewire\Testing\TestableLivewire; -use NunoMaduro\LaravelMojito\ViewAssertion; class ChartComponentTest extends TestCase { public function testMount() { - $component = new ChartComponent(''); - $component->mount('a1:a2', '100vh'); - - $this->assertSame('a1:a2', $component->position); - $this->assertSame(DefaultChartFactory::class, $component->chartFactory); - $this->assertSame($component->id, $component->wireId); - $this->assertSame($component->refreshIntervalInSeconds, 300); + Livewire::test(ChartComponent::class) + ->assertSet('position', '') + ->assertSet('chartFactory', DefaultChartFactory::class) + ->assertSet('refreshIntervalInSeconds', 300); } public function testRender() { - /** @var TestableLivewire $result */ - $result = Livewire::test(ChartComponent::class) - ->set('position', 'a1:a2') - ->call('render'); + $test = Livewire::test(ChartComponent::class); - $html = $result->lastRenderedDom; - $wireId = $result->id(); + $wireId = $test->id(); - $result->assertViewHas('chartFactory', DefaultChartFactory::class) + $test->assertViewHas('chartFactory', DefaultChartFactory::class) ->assertViewHas('refreshIntervalInSeconds', 300) ->assertViewHas('wireId', $wireId) - ->assertViewHas('height', '100%'); - - (new ViewAssertion($html)) - ->contains(''); + ->assertViewHas('height', '100%') + ->assertSeeHtml("chartDataRefreshed$wireId") + ->assertSeeHtml(''); } public function testRenderCustomProperties() { - /** @var TestableLivewire $result */ - $result = Livewire::test(ChartComponent::class) - ->set('chartFactory', ExamplePieChart::class) - ->set('refreshIntervalInSeconds', 60) - ->set('wireId', 'abc') - ->set('height', '75vh') - ->call('render'); - - $html = $result->lastRenderedDom; - - $result->assertViewHas('chartFactory', ExamplePieChart::class) + $test = Livewire::test(ChartComponent::class, [ + 'position' => 'a1:a2', + 'height' => '75vh', + 'chartFactory' => ExamplePieChart::class, + 'wireId' => $wireId = 'abc', + 'refreshIntervalInSeconds' => 60, + ]); + + $test + ->assertViewHas('chartFactory', ExamplePieChart::class) ->assertViewHas('refreshIntervalInSeconds', 60) - ->assertViewHas('wireId', 'abc') - ->assertViewHas('height', '75vh'); - - (new ViewAssertion($html)) - ->contains(''); + ->assertViewHas('height', '75vh') + ->assertSeeHtml("chartDataRefreshed$wireId") + ->assertSeeHtml(''); } } diff --git a/tests/Unit/Components/ChartRefreshComponentTest.php b/tests/Unit/Components/ChartRefreshComponentTest.php index 38ac2bc..dcde96d 100644 --- a/tests/Unit/Components/ChartRefreshComponentTest.php +++ b/tests/Unit/Components/ChartRefreshComponentTest.php @@ -7,64 +7,47 @@ use Fidum\ChartTile\Factories\DefaultChartFactory; use Fidum\ChartTile\Tests\TestCase; use Livewire\Livewire; -use Livewire\Testing\TestableLivewire; -use NunoMaduro\LaravelMojito\ViewAssertion; class ChartRefreshComponentTest extends TestCase { public function testMount() { - $component = new ChartRefreshComponent(''); - $component->mount('a1:a2', '100vh'); - - $this->assertSame('a1:a2', $component->position); - - $this->assertSame(DefaultChartFactory::class, $component->chartFactory); - $this->assertSame('100vh', $component->height); - $this->assertSame($component->id, $component->wireId); + Livewire::test(ChartRefreshComponent::class) + ->assertSet('position', '') + ->assertSet('height', '100%') + ->assertSet('chartFactory', DefaultChartFactory::class) + ->assertSet('refreshIntervalInSeconds', 300); } public function testRender() { - /** @var TestableLivewire $result */ - $result = Livewire::test(ChartRefreshComponent::class) - ->set('position', 'a1:a2') - ->call('render'); - - $html = $result->lastRenderedDom; - $wireId = $result->id(); - - $result->assertEmitted('chartDataRefreshed'.$wireId) + $test = Livewire::test(ChartRefreshComponent::class); + $wireId = $test->id(); + $test->assertDispatched('chartDataRefreshed'.$wireId) ->assertViewHas('chartFactory', DefaultChartFactory::class) ->assertViewHas('refreshIntervalInSeconds', 300) ->assertViewHas('wireId', $wireId) - ->assertViewHas('height', '100%'); - - (new ViewAssertion($html)) - ->contains('wire:id="'.$wireId.'"') - ->contains('class="hidden" wire:poll.300s'); + ->assertViewHas('height', '100%') + ->assertSeeHtml('wire:id="'.$wireId.'"') + ->assertSeeHtml("chartDataRefreshed$wireId") + ->assertSeeHtml('class="hidden" wire:poll.300s'); } public function testRenderCustomProperties() { - /** @var TestableLivewire $result */ - $result = Livewire::test(ChartRefreshComponent::class) - ->set('chartFactory', ExamplePieChart::class) - ->set('refreshIntervalInSeconds', 60) - ->set('wireId', 'abc') - ->set('height', '75vh') - ->call('render'); - - $html = $result->lastRenderedDom; - $wireId = $result->id(); - - $result->assertEmitted('chartDataRefreshedabc') + Livewire::test(ChartRefreshComponent::class, [ + 'position' => 'a1:a2', + 'height' => '75vh', + 'chartFactory' => ExamplePieChart::class, + 'wireId' => $wireId = 'abc', + 'refreshIntervalInSeconds' => 60, + ]) + ->assertDispatched('chartDataRefreshed'.$wireId) ->assertViewHas('chartFactory', ExamplePieChart::class) ->assertViewHas('refreshIntervalInSeconds', 60) ->assertViewHas('wireId', 'abc') - ->assertViewHas('height', '75vh'); - - (new ViewAssertion($html)) - ->contains(''); + ->assertViewHas('height', '75vh') + ->assertSeeHtml("chartDataRefreshed$wireId") + ->assertSeeHtml('class="hidden" wire:poll.60s'); } }