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
20 changes: 20 additions & 0 deletions app/Livewire/Dashboard/DashboardConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ public function storeUpload(StoreUploadedFileAction $storeUploadedFile): void
$this->step = 'format';
}

public function goToFormatStep(): void
{
if ($this->currentFile === null) {
$this->currentFileId = null;
$this->step = 'upload';

return;
}

$this->step = 'format';
}

public function ensureValidStep(): void
{
if ($this->step === 'format' && $this->currentFile === null) {
$this->currentFileId = null;
$this->step = 'upload';
}
}

public function replaceFile(): void
{
$this->resetCurrentUpload();
Expand Down
38 changes: 38 additions & 0 deletions tests/Feature/Livewire/DashboardConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use App\Livewire\Dashboard\DashboardConverter;
use App\Models\FileRecord;
use App\Models\User;
use Livewire\Livewire;

it('renders empty upload state', function () {
Expand All @@ -9,3 +11,39 @@
->assertSee('PNG, JPG, WEBP and PDF supported in beta')
->assertSee('Choose file');
});

it('does not allow format step without uploaded file', function () {
Livewire::test(DashboardConverter::class)
->set('step', 'format')
->call('ensureValidStep')
->assertSet('step', 'upload');
});

it('returns to upload step when current file is missing', function () {
Livewire::test(DashboardConverter::class)
->call('goToFormatStep')
->assertSet('step', 'upload')
->assertSee('Drop your file here');
});

it('handles a stale current file id by returning to upload step', function () {
$user = User::factory()->create();

Livewire::actingAs($user)
->test(DashboardConverter::class)
->set('currentFileId', 999999)
->call('goToFormatStep')
->assertSet('step', 'upload')
->assertSet('currentFileId', null);
});

it('opens the format step when a current file exists', 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');
});