- Subcategories can now be reordered within their category — up/down arrow
  buttons next to "Edytuj" in Admin > Kategorie. The order set there is used
  everywhere a subcategory list is shown (pickers, admin listings, etc.).
This commit is contained in:
2026-07-24 13:58:18 +02:00
parent 313e01ad24
commit 1df697afce
9 changed files with 149 additions and 7 deletions

View File

@@ -45,3 +45,59 @@ test('admin can add a description to a subcategory via the edit dialog', functio
expect($sub->fresh()->description)->toBe('Problemy z połączeniem VPN.');
});
test('admin can reorder subcategories with up/down arrows', function () {
$admin = adminUser();
$category = Category::query()->create(['name' => 'IT-Pomoc']);
$vpn = $category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
$wifi = $category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
$drukarki = $category->subcategories()->create(['name' => 'Drukarki', 'sort_order' => 2]);
Livewire::actingAs($admin)->test(Panel::class)
->call('setTab', 'categories')
->call('moveSubcategoryUp', $drukarki->id)
->assertOk();
expect($category->fresh()->subcategories->pluck('name')->all())
->toBe(['VPN', 'Drukarki', 'WiFi']);
Livewire::actingAs($admin)->test(Panel::class)
->call('setTab', 'categories')
->call('moveSubcategoryDown', $vpn->id)
->assertOk();
expect($category->fresh()->subcategories->pluck('name')->all())
->toBe(['Drukarki', 'VPN', 'WiFi']);
});
test('moving the top subcategory up or the bottom one down is a no-op', function () {
$admin = adminUser();
$category = Category::query()->create(['name' => 'IT-Pomoc']);
$vpn = $category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
$wifi = $category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
Livewire::actingAs($admin)->test(Panel::class)
->call('setTab', 'categories')
->call('moveSubcategoryUp', $vpn->id)
->call('moveSubcategoryDown', $wifi->id)
->assertOk();
expect($category->fresh()->subcategories->pluck('name')->all())
->toBe(['VPN', 'WiFi']);
});
test('a new subcategory is appended to the end of the display order', function () {
$admin = adminUser();
$category = Category::query()->create(['name' => 'IT-Pomoc']);
$category->subcategories()->create(['name' => 'VPN', 'sort_order' => 0]);
$category->subcategories()->create(['name' => 'WiFi', 'sort_order' => 1]);
Livewire::actingAs($admin)->test(Panel::class)
->call('setTab', 'categories')
->set('newSubNames.'.$category->id, 'Drukarki')
->call('addSubcategory', $category->id)
->assertOk();
expect($category->fresh()->subcategories->pluck('name')->all())
->toBe(['VPN', 'WiFi', 'Drukarki']);
});