65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Settings\Index as SettingsIndex;
|
|
use App\Livewire\Settings\Modals\Delete as SettingsDelete;
|
|
use App\Models\Role;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Livewire\Livewire;
|
|
|
|
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' => 'Delete-Pattern Tester',
|
|
'email' => 'delete@pattern.test',
|
|
'tenant_id' => $tenant->id,
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
$role = Role::where('name', 'school-admin')->first();
|
|
DB::table('role_user')->insert([
|
|
'user_id' => $this->user->id,
|
|
'role_id' => $role->id,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
});
|
|
|
|
it('Settings page delete-trigger uses wire-elements dispatch, not window.confirm', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
// Delete-trigger lives in the 'danger' section — switch to it first
|
|
$html = Livewire::test(SettingsIndex::class)
|
|
->call('setSection', 'danger')
|
|
->html();
|
|
|
|
expect($html)->not->toContain('window.confirm(');
|
|
expect($html)->not->toContain("confirm('");
|
|
expect($html)->not->toContain('confirm("');
|
|
|
|
expect($html)->toContain('openModal');
|
|
expect($html)->toContain('settings.modals.delete');
|
|
expect($html)->toContain('data-testid="delete-trigger"');
|
|
});
|
|
|
|
it('Settings\\Modals\\Delete only deletes when confirmText is exactly LÖSCHEN', function () {
|
|
$this->actingAs($this->user);
|
|
|
|
Livewire::test(SettingsDelete::class)
|
|
->assertSet('confirmText', '')
|
|
->set('confirmText', 'falsch')
|
|
->call('delete')
|
|
->assertSet('confirmText', 'falsch')
|
|
->set('confirmText', 'LÖSCHEN')
|
|
->call('delete');
|
|
});
|