Skip to content

Commit

Permalink
Update to Laravel Dashboard 3.x and Chart Tile 6.x (#15)
Browse files Browse the repository at this point in the history
* Update to Laravel Dashboard 3.x and Chart Tile 6.x

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
dmason30 and StyleCIBot authored Dec 2, 2023
1 parent 8776e91 commit f6a471f
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 166 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: ['8.3', '8.2', '8.1', '8.0', '7.4']
laravel: [10.*, 9.*, 8.*]
php: ['8.3', '8.2', '8.1']
laravel: [10.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: 9.*
php: '7.4'
- laravel: 10.*
php: '7.4'
- laravel: 10.*
php: '8.0'
include:
- laravel: 8.*
testbench: ^6.23
- laravel: 9.*
testbench: ^7.0
- laravel: 10.*
testbench: ^8.0

Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
}
],
"require": {
"php": "^7.4|^8.0",
"fidum/laravel-dashboard-chart-tile": "^5.0.1",
"laravel/vapor-cli": "^1.54",
"spatie/laravel-dashboard": "^2.1.4"
"php": "^8.1",
"fidum/laravel-dashboard-chart-tile": "^6.0",
"laravel/vapor-cli": "^1.60",
"spatie/laravel-dashboard": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.5",
"nunomaduro/laravel-mojito": "^0.2.10",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.5"
},
"autoload": {
Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Fidum\ChartTile\ChartTileServiceProvider;
use Fidum\VaporMetricsTile\VaporMetricsTileServiceProvider;
use Livewire\LivewireServiceProvider;
use NunoMaduro\LaravelMojito\MojitoServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Spatie\Dashboard\DashboardServiceProvider;

Expand Down Expand Up @@ -72,7 +71,6 @@ protected function getPackageProviders($app): array
ChartTileServiceProvider::class,
DashboardServiceProvider::class,
LivewireServiceProvider::class,
MojitoServiceProvider::class,
VaporMetricsTileServiceProvider::class,
];
}
Expand Down
90 changes: 33 additions & 57 deletions tests/Unit/Components/VaporCacheMetricsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,31 @@
use Fidum\VaporMetricsTile\Tests\TestCase;
use Fidum\VaporMetricsTile\VaporMetricsClient;
use Livewire\Livewire;
use Livewire\Testing\TestableLivewire;
use NunoMaduro\LaravelMojito\ViewAssertion;

class VaporCacheMetricsComponentTest extends TestCase
{
public function testMount()
{
$component = new VaporCacheMetricsComponent('');
$component->mount('a1:a2', 'My Cache Defaults');

$this->assertSame($component->position, 'a1:a2');
$this->assertSame($component->tileName, 'My Cache Defaults');
Livewire::test(VaporCacheMetricsComponent::class, [
'position' => 'a1:a2',
'tileName' => 'My Cache Defaults',
])
->assertSet('position', 'a1:a2')
->assertSet('tileName', 'My Cache Defaults');
}

public function testRenderNoResults()
{
/** @var TestableLivewire $result */
$result = Livewire::test(VaporCacheMetricsComponent::class)
Livewire::test(VaporCacheMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Cache Changed')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My Cache Changed')
->assertViewHas('refreshIntervalInSeconds', 60);

$this->assertStringNotContainsString('Node 1', $html);
$this->assertStringNotContainsString('Node 2', $html);

(new ViewAssertion($html))
->contains('0% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('0 <span class="text-dimmed text-xs">Cache Hits</span>')
->contains('0 <span class="text-dimmed text-xs">Cache Misses</span>');
->assertSee('My Cache Changed')
->assertViewHas('refreshIntervalInSeconds', 60)
->assertDontSee('Node 1')
->assertDontSee('Node 2')
->assertSeeHtml('0% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Cache Hits</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Cache Misses</span>');
}

public function testRenderSingleNode()
Expand All @@ -51,24 +42,16 @@ public function testRenderSingleNode()
'totalCacheMisses' => [13243],
]);

