From 5b0dcbe7f5190cde8a58b8217653b80664aba1f2 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:08:01 -0400 Subject: [PATCH 1/7] Fix config header --- src/Config/apexcharts.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Config/apexcharts.php b/src/Config/apexcharts.php index c2a9158..bfda663 100644 --- a/src/Config/apexcharts.php +++ b/src/Config/apexcharts.php @@ -4,10 +4,14 @@ /* |-------------------------------------------------------------------------- - | Font Options + | ApexCharts Default Options |-------------------------------------------------------------------------- | - | Here you may specify font family and font color. + | Here you may define the default options that will be applied to all + | ApexCharts rendered using this package. To learn more about each + | available option, check the official ApexCharts documentation. + | + | https://apexcharts.com/docs/options/ | */ From 44e86c7418a7165b032ae515677757817d933bcf Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:08:08 -0400 Subject: [PATCH 2/7] Fix toJson and toVue method --- src/Traits/Formatter.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Traits/Formatter.php b/src/Traits/Formatter.php index 62822d4..c0a2525 100644 --- a/src/Traits/Formatter.php +++ b/src/Traits/Formatter.php @@ -2,24 +2,25 @@ namespace Akaunting\Apexcharts\Traits; +use Illuminate\Http\JsonResponse; + +/** @mixin \Akaunting\Apexcharts\Chart */ trait Formatter { - public function toJson() + public function toJson(): JsonResponse { - return response()->json([ - 'id' => $this->id(), - 'options' => $this->getOptions(), - ]); + return response()->json($this->toVue()); } public function toVue(): array { return [ + 'id' => $this->getId(), 'height' => $this->getHeight(), 'width' => $this->getWidth(), 'type' => $this->getType(), - 'options' => $this->getOptions(), - 'series' => json_decode($this->getSeries()), + 'options' => json_decode($this->getOptions(), true), + 'series' => $this->getSeries(), ]; } } From d57a6c9b0ab24d6bd3358023868aa3423651da96 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:08:23 -0400 Subject: [PATCH 3/7] Add formatter tests and remove unneeded test attribute --- tests/Feature/ChartsTest.php | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index 5442dc2..c662daa 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -7,7 +7,6 @@ class ChartsTest extends TestCase { - /** @test */ public function testDefaultChart() { $chart = (new Chart)->setTitle('Users Test Chart'); @@ -16,7 +15,6 @@ public function testDefaultChart() $this->assertEquals('line', $chart->getType()); } - /** @test */ public function testPieChart() { $chart = (new Chart)->setType('pie') @@ -30,7 +28,6 @@ public function testPieChart() $this->assertEquals('pie', $chart->getType()); } - /** @test */ public function testDonutChart() { $chart = (new Chart)->setType('donut') @@ -42,7 +39,6 @@ public function testDonutChart() $this->assertEquals('donut', $chart->getType()); } - /** @test */ public function testRadialChart() { $chart = (new Chart)->setType('radial') @@ -54,7 +50,6 @@ public function testRadialChart() $this->assertEquals('radial', $chart->getType()); } - /** @test */ public function testPolarChart() { $chart = (new Chart)->setType('polarArea') @@ -66,7 +61,6 @@ public function testPolarChart() $this->assertEquals('polarArea', $chart->getType()); } - /** @test */ public function testLineChart() { $chart = (new Chart)->setType('line') @@ -90,7 +84,6 @@ public function testLineChart() $this->assertEquals('line', $chart->getType()); } - /** @test */ public function testAreaChart() { $chart = (new Chart)->setType('area') @@ -115,7 +108,6 @@ public function testAreaChart() $this->assertEquals('area', $chart->getType()); } - /** @test */ public function testBarChart() { $chart = (new Chart)->setType('bar') @@ -153,7 +145,6 @@ public function testBarChart() $this->assertEquals('bar', $chart->getType()); } - /** @test */ public function testHorizontalBarChart() { $chart = (new Chart)->setType('bar') @@ -181,7 +172,6 @@ public function testHorizontalBarChart() $this->assertTrue($chart->getHorizontal()); } - /** @test */ public function testHeatmapChart() { $chart = (new Chart)->setType('heatmap') @@ -205,7 +195,6 @@ public function testHeatmapChart() $this->assertEquals('heatmap', $chart->getType()); } - /** @test */ public function testRadarChart() { $chart = (new Chart)->setType('radar') @@ -228,4 +217,64 @@ public function testRadarChart() $this->assertEquals($chart, $chart->script()['chart']); $this->assertEquals('radar', $chart->getType()); } + + public function testToVue() + { + $chart = (new Chart)->setType('line') + ->setTitle('Total Users Monthly') + ->setSubtitle('From January to March') + ->setSeries([ + 'Jan', 'Feb', 'Mar' + ]) + ->setDataset('Users', 'line', [ + [ + 'name' => 'Active Users', + 'data' => [250, 700, 1200] + ] + ]) + ->setHeight(250) + ->setGridShow(true) + ->setStrokeShow(true); + + $this->assertEquals([ + 'id', + 'height', + 'width', + 'type', + 'options', + 'series', + ] , array_keys($chart->toVue())); + } + + public function testToJson() + { + $chart = (new Chart)->setType('line') + ->setTitle('Total Users Monthly') + ->setSubtitle('From January to March') + ->setSeries([ + 'Jan', 'Feb', 'Mar' + ]) + ->setDataset('Users', 'line', [ + [ + 'name' => 'Active Users', + 'data' => [250, 700, 1200] + ] + ]) + ->setHeight(250) + ->setGridShow(true) + ->setStrokeShow(true); + + $response = $chart->toJson(); + + $this->assertEquals([ + 'id', + 'height', + 'width', + 'type', + 'options', + 'series', + ] , array_keys( + json_decode($response->content(), true)) + ); + } } From da36ee244fd448fe663f6a2bb22789feed70762c Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:08:29 -0400 Subject: [PATCH 4/7] Remove unnecessary test config --- tests/TestCase.php | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 8d6dbc2..b205b61 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,34 +9,12 @@ class TestCase extends TestBenchTestCase { /** - * Sets the env data to interact as env file values - * - * @param [type] $app - * @return void + * Load the package service provider. */ - protected function getEnvironmentSetUp($app) - { - $app['config']->set('database.default', 'testing'); - - $app['config']->set('database.connection.testing', [ - 'driver' => 'sqlite', - 'database' => ':memory:' - ]); - } - - // set providers to test the class protected function getPackageProviders($app): array { return [ Provider::class, ]; } - - // With this method I can use the facade instead of all class namespace - protected function getPackageAliases($app): array - { - return [ - 'FirstPackage' => Facade::class - ]; - } } From be91959c774ced44691f46c33d7a7c5aed0c3ec3 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:15:18 -0400 Subject: [PATCH 5/7] CS fixes --- tests/Feature/ChartsTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index c662daa..dc2faf3 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -243,7 +243,7 @@ public function testToVue() 'type', 'options', 'series', - ] , array_keys($chart->toVue())); + ], array_keys($chart->toVue())); } public function testToJson() @@ -266,15 +266,17 @@ public function testToJson() $response = $chart->toJson(); - $this->assertEquals([ + $this->assertEquals( + [ 'id', 'height', 'width', 'type', 'options', 'series', - ] , array_keys( - json_decode($response->content(), true)) + ], array_keys( + json_decode($response->content(), true) + ) ); } } From 5c29024b2561add3710ff1b03f42697b4b4cfb3e Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:15:38 -0400 Subject: [PATCH 6/7] CS fix --- tests/Feature/ChartsTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index dc2faf3..df14afa 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -274,7 +274,8 @@ public function testToJson() 'type', 'options', 'series', - ], array_keys( + ], + array_keys( json_decode($response->content(), true) ) ); From d6d98af3873ac0d0029eba6f5f1eebe95993f69c Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sat, 30 Mar 2024 19:16:16 -0400 Subject: [PATCH 7/7] CS fix --- tests/Feature/ChartsTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/Feature/ChartsTest.php b/tests/Feature/ChartsTest.php index df14afa..a094c77 100644 --- a/tests/Feature/ChartsTest.php +++ b/tests/Feature/ChartsTest.php @@ -266,18 +266,13 @@ public function testToJson() $response = $chart->toJson(); - $this->assertEquals( - [ + $this->assertEquals([ 'id', 'height', 'width', 'type', 'options', 'series', - ], - array_keys( - json_decode($response->content(), true) - ) - ); + ], array_keys(json_decode($response->content(), true))); } }