diff --git a/app/Livewire/Dashboard/DashboardConverter.php b/app/Livewire/Dashboard/DashboardConverter.php index 85c9ade..e5a285b 100644 --- a/app/Livewire/Dashboard/DashboardConverter.php +++ b/app/Livewire/Dashboard/DashboardConverter.php @@ -6,6 +6,8 @@ use App\Exceptions\Files\FileStorageException; use App\Exceptions\Files\UnsupportedFileFormatException; use App\Models\FileRecord; +use App\Support\Converters\ConverterRegistry; +use App\Support\Converters\DTO\ConverterTarget; use App\Support\Files\UploadedFileRules; use Livewire\Component; use Livewire\WithFileUploads; @@ -102,6 +104,16 @@ public function getCurrentFileProperty(): ?FileRecord : null; } + /** @return list */ + public function getAvailableTargetsProperty(): array + { + if (! $this->currentFile) { + return []; + } + + return app(ConverterRegistry::class)->targetsFor($this->currentFile->extension); + } + public function render() { return view('livewire.dashboard.dashboard-converter'); diff --git a/resources/views/livewire/dashboard/dashboard-converter.blade.php b/resources/views/livewire/dashboard/dashboard-converter.blade.php index 666f652..72993d6 100644 --- a/resources/views/livewire/dashboard/dashboard-converter.blade.php +++ b/resources/views/livewire/dashboard/dashboard-converter.blade.php @@ -66,9 +66,16 @@ class="flex flex-col items-center justify-center gap-4 rounded-[var(--ca-radius- -
-

Choose output format

-

Target format selection will be added in Phase 7.

+
+

Convert {{ strtoupper($file->extension) }} to

+
+ @foreach ($this->availableTargets as $target) +
+ {{ $target->label }} +

{{ $target->description }}

+
+ @endforeach +
@endif diff --git a/tests/Feature/Livewire/DashboardConverterTest.php b/tests/Feature/Livewire/DashboardConverterTest.php index 22f67b7..e74434e 100644 --- a/tests/Feature/Livewire/DashboardConverterTest.php +++ b/tests/Feature/Livewire/DashboardConverterTest.php @@ -47,3 +47,37 @@ ->call('goToFormatStep') ->assertSet('step', 'format'); }); + +it('loads available target formats for an uploaded png file', function () { + $user = User::factory()->create(); + $file = FileRecord::factory()->for($user)->create(['extension' => 'png']); + + Livewire::actingAs($user) + ->test(DashboardConverter::class) + ->set('currentFileId', $file->id) + ->call('goToFormatStep') + ->assertSet('step', 'format') + ->assertSee('JPG') + ->assertSee('WEBP') + ->assertSee('PDF'); +}); + +it('loads available target formats for an uploaded jpg file', function () { + $user = User::factory()->create(); + $file = FileRecord::factory()->for($user)->create(['extension' => 'jpg']); + + Livewire::actingAs($user) + ->test(DashboardConverter::class) + ->set('currentFileId', $file->id) + ->call('goToFormatStep') + ->assertSet('step', 'format') + ->assertSee('PNG') + ->assertSee('WEBP') + ->assertSee('PDF'); +}); + +it('returns an empty target list when there is no current file', function () { + $component = Livewire::test(DashboardConverter::class); + + expect($component->instance()->availableTargets)->toBe([]); +}); diff --git a/tests/Feature/Livewire/DashboardConverterUploadTest.php b/tests/Feature/Livewire/DashboardConverterUploadTest.php index 108dfb8..1d5536d 100644 --- a/tests/Feature/Livewire/DashboardConverterUploadTest.php +++ b/tests/Feature/Livewire/DashboardConverterUploadTest.php @@ -18,7 +18,7 @@ ->call('storeUpload') ->assertSet('step', 'format') ->assertSee('sample.png') - ->assertSee('Choose output format'); + ->assertSee('Convert PNG to'); expect(FileRecord::query()->where('original_name', 'sample.png')->exists())->toBeTrue(); }); @@ -68,7 +68,7 @@ ->assertSee('not supported'); }); -it('shows format step placeholder after successful upload', function () { +it('shows target formats after successful upload', function () { Storage::fake('local'); $user = User::factory()->create(); @@ -78,8 +78,8 @@ ->set('upload', UploadedFile::fake()->image('photo.png')) ->call('storeUpload') ->assertSet('step', 'format') - ->assertSee('Choose output format') - ->assertSee('Target format selection will be added in Phase 7'); + ->assertSee('Convert PNG to') + ->assertSee('JPG'); }); it('shows uploaded file summary after upload', function () {