/** @var TestableLivewire $result */
$result = Livewire::test(VaporCacheMetricsComponent::class)
Livewire::test(VaporCacheMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Cache Defaults')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My Cache Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS);

$this->assertStringNotContainsString('Node 1', $html);
$this->assertStringNotContainsString('Node 2', $html);

(new ViewAssertion($html))
->contains('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('1,123 <span class="text-dimmed text-xs">Cache Hits</span>')
->contains('13,243 <span class="text-dimmed text-xs">Cache Misses</span>');
->assertSee('My Cache Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS)
->assertDontSee('Node 1')
->assertDontSee('Node 2')
->assertSeeHtml('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('1,123 <span class="text-dimmed text-xs">Cache Hits</span>')
->assertSeeHtml('13,243 <span class="text-dimmed text-xs">Cache Misses</span>');
}

public function testRenderMultipleNodes()
Expand All @@ -79,25 +62,18 @@ public function testRenderMultipleNodes()
'totalCacheMisses' => [13243, 6654],
]);

/** @var TestableLivewire $result */
$result = Livewire::test(VaporCacheMetricsComponent::class)
Livewire::test(VaporCacheMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Cache Defaults')
->call('render');

$result->assertSee('My Cache Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS);

$assert = new ViewAssertion($result->lastRenderedDom);

$assert->contains('Node 1')
->contains('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('1,123 <span class="text-dimmed text-xs">Cache Hits</span>')
->contains('13,243 <span class="text-dimmed text-xs">Cache Misses</span>');

$assert->contains('Node 2')
->contains('75% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('6,678 <span class="text-dimmed text-xs">Cache Hits</span>')
->contains('6,654 <span class="text-dimmed text-xs">Cache Misses</span>');
->assertSee('My Cache Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS)
->assertSeeHtml('Node 1')
->assertSeeHtml('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('1,123 <span class="text-dimmed text-xs">Cache Hits</span>')
->assertSeeHtml('13,243 <span class="text-dimmed text-xs">Cache Misses</span>')
->assertSeeHtml('Node 2')
->assertSeeHtml('75% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('6,678 <span class="text-dimmed text-xs">Cache Hits</span>')
->assertSeeHtml('6,654 <span class="text-dimmed text-xs">Cache Misses</span>');
}
}
50 changes: 17 additions & 33 deletions tests/Unit/Components/VaporDatabaseMetricsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,29 @@
use Fidum\VaporMetricsTile\Tests\TestCase;
use Fidum\VaporMetricsTile\VaporMetricsClient;
use Livewire\Livewire;
use Livewire\Testing\TestableLivewire;
use NunoMaduro\LaravelMojito\ViewAssertion;

class VaporDatabaseMetricsComponentTest extends TestCase
{
public function testMount()
{
$component = new VaporDatabaseMetricsComponent('');
$component->mount('a1:a2', 'My DB Defaults');

$this->assertSame($component->position, 'a1:a2');
$this->assertSame($component->tileName, 'My DB Defaults');
Livewire::test(VaporDatabaseMetricsComponent::class, [
'position' => 'a1:a2',
'tileName' => 'My DB Defaults',
])
->assertSet('position', 'a1:a2')
->assertSet('tileName', 'My DB Defaults');
}

public function testRenderNoResults()
{
/** @var TestableLivewire $result */
$result = Livewire::test(VaporDatabaseMetricsComponent::class)
Livewire::test(VaporDatabaseMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My DB Changed')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My DB Changed')
->assertViewHas('refreshIntervalInSeconds', 60);

(new ViewAssertion($html))
->contains('0% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('0 <span class="text-dimmed text-xs">Average Database Connections</span>')
->contains('0 <span class="text-dimmed text-xs">Max Database Connections</span>');
->assertSee('My DB Changed')
->assertViewHas('refreshIntervalInSeconds', 60)
->assertSeeHtml('0% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Average Database Connections</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Max Database Connections</span>');
}

public function testRenderSingleNode()
Expand All @@ -48,20 +40,12 @@ public function testRenderSingleNode()
'maxDatabaseConnections' => 13243,
]);

/** @var TestableLivewire $result */
$result = Livewire::test(VaporDatabaseMetricsComponent::class)
Livewire::test(VaporDatabaseMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My DB Defaults')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My DB Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS);

(new ViewAssertion($html))
->contains('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->contains('1,123 <span class="text-dimmed text-xs">Average Database Connections</span>')
->contains('13,243 <span class="text-dimmed text-xs">Max Database Connections</span>');
->assertSee('My DB Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS)->assertSeeHtml('43% <span class="text-dimmed text-xs">Average CPU Utilization</span>')
->assertSeeHtml('1,123 <span class="text-dimmed text-xs">Average Database Connections</span>')
->assertSeeHtml('13,243 <span class="text-dimmed text-xs">Max Database Connections</span>');
}
}
25 changes: 11 additions & 14 deletions tests/Unit/Components/VaporEnvironmentMetricsChartComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@
use Fidum\VaporMetricsTile\Components\VaporEnvironmentMetricsChartComponent;
use Fidum\VaporMetricsTile\Tests\TestCase;
use Livewire\Livewire;
use Livewire\Testing\TestableLivewire;

class VaporEnvironmentMetricsChartComponentTest extends TestCase
{
public function testMount()
{
$component = new VaporEnvironmentMetricsChartComponent('');
$component->mount('a1:a2', 273, 'My Env Defaults', 'test_type', '100vh');

$this->assertSame('a1:a2', $component->position);
$this->assertSame(273, $component->refreshIntervalInSeconds);
$this->assertSame('My Env Defaults', $component->tileName);
$this->assertSame('test_type', $component->type);
$this->assertSame('100vh', $component->height);
Livewire::test(VaporEnvironmentMetricsChartComponent::class, [
'position' => 'a1:a2',
'tileName' => 'My Env Defaults',
'type' => 'test_type',
'height' => '100vh',
])
->assertSet('position', 'a1:a2')
->assertSet('tileName', 'My Env Defaults')
->assertSet('type', 'test_type')
->assertSet('height', '100vh');
}

public function testRender()
{
/** @var TestableLivewire $result */
$result = Livewire::test(VaporEnvironmentMetricsChartComponent::class)
Livewire::test(VaporEnvironmentMetricsChartComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Env Changed')
->set('type', ChartType::DEFAULT)
->call('render');

$result
->assertViewHas('tileName', 'My Env Changed')
->assertViewHas('type', ChartType::DEFAULT)
->assertViewHas('refreshIntervalInSeconds', 300)
Expand Down
67 changes: 26 additions & 41 deletions tests/Unit/Components/VaporEnvironmentMetricsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,33 @@
use Fidum\VaporMetricsTile\Tests\TestCase;
use Fidum\VaporMetricsTile\VaporMetricsClient;
use Livewire\Livewire;
use Livewire\Testing\TestableLivewire;
use NunoMaduro\LaravelMojito\ViewAssertion;

class VaporEnvironmentMetricsComponentTest extends TestCase
{
public function testMount()
{
$component = new VaporEnvironmentMetricsComponent('');
$component->mount('a1:a2', 'My Env Defaults');

$this->assertSame($component->position, 'a1:a2');
$this->assertSame($component->tileName, 'My Env Defaults');
Livewire::test(VaporEnvironmentMetricsComponent::class, [
'position' => 'a1:a2',
'tileName' => 'My Env Defaults',
])
->assertSet('position', 'a1:a2')
->assertSet('tileName', 'My Env Defaults');
}

public function testRenderNoResults()
{
/** @var TestableLivewire $result */
$result = Livewire::test(VaporEnvironmentMetricsComponent::class)
Livewire::test(VaporEnvironmentMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Env Changed')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My Env Changed')
->assertViewHas('refreshIntervalInSeconds', 60);

(new ViewAssertion($html))
->contains('0 <span class="text-dimmed text-xs">API Gateway Requests</span>')
->contains('0 <span class="text-dimmed text-xs">Web Invocations</span>')
->contains('0ms <span class="text-dimmed text-xs">Average Web Duration</span>')
->contains('0 <span class="text-dimmed text-xs">CLI Invocations</span>')
->contains('0ms <span class="text-dimmed text-xs">Average CLI Duration</span>')
->contains('0 <span class="text-dimmed text-xs">Queue Invocations</span>')
->contains('0ms <span class="text-dimmed text-xs">Average Queue Duration</span>');
->assertSee('My Env Changed')
->assertViewHas('refreshIntervalInSeconds', 60)
->assertSeeHtml('0 <span class="text-dimmed text-xs">API Gateway Requests</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Web Invocations</span>')
->assertSeeHtml('0ms <span class="text-dimmed text-xs">Average Web Duration</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">CLI Invocations</span>')
->assertSeeHtml('0ms <span class="text-dimmed text-xs">Average CLI Duration</span>')
->assertSeeHtml('0 <span class="text-dimmed text-xs">Queue Invocations</span>')
->assertSeeHtml('0ms <span class="text-dimmed text-xs">Average Queue Duration</span>');
}

public function testRenderSingleNode()
Expand All @@ -56,24 +48,17 @@ public function testRenderSingleNode()
'averageQueueFunctionDuration' => 88292.23,
]);

/** @var TestableLivewire $result */
$result = Livewire::test(VaporEnvironmentMetricsComponent::class)
Livewire::test(VaporEnvironmentMetricsComponent::class)
->set('position', 'a1:a2')
->set('tileName', 'My Env Defaults')
->call('render');

$html = $result->lastRenderedDom;

$result->assertSee('My Env Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS);

(new ViewAssertion($html))
->contains('79 <span class="text-dimmed text-xs">API Gateway Requests</span>')
->contains('1,239,321 <span class="text-dimmed text-xs">Web Invocations</span>')
->contains('433ms <span class="text-dimmed text-xs">Average Web Duration</span>')
->contains('72,136 <span class="text-dimmed text-xs">CLI Invocations</span>')
->contains('234ms <span class="text-dimmed text-xs">Average CLI Duration</span>')
->contains('971,239 <span class="text-dimmed text-xs">Queue Invocations</span>')
->contains('88,292ms <span class="text-dimmed text-xs">Average Queue Duration</span>');
->assertSee('My Env Defaults')
->assertViewHas('refreshIntervalInSeconds', VaporMetricsClient::DEFAULT_REFRESH_SECONDS)
->assertSeeHtml('79 <span class="text-dimmed text-xs">API Gateway Requests</span>')
->assertSeeHtml('1,239,321 <span class="text-dimmed text-xs">Web Invocations</span>')
->assertSeeHtml('433ms <span class="text-dimmed text-xs">Average Web Duration</span>')
->assertSeeHtml('72,136 <span class="text-dimmed text-xs">CLI Invocations</span>')
->assertSeeHtml('234ms <span class="text-dimmed text-xs">Average CLI Duration</span>')
->assertSeeHtml('971,239 <span class="text-dimmed text-xs">Queue Invocations</span>')
->assertSeeHtml('88,292ms <span class="text-dimmed text-xs">Average Queue Duration</span>');
}
}

0 comments on commit f6a471f

Please sign in to comment.