pp-planer/tests/Feature/SongsBlockTest.php
Thorsten Bus b2d230e991 feat: Wave 3 (partial) - Service Edit page + 4 blocks (T14-T18)
T14: Service Edit Page Layout + Routing
- ServiceController::edit() with eager-loaded relationships
- Services/Edit.vue with 4 collapsible accordion blocks
- Route: GET /services/{service}/edit
- Information slides query: global + service-specific with expire_date filtering
- Tests: 2 new (edit page render + auth guard)

T15: Information Block (Slides + Expire Dates)
- InformationBlock.vue with dynamic expire_date filtering
- Shows slides where type='information' AND expire_date >= service.date
- Global visibility across services (not service-specific)
- SlideUploader with showExpireDate=true
- SlideGrid with prominent expire date + inline editing
- Badge showing slide count + 'expiring soon' warning (within 3 days)
- Tests: 7 new (105 assertions)

T16: Moderation Block (Service-Specific)
- ModerationBlock.vue (service-specific slides)
- Filters: type='moderation' AND service_id = current_service
- No expire date field (unlike Information block)
- Service isolation (slides from Service A don't appear in Service B)
- Tests: 5 new (14 assertions)

T17: Sermon Block (Service-Specific)
- SermonBlock.vue (identical to Moderation but type='sermon')
- Service-specific slides, no expire date
- Tests: 5 new (14 assertions)

T18: Songs Block (Matching + Arrangement + Translation)
- SongsBlock.vue with conditional UI (unmatched vs matched states)
- Unmatched: 'Erstellung anfragen' button + searchable select for manual assign
- Matched: ArrangementConfigurator + translation checkbox + preview/download buttons
- ServiceSongController::update() for use_translation and song_arrangement_id
- ArrangementConfigurator emits 'arrangement-selected' for auto-save
- ServiceController::edit() provides songsCatalog for matching search
- Tests: 2 new (45 assertions)

T19: Song PDF (INCOMPLETE - timeout)
- SongPdfController.php created (partial)
- resources/views/pdf/song.blade.php created (partial)
- SongPreviewModal.vue MISSING
- Tests MISSING
- Will be completed in next commit

All tests passing: 124/124 (703 assertions)
Build: ✓ Vite production build successful
German UI: All user-facing text in German with 'Du' form
Dependencies: barryvdh/laravel-dompdf added for PDF generation
2026-03-01 20:09:47 +01:00

141 lines
4.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Service;
use App\Models\ServiceSong;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\SongArrangementGroup;
use App\Models\SongGroup;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
final class SongsBlockTest extends TestCase
{
use RefreshDatabase;
public function test_songs_block_shows_unmatched_song_with_matching_options(): void
{
$user = User::factory()->create();
$service = Service::factory()->create();
Song::factory()->create([
'title' => 'Amazing Grace',
'ccli_id' => '22025',
]);
Song::factory()->create([
'title' => 'How Great Is Our God',
'ccli_id' => '4348399',
]);
ServiceSong::factory()->create([
'service_id' => $service->id,
'order' => 2,
'song_id' => null,
'cts_song_name' => 'Unmatched Song',
'cts_ccli_id' => '123456',
]);
ServiceSong::factory()->create([
'service_id' => $service->id,
'order' => 1,
'song_id' => null,
'cts_song_name' => 'First Song',
'cts_ccli_id' => '654321',
]);
Auth::login($user);
$response = $this->get(route('services.edit', $service));
$response->assertOk();
$response->assertInertia(
fn ($page) => $page
->component('Services/Edit')
->has('serviceSongs', 2)
->where('serviceSongs.0.cts_song_name', 'First Song')
->where('serviceSongs.0.song_id', null)
->where('serviceSongs.1.cts_song_name', 'Unmatched Song')
->where('serviceSongs.1.song_id', null)
->has('songsCatalog')
->where('songsCatalog', fn ($songsCatalog) => collect($songsCatalog)->contains(
fn (array $song) => $song['title'] === 'Amazing Grace' && $song['ccli_id'] === '22025'
))
);
}
public function test_songs_block_provides_matched_song_data_for_arrangement_configurator_and_translation_toggle(): void
{
$user = User::factory()->create();
$service = Service::factory()->create();
$song = Song::factory()->create([
'title' => 'Living Hope',
'ccli_id' => '7106807',
'has_translation' => true,
]);
$verse = SongGroup::factory()->create([
'song_id' => $song->id,
'name' => 'Strophe 1',
'color' => '#3B82F6',
'order' => 1,
]);
$chorus = SongGroup::factory()->create([
'song_id' => $song->id,
'name' => 'Refrain',
'color' => '#10B981',
'order' => 2,
]);
$normal = SongArrangement::factory()->create([
'song_id' => $song->id,
'name' => 'Normal',
'is_default' => true,
]);
SongArrangementGroup::factory()->create([
'song_arrangement_id' => $normal->id,
'song_group_id' => $verse->id,
'order' => 1,
]);
SongArrangementGroup::factory()->create([
'song_arrangement_id' => $normal->id,
'song_group_id' => $chorus->id,
'order' => 2,
]);
ServiceSong::factory()->create([
'service_id' => $service->id,
'order' => 1,
'song_id' => $song->id,
'song_arrangement_id' => $normal->id,
'use_translation' => true,
'cts_song_name' => 'Living Hope',
'cts_ccli_id' => '7106807',
]);
Auth::login($user);
$response = $this->get(route('services.edit', $service));
$response->assertOk();
$response->assertInertia(
fn ($page) => $page
->component('Services/Edit')
->where('serviceSongs.0.song_id', $song->id)
->where('serviceSongs.0.song.has_translation', true)
->where('serviceSongs.0.song.arrangements.0.name', 'Normal')
->where('serviceSongs.0.song.arrangements.0.groups.0.name', 'Strophe 1')
->where('serviceSongs.0.song.groups.0.name', 'Strophe 1')
->where('serviceSongs.0.song_arrangement_id', $normal->id)
);
}
}