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
9 changes: 8 additions & 1 deletion app/Livewire/Dashboard/DashboardConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class DashboardConverter extends Component

public ?string $selectedTargetFormat = null;

public ?string $selectedConverterKey = null;

public ?string $targetFormatError = null;

/** @var array<int, array<string, mixed>> */
Expand Down Expand Up @@ -134,14 +136,16 @@ public function selectTargetFormat(string $targetFormat): void
);

if ($converter === null) {
$this->selectedTargetFormat = null;
$this->resetTargetSelection();
$this->targetFormatError = 'This conversion is not supported yet.';
$this->step = 'format';

return;
}

$this->selectedTargetFormat = $converter->targetFormat();
$this->selectedConverterKey = $converter->key();
$this->optionsSchema = $converter->optionsSchema();
$this->step = 'settings';
}

Expand Down Expand Up @@ -191,7 +195,10 @@ private function resetCurrentUpload(): void
private function resetTargetSelection(): void
{
$this->selectedTargetFormat = null;
$this->selectedConverterKey = null;
$this->targetFormatError = null;
$this->optionsSchema = [];
$this->options = [];
}

public function getCurrentFileProperty(): ?FileRecord
Expand Down
33 changes: 33 additions & 0 deletions tests/Feature/Livewire/DashboardConverterSettingsStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@
->assertSeeHtml('data-testid="option-field-mystery"');
});

it('loads the converter options schema when a target format is selected', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create([
'extension' => 'png',
'mime_type' => 'image/png',
]);

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', $file->id)
->call('selectTargetFormat', 'jpg')
->assertSet('selectedTargetFormat', 'jpg')
->assertSet('selectedConverterKey', 'png:jpg')
->assertSet('step', 'settings')
->assertSee('Quality')
->assertSee('Background color');
});

it('clears the loaded schema when an unsupported target is selected', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create(['extension' => 'png']);

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', $file->id)
->call('selectTargetFormat', 'jpg')
->assertSet('selectedConverterKey', 'png:jpg')
->call('selectTargetFormat', 'mp3')
->assertSet('selectedConverterKey', null)
->assertSet('optionsSchema', [])
->assertSet('step', 'format');
});

it('shows a controlled fallback for an unsupported field type', function () {
$user = User::factory()->create();
$file = FileRecord::factory()->for($user)->create(['extension' => 'png']);
Expand Down