diff --git a/app/Livewire/Dashboard/DashboardConverter.php b/app/Livewire/Dashboard/DashboardConverter.php index c0ae19d..cb32f95 100644 --- a/app/Livewire/Dashboard/DashboardConverter.php +++ b/app/Livewire/Dashboard/DashboardConverter.php @@ -114,6 +114,31 @@ public function selectTargetFormat(string $targetFormat): void $this->step = 'settings'; } + public function backToUploadSummary(): void + { + if ($this->currentFile === null) { + $this->currentFileId = null; + $this->step = 'upload'; + + return; + } + + $this->resetTargetSelection(); + $this->step = 'upload'; + } + + public function backToFormatStep(): void + { + if ($this->currentFile === null) { + $this->currentFileId = null; + $this->step = 'upload'; + + return; + } + + $this->step = 'format'; + } + public function replaceFile(): void { $this->resetCurrentUpload(); diff --git a/resources/views/livewire/dashboard/dashboard-converter.blade.php b/resources/views/livewire/dashboard/dashboard-converter.blade.php index 94609b5..e0ded51 100644 --- a/resources/views/livewire/dashboard/dashboard-converter.blade.php +++ b/resources/views/livewire/dashboard/dashboard-converter.blade.php @@ -1,7 +1,32 @@
- @if ($step === 'upload') + @if ($step === 'upload' && $this->currentFile) + @php($file = $this->currentFile) +
+
+
+ +
+

{{ $file->original_name }}

+

+ {{ strtoupper($file->extension) }} · + {{ number_format($file->size_bytes / 1024, 1) }} KB +

+
+
+ +
+ Replace + Remove +
+
+ +
+ Choose format +
+
+ @elseif ($step === 'upload')
+
+ ← Back +
+
@@ -108,6 +137,10 @@ class="flex items-start gap-3 rounded-[var(--ca-radius-md)] border border-[var(- @if ($step === 'settings' && $this->currentFile) @php($file = $this->currentFile)
+
+ ← Back +
+

Settings for {{ strtoupper($file->extension) }} to {{ strtoupper($selectedTargetFormat) }} diff --git a/tests/Feature/Livewire/DashboardConverterNavigationTest.php b/tests/Feature/Livewire/DashboardConverterNavigationTest.php new file mode 100644 index 0000000..cbb34c7 --- /dev/null +++ b/tests/Feature/Livewire/DashboardConverterNavigationTest.php @@ -0,0 +1,68 @@ +create(); + $file = FileRecord::factory()->for($user)->create([ + 'extension' => 'png', + 'original_name' => 'image.png', + ]); + + Livewire::actingAs($user) + ->test(DashboardConverter::class) + ->set('currentFileId', $file->id) + ->call('goToFormatStep') + ->call('backToUploadSummary') + ->assertSet('step', 'upload') + ->assertSet('currentFileId', $file->id) + ->assertSee('image.png'); + + expect(FileRecord::query()->whereKey($file->id)->exists())->toBeTrue(); +}); + +it('resets the selected target format when going back to the upload summary', 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') + ->call('selectTargetFormat', 'jpg') + ->assertSet('step', 'settings') + ->call('backToUploadSummary') + ->assertSet('step', 'upload') + ->assertSet('selectedTargetFormat', null); +}); + +it('goes back from the settings placeholder to the format step preserving the 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') + ->call('selectTargetFormat', 'jpg') + ->assertSet('step', 'settings') + ->call('backToFormatStep') + ->assertSet('step', 'format') + ->assertSet('currentFileId', $file->id) + ->assertSee('Convert PNG to'); +}); + +it('returns to upload when navigating back with a missing file', function () { + $user = User::factory()->create(); + + Livewire::actingAs($user) + ->test(DashboardConverter::class) + ->set('currentFileId', 999999) + ->set('step', 'format') + ->call('backToUploadSummary') + ->assertSet('step', 'upload') + ->assertSet('currentFileId', null); +});