pp-planer/tests/Feature/TranslatePageTest.php
Thorsten Bus ae42b48753 feat(songs): per-song sections + section editing; fix CCLI import bugs
Refactor lyric storage so each song owns its sections instead of sharing
global labels. Adds song_sections (per song+label) owning song_slides;
labels stay global ProPresenter group tags (name/color/macro). Arrangements
now reference sections, so editing/importing one song no longer corrupts
others that share a label name.

- New: song_sections table + migration with safe backfill; SongSection,
  SongArrangementSection models; SongSectionController (edit/add/delete
  sections, immediate persistence) wired into SongEditModal.
- Refactor writers/readers: CcliImport, ProImport, SongService,
  ArrangementController, SongController, ProExport, PDF, Translation
  (translation reset now section-scoped), CCLI pairing.
- CCLI import fixes: parse SongSelect copy-icon format (German "Vers"
  abbrev + trailing author), fill empty CTS-synced songs instead of
  blocking as duplicate, distinct label colors per section kind,
  import&edit/existing-song open the edit modal (no 404/405), teleport
  paste dialog above assign dialog, preview shows section content,
  correct SongSelect search URL, copy-icon instructions.
- Bookmarklet clicks #generalCopyLyricsButton and captures clipboard;
  serves correct host from request.
- Export: embed key-visual/background under fixed bundle-relative names.
- Tests updated for the section model; new section + isolation coverage.
2026-05-31 14:45:47 +02:00

102 lines
3.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Controllers\TranslationController;
use App\Models\Label;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\SongArrangementLabel;
use App\Models\SongSlide;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Tests\TestCase;
final class TranslatePageTest extends TestCase
{
use RefreshDatabase;
public function test_translate_page_response_contains_ordered_groups_and_slides(): void
{
$song = Song::factory()->create([
'title' => 'Grosser Gott',
]);
$arrangement = SongArrangement::factory()->create([
'song_id' => $song->id,
'name' => 'Normal',
'is_default' => true,
]);
$labelLater = Label::factory()->create([
'name' => 'Refrain',
'color' => '#22c55e',
]);
$labelFirst = Label::factory()->create([
'name' => 'Strophe 1',
'color' => '#0ea5e9',
]);
$sectionFirst = songSectionFor($song, $labelFirst, 1);
$sectionLater = songSectionFor($song, $labelLater, 2);
SongArrangementLabel::factory()->create([
'song_arrangement_id' => $arrangement->id,
'song_section_id' => $sectionFirst->id,
'order' => 1,
]);
SongArrangementLabel::factory()->create([
'song_arrangement_id' => $arrangement->id,
'song_section_id' => $sectionLater->id,
'order' => 2,
]);
SongSlide::factory()->create([
'song_section_id' => $sectionFirst->id,
'order' => 2,
'text_content' => "Zeile A\nZeile B",
'text_content_translated' => "Line A\nLine B",
]);
SongSlide::factory()->create([
'song_section_id' => $sectionFirst->id,
'order' => 1,
'text_content' => "Zeile C\nZeile D\nZeile E",
'text_content_translated' => null,
]);
SongSlide::factory()->create([
'song_section_id' => $sectionLater->id,
'order' => 1,
'text_content' => 'Refrain',
'text_content_translated' => 'Chorus',
]);
$controller = app(TranslationController::class);
$inertiaResponse = $controller->page($song);
$request = Request::create('/songs/'.$song->id.'/translate', 'GET');
$request->headers->set('X-Inertia', 'true');
$response = $inertiaResponse->toResponse($request);
$this->assertInstanceOf(JsonResponse::class, $response);
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
$this->assertSame('Songs/Translate', $payload['component']);
$this->assertSame($song->id, $payload['props']['song']['id']);
$this->assertSame('Grosser Gott', $payload['props']['song']['title']);
$this->assertCount(2, $payload['props']['song']['groups']);
$this->assertSame('Strophe 1', $payload['props']['song']['groups'][0]['name']);
$this->assertSame(1, $payload['props']['song']['groups'][0]['slides'][0]['order']);
$this->assertSame("Zeile C\nZeile D\nZeile E", $payload['props']['song']['groups'][0]['slides'][0]['text_content']);
$this->assertSame(2, $payload['props']['song']['groups'][0]['slides'][1]['order']);
$this->assertSame("Zeile A\nZeile B", $payload['props']['song']['groups'][0]['slides'][1]['text_content']);
$this->assertSame('Refrain', $payload['props']['song']['groups'][1]['name']);
$this->assertSame('Chorus', $payload['props']['song']['groups'][1]['slides'][0]['text_content_translated']);
}
}