122 lines
3.4 KiB
PHP
122 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Datatable\Studio\Finance\ExpensesTable;
|
|
use App\Models\Employee;
|
|
use App\Models\Expense;
|
|
use App\Models\Outlet;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
// Setup Permissions if needed, though view might not need them strictly for data loading,
|
|
// but actions column does check permissions
|
|
$this->user = User::factory()->has(Employee::factory(), 'employee')->create();
|
|
$this->outlet = Outlet::factory()->create();
|
|
$this->user->outlets()->attach($this->outlet);
|
|
|
|
// Give permissions to view actions
|
|
// actions column checks: update expense, delete expense, or own data
|
|
// So for own data, no perm needed.
|
|
});
|
|
|
|
it('renders successfully', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->assertStatus(200);
|
|
});
|
|
|
|
it('shows expenses from user outlets', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'outlet_id' => $this->outlet->id,
|
|
'description' => 'My Expense',
|
|
'amount' => 50000,
|
|
]);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->assertSee('My Expense')
|
|
->assertSee('50.000'); // Assuming currency formatting adds dot for thousands (ID)
|
|
});
|
|
|
|
it('does not show expenses from other outlets', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
$otherOutlet = Outlet::factory()->create();
|
|
$otherUser = User::factory()->has(Employee::factory(), 'employee')->create();
|
|
$otherUser->outlets()->attach($otherOutlet);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $otherUser->id,
|
|
'outlet_id' => $otherOutlet->id,
|
|
'description' => 'Other Expense',
|
|
'amount' => 100000,
|
|
]);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->assertDontSee('Other Expense');
|
|
});
|
|
|
|
it('can search by description', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'outlet_id' => $this->outlet->id,
|
|
'description' => 'UniqueTerm',
|
|
'amount' => 12345,
|
|
]);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'outlet_id' => $this->outlet->id,
|
|
'description' => 'AnotherItem',
|
|
'amount' => 67890,
|
|
]);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->set('search', 'UniqueTerm') // Standard search property
|
|
->assertSee('UniqueTerm')
|
|
->assertDontSee('AnotherItem');
|
|
});
|
|
|
|
it('can search by amount', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'outlet_id' => $this->outlet->id,
|
|
'description' => 'Exp1',
|
|
'amount' => 8888,
|
|
]);
|
|
|
|
Expense::factory()->create([
|
|
'user_id' => $this->user->id,
|
|
'outlet_id' => $this->outlet->id,
|
|
'description' => 'Exp2',
|
|
'amount' => 9999,
|
|
]);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->set('search', '8888')
|
|
->assertSee('Exp1')
|
|
->assertDontSee('Exp2');
|
|
});
|
|
|
|
it('renders columns correctly', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Livewire::test(ExpensesTable::class)
|
|
->assertSee('Pegawai')
|
|
->assertSee('Keterangan')
|
|
->assertSee('Jumlah')
|
|
->assertSee('Outlet')
|
|
->assertSee('Tanggal')
|
|
->assertSee('Aksi');
|
|
});
|