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
13 changes: 13 additions & 0 deletions app/Livewire/RecentConversionsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@
use App\Enums\ConversionStatus;
use App\Models\ConversionJob;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
use Livewire\Component;

class RecentConversionsTable extends Component
{
public string $search = '';

public function render(): View
{
$conversions = ConversionJob::query()
->where('user_id', auth()->id())
->with(['sourceFile', 'resultFile'])
->when($this->search !== '', function (Builder $query) {
$search = trim($this->search);

$query->where(function (Builder $query) use ($search) {
$query->where('source_format', 'like', "%{$search}%")
->orWhere('target_format', 'like', "%{$search}%")
->orWhereHas('sourceFile', fn (Builder $q) => $q->where('original_name', 'like', "%{$search}%")
);
});
})
->latest()
->get();

Expand Down
9 changes: 9 additions & 0 deletions resources/views/livewire/recent-conversions-table.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<section>
<h2 class="text-xl font-semibold tracking-tight text-[var(--ca-text)]">Recent Conversions</h2>

<div class="mt-4 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<input
type="search"
wire:model.live.debounce.300ms="search"
placeholder="Search files, formats..."
class="w-full rounded-[var(--ca-radius-md)] border border-[var(--ca-border)] bg-white px-3 py-2 text-sm text-[var(--ca-text)] placeholder-[var(--ca-muted)] focus:outline-none focus:ring-2 focus:ring-[var(--ca-primary)]/30 sm:max-w-xs"
>
</div>

<div class="mt-4">
@if ($conversions->isEmpty())
<div class="flex flex-col items-center justify-center rounded-[var(--ca-radius-lg)] border border-dashed border-[var(--ca-border)] bg-[var(--ca-surface-muted)]/40 px-6 py-12 text-center">
Expand Down
80 changes: 80 additions & 0 deletions tests/Feature/Livewire/RecentConversionsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,86 @@
->assertSee('Upload a file to start converting');
});

it('searches conversions by source file name', function () {
$user = User::factory()->create();

$matchFile = FileRecord::factory()->for($user)->create([
'original_name' => 'marketing-report.png',
]);

$otherFile = FileRecord::factory()->for($user)->create([
'original_name' => 'product-photo.jpg',
]);

ConversionJob::factory()->for($user)->for($matchFile, 'sourceFile')->create();
ConversionJob::factory()->for($user)->for($otherFile, 'sourceFile')->create();

$this->actingAs($user);

Livewire::test(RecentConversionsTable::class)
->set('search', 'marketing')
->assertSee('marketing-report.png')
->assertDontSee('product-photo.jpg');
});

it('searches conversions by source format', function () {
$user = User::factory()->create();

$sourceA = FileRecord::factory()->for($user)->create(['original_name' => 'report.docx']);
$sourceB = FileRecord::factory()->for($user)->create(['original_name' => 'image.bmp']);

ConversionJob::factory()->for($user)->for($sourceA, 'sourceFile')->create([
'source_format' => 'docx',
'target_format' => 'jpg',
]);
ConversionJob::factory()->for($user)->for($sourceB, 'sourceFile')->create([
'source_format' => 'bmp',
'target_format' => 'webp',
]);

$this->actingAs($user);

Livewire::test(RecentConversionsTable::class)
->set('search', 'docx')
->assertSee('DOCX')
->assertDontSee('WEBP');
});

it('searches conversions by target format', function () {
$user = User::factory()->create();

$sourceA = FileRecord::factory()->for($user)->create(['original_name' => 'image.bmp']);
$sourceB = FileRecord::factory()->for($user)->create(['original_name' => 'report.docx']);

ConversionJob::factory()->for($user)->for($sourceA, 'sourceFile')->create([
'source_format' => 'bmp',
'target_format' => 'webp',
]);
ConversionJob::factory()->for($user)->for($sourceB, 'sourceFile')->create([
'source_format' => 'docx',
'target_format' => 'tiff',
]);

$this->actingAs($user);

Livewire::test(RecentConversionsTable::class)
->set('search', 'webp')
->assertSee('WEBP')
->assertDontSee('TIFF');
});

it('shows all conversions when search is empty', function () {
$user = User::factory()->create();

ConversionJob::factory()->count(3)->for($user)->create();

$this->actingAs($user);

Livewire::test(RecentConversionsTable::class)
->set('search', '')
->assertViewHas('conversions', fn ($c) => $c->count() === 3);
});

it('shows download action for completed conversion with result file', function () {
$user = User::factory()->create();

Expand Down