create([ 'title' => 'Grosser Gott', ]); $groupLater = SongGroup::factory()->create([ 'song_id' => $song->id, 'name' => 'Refrain', 'color' => '#22c55e', 'order' => 2, ]); $groupFirst = SongGroup::factory()->create([ 'song_id' => $song->id, 'name' => 'Strophe 1', 'color' => '#0ea5e9', 'order' => 1, ]); SongSlide::factory()->create([ 'song_group_id' => $groupFirst->id, 'order' => 2, 'text_content' => "Zeile A\nZeile B", 'text_content_translated' => "Line A\nLine B", ]); SongSlide::factory()->create([ 'song_group_id' => $groupFirst->id, 'order' => 1, 'text_content' => "Zeile C\nZeile D\nZeile E", 'text_content_translated' => null, ]); SongSlide::factory()->create([ 'song_group_id' => $groupLater->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']); } }