Files
usher-manage-stack/tests/Feature/Admin/MemberNoteInlineUITest.php
gbanyan eba6f60d18 test(02-01): add feature tests for inline note UI
- Test note count badge renders with correct count from withCount
- Test Alpine.js directives present in HTML (noteFormOpen, submitNote, x-model, :disabled)
- Test 備忘錄 column header renders
- Test zero-note members show 0 count
- Test correct note store route URL embedded for each member

All 5 tests pass. No regressions in 7 Phase 1 tests.
2026-02-13 12:33:40 +08:00

101 lines
3.0 KiB
PHP

<?php
namespace Tests\Feature\Admin;
use App\Models\Member;
use App\Models\Note;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class MemberNoteInlineUITest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->artisan('db:seed', ['--class' => 'RoleSeeder']);
}
/** @test */
public function member_list_renders_note_count_badge_for_each_member()
{
$admin = User::factory()->create();
$admin->assignRole('admin');
$member = Member::factory()->create();
// Create 3 notes for this member
Note::factory()->count(3)->forMember($member)->byAuthor($admin)->create();
$response = $this->actingAs($admin)->get(route('admin.members.index'));
$response->assertStatus(200);
// Verify the Alpine.js noteCount is initialized with 3
$response->assertSee('noteCount: 3', false);
// Verify badge rendering element exists
$response->assertSee('x-text="noteCount"', false);
}
/** @test */
public function member_list_renders_inline_note_form_with_alpine_directives()
{
$admin = User::factory()->create();
$admin->assignRole('admin');
Member::factory()->create();
$response = $this->actingAs($admin)->get(route('admin.members.index'));
$response->assertStatus(200);
// Verify Alpine.js form directives are present
$response->assertSee('noteFormOpen', false);
$response->assertSee('@submit.prevent="submitNote()"', false);
$response->assertSee('x-model="noteContent"', false);
$response->assertSee(':disabled="isSubmitting', false);
}
/** @test */
public function member_list_renders_note_column_header()
{
$admin = User::factory()->create();
$admin->assignRole('admin');
$response = $this->actingAs($admin)->get(route('admin.members.index'));
$response->assertStatus(200);
$response->assertSee('備忘錄', false);
}
/** @test */
public function member_with_zero_notes_shows_zero_count()
{
$admin = User::factory()->create();
$admin->assignRole('admin');
Member::factory()->create();
$response = $this->actingAs($admin)->get(route('admin.members.index'));
$response->assertStatus(200);
$response->assertSee('noteCount: 0', false);
}
/** @test */
public function member_list_includes_correct_note_store_route_for_each_member()
{
$admin = User::factory()->create();
$admin->assignRole('admin');
$member = Member::factory()->create();
$response = $this->actingAs($admin)->get(route('admin.members.index'));
$response->assertStatus(200);
// Verify the axios.post URL contains the correct member route
$expectedRoute = route('admin.members.notes.store', $member);
$response->assertSee($expectedRoute, false);
}
}