Add tests for color helper
This commit is contained in:
parent
4382adce85
commit
49136a4d67
3 changed files with 27 additions and 25 deletions
|
@ -73,10 +73,14 @@ class Helper
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v3.3]
|
* @since [v3.3]
|
||||||
* @return array
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function defaultChartColors($index = 0)
|
public static function defaultChartColors(int $index = 0)
|
||||||
{
|
{
|
||||||
|
if ($index < 0) {
|
||||||
|
$index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$colors = [
|
$colors = [
|
||||||
'#008941',
|
'#008941',
|
||||||
'#FF4A46',
|
'#FF4A46',
|
||||||
|
@ -359,8 +363,8 @@ class Helper
|
||||||
if($index < 0) {
|
if($index < 0) {
|
||||||
$index = 0;
|
$index = 0;
|
||||||
}
|
}
|
||||||
elseif($index > 265) {
|
elseif($index >($total_colors - 1)) {
|
||||||
$index = 265;
|
$index = $total_colors - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use App\Models\Statuslabel;
|
|
||||||
use Tests\TestCase;
|
|
||||||
use App\Models\Asset;
|
|
||||||
|
|
||||||
class DefaultColorKeyTest extends TestCase
|
|
||||||
{
|
|
||||||
public function DefaultColorKeyTest()
|
|
||||||
{
|
|
||||||
Statuslabel::factory()->hasAssets(1)->count(255)->create();
|
|
||||||
|
|
||||||
$this->defaultChartColors($index);
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('index', ($index)[0]);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
19
tests/Unit/Helpers/HelperTest.php
Normal file
19
tests/Unit/Helpers/HelperTest.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Helpers;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class HelperTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testDefaultChartColorsMethodHandlesHighValues()
|
||||||
|
{
|
||||||
|
$this->assertIsString(Helper::defaultChartColors(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDefaultChartColorsMethodHandlesNegativeNumbers()
|
||||||
|
{
|
||||||
|
$this->assertIsString(Helper::defaultChartColors(-1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue