Add tests for color helper

This commit is contained in:
Marcus Moore 2023-11-08 12:35:42 -08:00
parent 4382adce85
commit 49136a4d67
3 changed files with 27 additions and 25 deletions

View file

@ -73,10 +73,14 @@ class Helper
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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 = [
'#008941',
'#FF4A46',
@ -359,8 +363,8 @@ class Helper
if($index < 0) {
$index = 0;
}
elseif($index > 265) {
$index = 265;
elseif($index >($total_colors - 1)) {
$index = $total_colors - 1;
}
}

View file

@ -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]);
}
}

View 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));
}
}