91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Tasks\Index as TasksIndex;
|
|
use App\Models\License;
|
|
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' => 'Start Tester', 'email' => 'start@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(),
|
|
]);
|
|
|
|
$this->actingAs($this->user);
|
|
});
|
|
|
|
it('Start button has data-testid + wire:click="startTask(<slug>)"', function () {
|
|
$html = Livewire::test(TasksIndex::class)->html();
|
|
expect($html)->toContain('data-testid="task-start-btn"');
|
|
expect($html)->toContain("wire:click=\"startTask('math-multiplikation-bis-100')\"");
|
|
});
|
|
|
|
it('Repeat button has wire:click="repeatTask(<slug>)" for done tasks', function () {
|
|
$html = Livewire::test(TasksIndex::class)->call('setFilter', 'done')->html();
|
|
expect($html)->toContain('data-testid="task-repeat-btn"');
|
|
expect($html)->toContain('repeatTask(');
|
|
});
|
|
|
|
it('startTask action runs and adds slug to startedKeys', function () {
|
|
Livewire::test(TasksIndex::class)
|
|
->assertSet('startedKeys', [])
|
|
->call('startTask', 'math-multiplikation-bis-100')
|
|
->assertSet('startedKeys', ['math-multiplikation-bis-100']);
|
|
});
|
|
|
|
it('startTask redirects to tasks.run page with slug', function () {
|
|
Livewire::test(TasksIndex::class)
|
|
->call('startTask', 'math-multiplikation-bis-100')
|
|
->assertRedirect(route('tasks.run', ['slug' => 'math-multiplikation-bis-100']));
|
|
});
|
|
|
|
it('Detail (info) button still opens tasks.modals.detail — separate from Start', function () {
|
|
$html = Livewire::test(TasksIndex::class)->html();
|
|
expect($html)->toContain('data-testid="task-detail-btn"');
|
|
expect($html)->toContain('tasks.modals.detail');
|
|
});
|
|
|
|
it('startTask ignores unknown slug', function () {
|
|
Livewire::test(TasksIndex::class)
|
|
->call('startTask', 'non-existent-slug')
|
|
->assertSet('startedKeys', []);
|
|
});
|
|
|
|
it('repeatTask works for done tasks', function () {
|
|
Livewire::test(TasksIndex::class)
|
|
->call('repeatTask', 'deutsch-gedicht-lernen')
|
|
->assertSet('startedKeys', ['deutsch-gedicht-lernen']);
|
|
});
|
|
|
|
it('multiple startTask calls do not duplicate startedKeys', function () {
|
|
Livewire::test(TasksIndex::class)
|
|
->call('startTask', 'math-multiplikation-bis-100')
|
|
->call('startTask', 'math-multiplikation-bis-100')
|
|
->call('startTask', 'math-multiplikation-bis-100')
|
|
->assertSet('startedKeys', ['math-multiplikation-bis-100']);
|
|
});
|