diff --git a/app/Livewire/Dashboard/DashboardConverter.php b/app/Livewire/Dashboard/DashboardConverter.php index 52ce205..75cfef3 100644 --- a/app/Livewire/Dashboard/DashboardConverter.php +++ b/app/Livewire/Dashboard/DashboardConverter.php @@ -146,9 +146,23 @@ public function selectTargetFormat(string $targetFormat): void $this->selectedTargetFormat = $converter->targetFormat(); $this->selectedConverterKey = $converter->key(); $this->optionsSchema = $converter->optionsSchema(); + $this->initializeOptionsFromSchema(); $this->step = 'settings'; } + private function initializeOptionsFromSchema(): void + { + $this->options = []; + + foreach ($this->optionsSchema as $field) { + if (! isset($field['key']) || ! array_key_exists('default', $field)) { + continue; + } + + $this->options[$field['key']] = $field['default']; + } + } + public function backToUploadSummary(): void { if ($this->currentFile === null) { diff --git a/tests/Feature/Livewire/DashboardConverterSettingsStepTest.php b/tests/Feature/Livewire/DashboardConverterSettingsStepTest.php index 1941bf1..76a1d9e 100644 --- a/tests/Feature/Livewire/DashboardConverterSettingsStepTest.php +++ b/tests/Feature/Livewire/DashboardConverterSettingsStepTest.php @@ -85,6 +85,34 @@ ->assertSee('Background color'); }); +it('initializes default options from the converter schema', 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('options.quality', 'high') + ->assertSet('options.resize', 'original') + ->assertSet('options.background_color', '#ffffff') + ->assertSet('options.remove_metadata', true); +}); + +it('resets options to defaults when switching to a different target format', 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') + ->set('options.quality', 'best') + ->call('selectTargetFormat', 'pdf') + ->assertSet('options.page_size', 'auto') + ->assertSet('options.quality', null); +}); + it('clears the loaded schema when an unsupported target is selected', function () { $user = User::factory()->create(); $file = FileRecord::factory()->for($user)->create(['extension' => 'png']);