67 lines
3.1 KiB
PHP
67 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\InterestRequest;
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Tests\TestCase;
|
|
|
|
class DashboardTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_guests_are_redirected_to_the_login_page()
|
|
{
|
|
$response = $this->get(route('dashboard'));
|
|
$response->assertRedirect(route('login'));
|
|
}
|
|
|
|
public function test_authenticated_users_can_visit_the_dashboard()
|
|
{
|
|
$user = User::factory()->create();
|
|
$this->actingAs($user);
|
|
|
|
$response = $this->get(route('dashboard'));
|
|
$response->assertOk();
|
|
$response->assertInertia(fn (Assert $page) => $page->component('dashboard')->where('summary', null));
|
|
}
|
|
|
|
public function test_manager_sees_real_counts_and_only_five_recent_requests(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
config(['portal.managers' => [$user->email]]);
|
|
$sector = Sector::create(['name' => 'Energia', 'slug' => 'energia-especifica', 'is_active' => true, 'published_at' => now()]);
|
|
foreach (['published', 'draft', 'archived'] as $status) {
|
|
Opportunity::create(['sector_id' => $sector->id, 'reference' => $status, 'slug' => $status,
|
|
'title' => $status, 'status' => $status, 'published_at' => now()->subMinute()]);
|
|
}
|
|
for ($i = 0; $i < 7; $i++) {
|
|
InterestRequest::create(['reference' => 'IR-TEST-'.$i, 'full_name' => 'Pessoa de teste',
|
|
'email' => 'test@example.invalid', 'investor_type' => 'empresa', 'country' => 'Moçambique',
|
|
'sector_interest' => 'Energia', 'message' => 'Mensagem privada de teste', 'privacy_consent' => true,
|
|
'status' => $i === 0 ? 'closed' : 'received']);
|
|
}
|
|
$this->actingAs($user)->get(route('dashboard'))->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->component('dashboard')->where('summary.requestsByStatus.received', 6)
|
|
->where('summary.requestsByStatus.closed', 1)->where('summary.requestsByStatus.in_review', 0)
|
|
->where('summary.publishedOpportunities', 1)->where('summary.draftOpportunities', 1)
|
|
->where('summary.activeSectors', 1)->has('summary.recentRequests', 5)
|
|
->where('summary.recentRequests.0.reference', 'IR-TEST-6')
|
|
->missing('summary.recentRequests.0.email')->missing('summary.recentRequests.0.message'));
|
|
$this->actingAs(User::factory()->create())->get(route('dashboard'))->assertInertia(fn (Assert $page) => $page->where('summary', null));
|
|
}
|
|
|
|
public function test_empty_manager_dashboard_has_zero_counts(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
config(['portal.managers' => [$user->email]]);
|
|
$this->actingAs($user)->get(route('dashboard'))->assertInertia(fn (Assert $page) => $page
|
|
->where('summary.requestsByStatus.received', 0)->where('summary.publishedOpportunities', 0)
|
|
->where('summary.activeSectors', 0)->has('summary.recentRequests', 0));
|
|
}
|
|
}
|