Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Livewire/Dashboard/DashboardConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +104,16 @@ public function getCurrentFileProperty(): ?FileRecord
: null;
}

/** @return list<ConverterTarget> */
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');
Expand Down
13 changes: 10 additions & 3 deletions resources/views/livewire/dashboard/dashboard-converter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ class="flex flex-col items-center justify-center gap-4 rounded-[var(--ca-radius-
</div>
</div>

<div class="rounded-[var(--ca-radius-md)] border border-dashed border-[var(--ca-border)] bg-[var(--ca-surface-muted)]/40 px-6 py-8 text-center">
<p class="text-base font-semibold text-[var(--ca-text)]">Choose output format</p>
<p class="mt-1 text-sm text-[var(--ca-muted)]">Target format selection will be added in Phase 7.</p>
<div class="flex flex-col gap-3">
<p class="text-base font-semibold text-[var(--ca-text)]">Convert {{ strtoupper($file->extension) }} to</p>
<div class="flex flex-col gap-2">
@foreach ($this->availableTargets as $target)
<div class="rounded-[var(--ca-radius-md)] border border-[var(--ca-border)] bg-white px-4 py-3">
<span class="text-sm font-semibold text-[var(--ca-text)]">{{ $target->label }}</span>
<p class="text-xs text-[var(--ca-muted)]">{{ $target->description }}</p>
</div>
@endforeach
</div>
</div>
</div>
@endif
Expand Down
34 changes: 34 additions & 0 deletions tests/Feature/Livewire/DashboardConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
8 changes: 4 additions & 4 deletions tests/Feature/Livewire/DashboardConverterUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
Expand All @@ -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 () {
Expand Down