Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for dashboard counts #15472

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/Feature/DashboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace Tests\Feature;

use App\Models\Accessory;
use App\Models\Asset;
use App\Models\Component;
use App\Models\Consumable;
use App\Models\License;
use App\Models\User;
use Tests\TestCase;

Expand All @@ -13,4 +18,39 @@ public function testUsersWithoutAdminAccessAreRedirected()
->get(route('home'))
->assertRedirect(route('view-assets'));
}

public function testCountsAreLoadedCorrectlyForAdmins()
{
Asset::factory()->count(2)->create();
Accessory::factory()->count(2)->create();
License::factory()->count(2)->create();
Consumable::factory()->count(2)->create();
Component::factory()->count(2)->create();

$this->actingAs(User::factory()->admin()->create())
->get(route('home'))
->assertViewIs('dashboard')
->assertViewHas('counts', function ($value) {
$accessoryCount = Accessory::count();
$assetCount = Asset::count();
$componentCount = Component::count();
$consumableCount = Consumable::count();
$licenseCount = License::assetcount();
$userCount = User::count();

$this->assertEquals($value['accessory'], $accessoryCount, 'Accessory count incorrect.');
$this->assertEquals($value['asset'], $assetCount, 'Asset count incorrect.');
$this->assertEquals($value['license'], $licenseCount, 'License count incorrect.');
$this->assertEquals($value['consumable'], $consumableCount, 'Consumable count incorrect.');
$this->assertEquals($value['component'], $componentCount, 'Component count incorrect.');
$this->assertEquals($value['user'], $userCount, 'User count incorrect.');
$this->assertEquals(
$value['grand_total'],
$accessoryCount + $assetCount + $consumableCount + $licenseCount,
'Grand total count incorrect.'
);

return true;
});
}
}
Loading