Skip to content

A free open source IT asset/license management system

Add tests for color helper

Marcus Moore49136a4d67c9
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php
index 6039457637..800a2491d4 100644
--- a/app/Helpers/Helper.php
+++ b/app/Helpers/Helper.php
@@ -73,10 +73,14 @@ class Helper
*
* @author [A. Gianotto] [<[email protected]>]
* @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;
}
}
diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php
deleted file mode 100644
index 3fab03b7f6..0000000000
--- a/tests/Feature/DefaultColorKeyTest.php
+++ /dev/null
@@ -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]);
-
-
- }
-}
diff --git a/tests/Unit/Helpers/HelperTest.php b/tests/Unit/Helpers/HelperTest.php
new file mode 100644
index 0000000000..0b5fba986c
--- /dev/null
+++ b/tests/Unit/Helpers/HelperTest.php
@@ -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));
+ }
+}