Merge branch 'main' of github.com:solidtime-io/solidtime

This commit is contained in:
Gregor Vostrak
2024-04-25 20:14:56 +02:00
4 changed files with 76 additions and 3 deletions

View File

@@ -7,12 +7,13 @@ namespace App\Http\Controllers\Web;
use App\Models\Organization; use App\Models\Organization;
use App\Models\User; use App\Models\User;
use App\Service\DashboardService; use App\Service\DashboardService;
use App\Service\PermissionStore;
use Inertia\Inertia; use Inertia\Inertia;
use Inertia\Response; use Inertia\Response;
class DashboardController extends Controller class DashboardController extends Controller
{ {
public function dashboard(DashboardService $dashboardService): Response public function dashboard(DashboardService $dashboardService, PermissionStore $permissionStore): Response
{ {
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
@@ -24,10 +25,14 @@ class DashboardController extends Controller
$totalWeeklyBillableTime = $dashboardService->totalWeeklyBillableTime($user, $organization); $totalWeeklyBillableTime = $dashboardService->totalWeeklyBillableTime($user, $organization);
$totalWeeklyBillableAmount = $dashboardService->totalWeeklyBillableAmount($user, $organization); $totalWeeklyBillableAmount = $dashboardService->totalWeeklyBillableAmount($user, $organization);
$weeklyProjectOverview = $dashboardService->weeklyProjectOverview($user, $organization); $weeklyProjectOverview = $dashboardService->weeklyProjectOverview($user, $organization);
$latestTeamActivity = $dashboardService->latestTeamActivity($organization);
$latestTasks = $dashboardService->latestTasks($user, $organization); $latestTasks = $dashboardService->latestTasks($user, $organization);
$lastSevenDays = $dashboardService->lastSevenDays($user, $organization); $lastSevenDays = $dashboardService->lastSevenDays($user, $organization);
$latestTeamActivity = null;
if ($permissionStore->has($organization, 'time-entries:view:all')) {
$latestTeamActivity = $dashboardService->latestTeamActivity($organization);
}
return Inertia::render('Dashboard', [ return Inertia::render('Dashboard', [
'weeklyProjectOverview' => $weeklyProjectOverview, 'weeklyProjectOverview' => $weeklyProjectOverview,
'latestTasks' => $latestTasks, 'latestTasks' => $latestTasks,

View File

@@ -39,6 +39,15 @@ class UserFactory extends Factory
]; ];
} }
public function forCurrentOrganization(Organization $organization): static
{
return $this->state(function (array $attributes) use ($organization): array {
return [
'current_team_id' => $organization->getKey(),
];
});
}
public function randomTimeZone(): static public function randomTimeZone(): static
{ {
return $this->state(function (array $attributes) { return $this->state(function (array $attributes) {

View File

@@ -75,7 +75,7 @@ const switchToTeam = (team: Organization) => {
<div class="w-60"> <div class="w-60">
<!-- Organization Management --> <!-- Organization Management -->
<div class="block px-4 py-2 text-xs text-muted"> <div class="block px-4 py-2 text-xs text-muted">
Manage Team Manage Organization
</div> </div>
<!-- Organization Settings --> <!-- Organization Settings -->

View File

@@ -4,7 +4,10 @@ declare(strict_types=1);
namespace Tests\Unit\Endpoint\Web; namespace Tests\Unit\Endpoint\Web;
use App\Enums\Role;
use App\Models\Organization;
use App\Models\User; use App\Models\User;
use Inertia\Testing\AssertableInertia as Assert;
class DashboardEndpointTest extends EndpointTestAbstract class DashboardEndpointTest extends EndpointTestAbstract
{ {
@@ -19,5 +22,61 @@ class DashboardEndpointTest extends EndpointTestAbstract
// Assert // Assert
$response->assertSuccessful(); $response->assertSuccessful();
$response->assertInertia(fn (Assert $page) => $page
->has('weeklyProjectOverview')
->has('latestTasks')
->has('lastSevenDays')
->has('latestTeamActivity')
->has('dailyTrackedHours')
->has('totalWeeklyTime')
->has('totalWeeklyBillableTime')
->has('totalWeeklyBillableAmount')
->has('weeklyHistory')
->whereNot('weeklyProjectOverview', null)
->whereNot('latestTasks', null)
->whereNot('lastSevenDays', null)
->whereNot('latestTeamActivity', null)
->whereNot('dailyTrackedHours', null)
->whereNot('totalWeeklyTime', null)
->whereNot('totalWeeklyBillableTime', null)
->whereNot('totalWeeklyBillableAmount', null)
->whereNot('weeklyHistory', null)
->whereNot('latestTeamActivity', null)
);
}
public function test_showing_dashboard_succeeds_with_less_data_for_user_with_employee_role(): void
{
// Arrange
$organization = Organization::factory()->create();
$user = User::factory()->forCurrentOrganization($organization)->create();
$organization->users()->attach($user, ['role' => Role::Employee->value]);
$this->actingAs($user);
// Act
$response = $this->get('/dashboard');
// Assert
$response->assertSuccessful();
$response->assertInertia(fn (Assert $page) => $page
->has('weeklyProjectOverview')
->has('latestTasks')
->has('lastSevenDays')
->has('latestTeamActivity')
->has('dailyTrackedHours')
->has('totalWeeklyTime')
->has('totalWeeklyBillableTime')
->has('totalWeeklyBillableAmount')
->has('weeklyHistory')
->whereNot('weeklyProjectOverview', null)
->whereNot('latestTasks', null)
->whereNot('lastSevenDays', null)
->where('latestTeamActivity', null)
->whereNot('dailyTrackedHours', null)
->whereNot('totalWeeklyTime', null)
->whereNot('totalWeeklyBillableTime', null)
->whereNot('totalWeeklyBillableAmount', null)
->whereNot('weeklyHistory', null)
);
} }
} }