lernschiff/tests/Feature/Livewire/ModalLayoutTest.php

94 lines
3.5 KiB
PHP

<?php
/**
* Verifies wire-elements modal vendor view override:
* - z-50 (must sit above sidebar z-20)
* - items-center justify-center (always centered)
* - role="dialog" + aria-modal for a11y
*/
use App\Models\License;
use App\Models\Role;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Support\Facades\DB;
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
beforeEach(function () {
$this->seed(\Database\Seeders\RolesSeeder::class);
$tenant = Tenant::firstOrCreate(
['name' => 'Test Schule'],
['type' => 'school', 'active' => true]
);
$this->user = User::withoutGlobalScopes()->create([
'name' => 'Modal Layout Tester', 'email' => 'modallayout@test.example',
'tenant_id' => $tenant->id, 'password' => bcrypt('password'),
]);
$role = Role::where('name', 'child')->first();
DB::table('role_user')->insert([
'user_id' => $this->user->id, 'role_id' => $role->id,
'created_at' => now(), 'updated_at' => now(),
]);
$license = License::withoutGlobalScopes()->create([
'tenant_id' => $tenant->id, 'type' => 'school_flat',
'expires_at' => now()->addYear(), 'active' => true,
]);
DB::table('license_assignments')->insert([
'license_id' => $license->id, 'user_id' => $this->user->id,
'created_at' => now(), 'updated_at' => now(),
]);
});
it('vendor override modal view file exists', function () {
expect(file_exists(base_path('resources/views/vendor/wire-elements-modal/modal.blade.php')))->toBeTrue();
});
it('modal override has z-50 (above sidebar z-20)', function () {
$tpl = file_get_contents(base_path('resources/views/vendor/wire-elements-modal/modal.blade.php'));
expect($tpl)->toContain('z-50');
expect($tpl)->not->toContain('z-10');
});
it('modal override is centered (items-center justify-center)', function () {
$tpl = file_get_contents(base_path('resources/views/vendor/wire-elements-modal/modal.blade.php'));
expect($tpl)->toContain('items-center');
expect($tpl)->toContain('justify-center');
});
it('modal override has role=dialog + aria-modal for accessibility', function () {
$tpl = file_get_contents(base_path('resources/views/vendor/wire-elements-modal/modal.blade.php'));
expect($tpl)->toContain('role="dialog"');
expect($tpl)->toContain('aria-modal="true"');
});
it('modal override uses design tokens (bg-bg-soft, bg-ink-1/60)', function () {
$tpl = file_get_contents(base_path('resources/views/vendor/wire-elements-modal/modal.blade.php'));
expect($tpl)->toContain('bg-bg-soft');
expect($tpl)->toContain('bg-ink-1/60');
});
it('sidebar uses z-20 (modal must be higher than this)', function () {
$tpl = file_get_contents(base_path('resources/views/components/layout/sidebar.blade.php'));
expect($tpl)->toContain('z-20');
});
it('dashboard renders the vendor override (not the default modal view)', function () {
$this->actingAs($this->user);
$response = $this->get(route('dashboard'));
$response->assertOk();
// Override view contains data-testid="modal-root" — default view does not
$response->assertSee('data-testid="modal-root"', false);
});
it('rendered dashboard modal container has z-50 class', function () {
$this->actingAs($this->user);
$html = $this->get(route('dashboard'))->getContent();
expect(preg_match('/data-testid="modal-root"[^>]*\bz-50\b/s', $html) === 1
|| preg_match('/\bz-50\b[^>]*data-testid="modal-root"/s', $html) === 1)->toBeTrue();
});