Replace all SongGroup/SongArrangementGroup model usages with Label/SongArrangementLabel after the schema migration to global labels. Updates 12 app files and 11 test files: - SongService: createDefaultGroups now finds-or-creates global Labels by name - ArrangementController: validates label_id (labels are global, no song-ownership) - ProImportService: imports groups as Labels (firstOrCreate by name); does not overwrite existing label colors per spec - ProExportService/SongPdfController/TranslationService/etc: traverse via arrangements -> arrangementLabels -> label -> songSlides chain - All test factories and assertions adapted to label-based schema
100 lines
3.5 KiB
PHP
100 lines
3.5 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',
|
|
]);
|
|
|
|
SongArrangementLabel::factory()->create([
|
|
'song_arrangement_id' => $arrangement->id,
|
|
'label_id' => $labelFirst->id,
|
|
'order' => 1,
|
|
]);
|
|
|
|
SongArrangementLabel::factory()->create([
|
|
'song_arrangement_id' => $arrangement->id,
|
|
'label_id' => $labelLater->id,
|
|
'order' => 2,
|
|
]);
|
|
|
|
SongSlide::factory()->create([
|
|
'label_id' => $labelFirst->id,
|
|
'order' => 2,
|
|
'text_content' => "Zeile A\nZeile B",
|
|
'text_content_translated' => "Line A\nLine B",
|
|
]);
|
|
|
|
SongSlide::factory()->create([
|
|
'label_id' => $labelFirst->id,
|
|
'order' => 1,
|
|
'text_content' => "Zeile C\nZeile D\nZeile E",
|
|
'text_content_translated' => null,
|
|
]);
|
|
|
|
SongSlide::factory()->create([
|
|
'label_id' => $labelLater->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']);
|
|
}
|
|
}
|