diff --git a/app/Filters/Item/FilterCategoryItem.php b/app/Filters/Item/FilterCategoryItem.php new file mode 100644 index 0000000..2a664e0 --- /dev/null +++ b/app/Filters/Item/FilterCategoryItem.php @@ -0,0 +1,22 @@ +filters, 'category')) !== null) { + $builder->where('category_id', '=', $category); + } + + return $next($builder); + } +} diff --git a/app/Filters/Signature/Filters/FilterSignatureCategory.php b/app/Filters/Signature/Filters/FilterSignatureCategory.php index c188287..e749541 100644 --- a/app/Filters/Signature/Filters/FilterSignatureCategory.php +++ b/app/Filters/Signature/Filters/FilterSignatureCategory.php @@ -2,7 +2,7 @@ namespace App\Filters\Signature\Filters; -use App\Filters\Signature\ShareableConstructor; +use App\Filters\Traits\ShareableConstructor; use Closure; use Illuminate\Database\Eloquent\Builder; use Illuminate\Pagination\LengthAwarePaginator; @@ -16,7 +16,7 @@ public function handle(Builder $builder, Closure $next): LengthAwarePaginator if (($category = data_get($this->filters, 'category')) !== null) { $builder->whereHas( 'item', - fn (Builder $builder) => $builder->where('category_id', $category) + fn (Builder $builder) => $builder->where('category_id', '=', $category) ); } diff --git a/app/Filters/Signature/Filters/FilterSignatureDate.php b/app/Filters/Signature/Filters/FilterSignatureDate.php index 43d09aa..8de9d4e 100644 --- a/app/Filters/Signature/Filters/FilterSignatureDate.php +++ b/app/Filters/Signature/Filters/FilterSignatureDate.php @@ -2,7 +2,7 @@ namespace App\Filters\Signature\Filters; -use App\Filters\Signature\ShareableConstructor; +use App\Filters\Traits\ShareableConstructor; use Closure; use Illuminate\Database\Eloquent\Builder; use Illuminate\Pagination\LengthAwarePaginator; diff --git a/app/Filters/Signature/Filters/FilterSignatureItem.php b/app/Filters/Signature/Filters/FilterSignatureItem.php index eecdcc9..811dcf0 100644 --- a/app/Filters/Signature/Filters/FilterSignatureItem.php +++ b/app/Filters/Signature/Filters/FilterSignatureItem.php @@ -2,7 +2,7 @@ namespace App\Filters\Signature\Filters; -use App\Filters\Signature\ShareableConstructor; +use App\Filters\Traits\ShareableConstructor; use Closure; use Illuminate\Database\Eloquent\Builder; use Illuminate\Pagination\LengthAwarePaginator; diff --git a/app/Filters/Signature/ShareableConstructor.php b/app/Filters/Traits/ShareableConstructor.php similarity index 79% rename from app/Filters/Signature/ShareableConstructor.php rename to app/Filters/Traits/ShareableConstructor.php index dbee2a1..a5c493d 100644 --- a/app/Filters/Signature/ShareableConstructor.php +++ b/app/Filters/Traits/ShareableConstructor.php @@ -1,6 +1,6 @@ 'category', + 'frontend::reset' => 'category', + 'frontend::load::more' => 'item', ]; public function render(): View @@ -28,6 +29,15 @@ public function render(): View return view('livewire.frontend.index'); } + public function more(): void + { + $this->limit += 9; + + $this->emitSelf('frontend::load::more', [ + 'category' => $this->category, + ]); + } + public function category(): void { $this->filtered = false; @@ -35,7 +45,7 @@ public function category(): void $this->data = Category::with('items') ->withCount(['items' => fn (Builder $query) => $query->active()]) // @phpstan-ignore-line ->active() - ->limit($this->limit) + ->oldest('name') ->get(); } @@ -53,7 +63,8 @@ public function item(Category $category): void ->search($this->search, 'name') ->with('signatures') ->active() - ->limit($this->limit) + ->take($this->limit) + ->oldest('name') ->get(); } } diff --git a/app/Http/Livewire/Item/Create.php b/app/Http/Livewire/Item/Create.php index 5d084f1..1079f8a 100644 --- a/app/Http/Livewire/Item/Create.php +++ b/app/Http/Livewire/Item/Create.php @@ -17,6 +17,8 @@ class Create extends Component public bool $modal = false; + public bool $description = false; + protected array $validationAttributes = [ 'item.category_id' => 'categoria', 'item.name' => 'nome', @@ -55,7 +57,7 @@ public function rules(): array 'item.category_id' => ['required', Rule::exists('categories', 'id')], 'item.name' => ['required', 'string', 'max:255', Rule::unique('items', 'name')], 'item.description' => ['nullable', 'max:255'], - 'item.reference' => ['nullable', 'string', 'max:255'], + 'item.reference' => ['nullable', 'url'], 'item.quantity' => ['required', 'integer'], 'item.price' => [Rule::when($this->item->is_quotable, ['required', 'numeric', ])], 'item.is_quotable' => ['nullable', 'boolean'], diff --git a/app/Http/Livewire/Item/Filter.php b/app/Http/Livewire/Item/Filter.php new file mode 100644 index 0000000..2889607 --- /dev/null +++ b/app/Http/Livewire/Item/Filter.php @@ -0,0 +1,60 @@ +modal) { + $this->category = null; + } + } + + public function filter(): void + { + $this->modal = false; + $this->count = 1; + + if (!$this->category) { + $this->notification()->error('Ops!', 'Selecione ao menos uma categoria.'); + + return; + } + + $this->emitUp('item::index::filter', [ + 'category' => $this->category, + ]); + + $this->filtered = true; + } + + public function clear(): void + { + $this->category = null; + + $this->filtered = false; + $this->count = 0; + + $this->emitUp('item::index::refresh'); + } +} diff --git a/app/Http/Livewire/Item/Index.php b/app/Http/Livewire/Item/Index.php index 910cbc3..70e97e5 100644 --- a/app/Http/Livewire/Item/Index.php +++ b/app/Http/Livewire/Item/Index.php @@ -2,10 +2,13 @@ namespace App\Http\Livewire\Item; +use App\Filters\Item\FilterCategoryItem; use App\Http\Livewire\Traits\Table; use App\Models\Item; use Illuminate\Contracts\View\View; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Pipeline; use Livewire\Component; class Index extends Component @@ -14,8 +17,11 @@ class Index extends Component protected $listeners = [ 'item::index::refresh' => '$refresh', + 'item::index::filter' => 'filter', ]; + private array $filters = []; + public function render(): View { return view('livewire.item.index', [ @@ -23,18 +29,25 @@ public function render(): View ]); } + public function filter(array $filters): void + { + $this->filters = [...$filters]; + } + private function data(): LengthAwarePaginator { - return Item::with(['category', 'signatures']) - ->withCount('signatures') - ->search( - $this->search, - 'name', - 'description', - 'reference', - ) - ->orderBy($this->sort, $this->direction) - ->paginate($this->quantity); + $items = Item::with(['category', 'signatures']) + ->withCount('signatures'); + + return Pipeline::send($items) + ->through([ + new FilterCategoryItem($this->filters), + ]) + ->then( + fn (Builder $builder) => $builder->search($this->search, 'name', 'description', 'reference') // @phpstan-ignore-line + ->orderBy($this->sort, $this->direction) + ->paginate($this->quantity) + ); } public function update(Item $item): void diff --git a/app/Http/Livewire/Item/Update.php b/app/Http/Livewire/Item/Update.php index 06ce6d2..b52380f 100644 --- a/app/Http/Livewire/Item/Update.php +++ b/app/Http/Livewire/Item/Update.php @@ -17,6 +17,8 @@ class Update extends Component public bool $modal = false; + public bool $description = false; + protected $listeners = [ 'item::update::load' => 'load', ]; @@ -38,7 +40,7 @@ public function rules(): array 'item.category_id' => ['required', Rule::exists('categories', 'id')], 'item.name' => ['required', 'string', 'max:255', Rule::unique('items', 'name')->ignore($this->item->id)], 'item.description' => ['nullable', 'max:255'], - 'item.reference' => ['nullable', 'string', 'max:255'], + 'item.reference' => ['nullable', 'url'], 'item.quantity' => ['required', 'integer'], 'item.price' => [Rule::when($this->item->is_quotable, ['required', 'numeric', ])], 'item.is_quotable' => ['nullable', 'boolean'], diff --git a/app/Models/Item.php b/app/Models/Item.php index 78c6dd9..365d320 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -31,7 +31,6 @@ class Item extends Model protected $casts = [ 'quantity' => 'integer', - 'price' => 'decimal:2', 'is_quotable' => 'boolean', 'is_active' => 'boolean', 'last_signed_at' => 'datetime', diff --git a/app/View/Components/Filter/Item.php b/app/View/Components/Filter/Item.php index 32e58dd..bde126f 100644 --- a/app/View/Components/Filter/Item.php +++ b/app/View/Components/Filter/Item.php @@ -11,6 +11,7 @@ class Item extends Component public function __construct( public string $label = 'Item', public ?string $placeholder = 'Procure um item', + public ?string $category = null, public bool $active = true, ) { // diff --git a/database/migrations/2023_08_21_192725_alter_items_table_change_column_reference_to_text.php b/database/migrations/2023_08_21_192725_alter_items_table_change_column_reference_to_text.php new file mode 100644 index 0000000..b8ad221 --- /dev/null +++ b/database/migrations/2023_08_21_192725_alter_items_table_change_column_reference_to_text.php @@ -0,0 +1,23 @@ + $table->text('reference')->nullable()->change() + ); + } + + public function down(): void + { + Schema::table( + 'items', + fn (Blueprint $table) => $table->string('reference')->nullable()->change() + ); + } +}; diff --git a/package-lock.json b/package-lock.json index b8feb8d..e08f854 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,13 @@ { - "name": "wandes", + "name": "gifts", "lockfileVersion": 3, "requires": true, "packages": { "": { "dependencies": { "@alpinejs/mask": "^3.12.3", - "apexcharts": "^3.41.1" + "apexcharts": "^3.41.1", + "tippy.js": "^6.3.7" }, "devDependencies": { "@tailwindcss/forms": "^0.5.2", @@ -471,6 +472,15 @@ "node": ">= 8" } }, + "node_modules/@popperjs/core": { + "version": "2.11.8", + "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", + "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/popperjs" + } + }, "node_modules/@tailwindcss/forms": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.4.tgz", @@ -1747,6 +1757,14 @@ "node": ">=0.8" } }, + "node_modules/tippy.js": { + "version": "6.3.7", + "resolved": "https://registry.npmjs.org/tippy.js/-/tippy.js-6.3.7.tgz", + "integrity": "sha512-E1d3oP2emgJ9dRQZdf3Kkn0qJgI6ZLpyS5z6ZkY1DF3kaQaBsGZsndEpHwx+eC+tYM41HaSNvNtLx8tU57FzTQ==", + "dependencies": { + "@popperjs/core": "^2.9.0" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", diff --git a/package.json b/package.json index 3ff4441..5e49126 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "dependencies": { "@alpinejs/mask": "^3.12.3", - "apexcharts": "^3.41.1" + "apexcharts": "^3.41.1", + "tippy.js": "^6.3.7" } } diff --git a/resources/css/app.css b/resources/css/app.css index b5c61c9..b7857f7 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -1,3 +1,27 @@ @tailwind base; @tailwind components; @tailwind utilities; + +@layer utilities { + .custom-scrollbar { + scrollbar-width: auto; + } + + .custom-scrollbar::-webkit-scrollbar { + width: 8px; + } + + .custom-scrollbar::-webkit-scrollbar:horizontal { + height: 8px; + } + + .custom-scrollbar::-webkit-scrollbar-track { + background: transparent; + } + + .custom-scrollbar::-webkit-scrollbar-thumb { + background-color: #c9c9c9; + border-radius: 10px; + border: transparent; + } +} diff --git a/resources/js/app.js b/resources/js/app.js index ce29039..aefe17b 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -1,4 +1,5 @@ import './bootstrap'; +import './modules/tooltip'; import Alpine from 'alpinejs'; import ApexCharts from 'apexcharts'; import mask from '@alpinejs/mask' diff --git a/resources/js/modules/tooltip.js b/resources/js/modules/tooltip.js new file mode 100644 index 0000000..44d2897 --- /dev/null +++ b/resources/js/modules/tooltip.js @@ -0,0 +1,13 @@ +import tippy from 'tippy.js'; +import 'tippy.js/dist/tippy.css'; + +document.addEventListener('alpine:init', () => { + Alpine.directive('tooltip', (el, { expression }) => { + tippy(el, { + content: expression, + animation: 'shift-away', + duration: 0, + allowHTML: true, + }) + }) +}); diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 13ceea4..46bfa15 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,5 +1,5 @@ -
+ @csrf
- + {{ __('Acessar') }}
diff --git a/resources/views/components/filter/item.blade.php b/resources/views/components/filter/item.blade.php index 0b36ba0..6585c33 100644 --- a/resources/views/components/filter/item.blade.php +++ b/resources/views/components/filter/item.blade.php @@ -3,7 +3,7 @@ placeholder="{{ $placeholder }}" :async-data="[ 'api' => route('api.search.item'), - 'params' => ['active' => $active], + 'params' => ['category' => $category, 'active' => $active], ]" option-label="name" option-value="id" diff --git a/resources/views/components/layout/header.blade.php b/resources/views/components/layout/header.blade.php index 3491aa9..387bf05 100644 --- a/resources/views/components/layout/header.blade.php +++ b/resources/views/components/layout/header.blade.php @@ -6,6 +6,9 @@ + + +
@if (session()->has('impersonate')) diff --git a/resources/views/components/table/index.blade.php b/resources/views/components/table/index.blade.php index 3be44bb..4379a00 100644 --- a/resources/views/components/table/index.blade.php +++ b/resources/views/components/table/index.blade.php @@ -1,4 +1,4 @@ -
+
{{ $slot }}
diff --git a/resources/views/components/tooltip.blade.php b/resources/views/components/tooltip.blade.php new file mode 100644 index 0000000..1ab61e9 --- /dev/null +++ b/resources/views/components/tooltip.blade.php @@ -0,0 +1 @@ +merge(['class' => 'h-5 w-5 inline-flex text-primary dark:text-red-400']) }} /> diff --git a/resources/views/frontend.blade.php b/resources/views/frontend.blade.php index 3a18538..d4b6e10 100644 --- a/resources/views/frontend.blade.php +++ b/resources/views/frontend.blade.php @@ -15,7 +15,7 @@
-

+

{!! Settings::get('subtitulo') !!}

diff --git a/resources/views/livewire/frontend/index.blade.php b/resources/views/livewire/frontend/index.blade.php index aaa9c66..e1de6a6 100644 --- a/resources/views/livewire/frontend/index.blade.php +++ b/resources/views/livewire/frontend/index.blade.php @@ -5,8 +5,11 @@
+
+ +
@if (!$filtered && $data) -
+
@php /** @var \App\Models\Category $category */ @endphp @forelse ($data as $category)
@@ -34,11 +37,11 @@ @endif @if ($filtered && $data)
-

+

{{ $category->name }}

@if ($category->description) -

{{ $category->description }}

+

{{ $category->description }}

@endif
@@ -47,7 +50,7 @@ type="search" />
-
+
@php /** @var \App\Models\Item $item */ @endphp @forelse ($data as $item)
@@ -55,6 +58,9 @@

{{ $item->name }} + @if ($item->description) + + @endif

{!! trans_choice( @@ -74,7 +80,7 @@

@endforelse
-
+
+ @if ($data->count() > 9) + + @endif
@endif
diff --git a/resources/views/livewire/frontend/signature.blade.php b/resources/views/livewire/frontend/signature.blade.php index 34f7fc6..5e45c51 100644 --- a/resources/views/livewire/frontend/signature.blade.php +++ b/resources/views/livewire/frontend/signature.blade.php @@ -58,6 +58,14 @@ class="w-full" Ao assinar {{ $quantity }} unidade(s) o valor total que deverá ser entregue como presente será o valor de R$ {{ $item->priceQuoted($quantity, false) }} porque este item possui cotas (cotas disponíveis: {{ $available }}). + @if ($item->reference) + + @endif
@endif
diff --git a/resources/views/livewire/item/create.blade.php b/resources/views/livewire/item/create.blade.php index d90d529..625d467 100644 --- a/resources/views/livewire/item/create.blade.php +++ b/resources/views/livewire/item/create.blade.php @@ -9,13 +9,19 @@ -
- -
+ @if (!$description) +

Definir descrição no item

+ @endif + + @if ($description) +
+ +
+ @endif
+
+ + + + @if ($filtered) + + {{ $count }} filtro + + + @endif +
+ +
+ +
+ +
+
+ + +
+
+
+
+
diff --git a/resources/views/livewire/item/index.blade.php b/resources/views/livewire/item/index.blade.php index d1c355a..b1c46d6 100644 --- a/resources/views/livewire/item/index.blade.php +++ b/resources/views/livewire/item/index.blade.php @@ -1,10 +1,13 @@
@php /** @var \App\Models\Item $item */ @endphp
-
+
@if (!($guest = user()->isGuest())) @endif + @if ($items->isNotEmpty()) + + @endif
@if ($items->isNotEmpty()) diff --git a/resources/views/livewire/item/update.blade.php b/resources/views/livewire/item/update.blade.php index 0596681..559d27a 100644 --- a/resources/views/livewire/item/update.blade.php +++ b/resources/views/livewire/item/update.blade.php @@ -7,13 +7,19 @@ @endif -
- -
+ @if (!$description) +

Definir descrição no item

+ @endif + + @if ($item && $item->description || $description) +
+ +
+ @endif
@endif - @if ($item && $item->price) + @if ($item && $item->is_quotable && $item->price > 0)
Valor da Cota: R$ {{ $item->quotePrice(false) }} diff --git a/resources/views/livewire/signature/filter.blade.php b/resources/views/livewire/signature/filter.blade.php index e0c8f9d..ee97fbc 100644 --- a/resources/views/livewire/signature/filter.blade.php +++ b/resources/views/livewire/signature/filter.blade.php @@ -15,15 +15,9 @@ class="cursor-pointer w-4 h-4 text-red-500" />
- isGuest())) @endif - @if ($signatures->isNotEmpty()) - - @endif +
@if ($signatures->isNotEmpty())
diff --git a/tests/Feature/Http/Livewire/Frontend/IndexTest.php b/tests/Feature/Http/Livewire/Frontend/IndexTest.php index 714b9c0..ef31a9e 100644 --- a/tests/Feature/Http/Livewire/Frontend/IndexTest.php +++ b/tests/Feature/Http/Livewire/Frontend/IndexTest.php @@ -63,3 +63,80 @@ ->call('category') ->assertSee('5 itens nesta categoria'); }); + +it('can view item', function () { + $items = Item::factory(2) + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $first = $items->first(); + $last = $items->last(); + + livewire(Index::class) + ->call('item', $category) + ->assertSee([ + $first->name, + $last->name, + ]); +}); + +it('can view description', function () { + $items = Item::factory(2) + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $first = $items->first(); + $last = $items->last(); + + $first->update(['description' => Lorem::text()]); + $last->update(['description' => null]); + + livewire(Index::class) + ->call('item', $category) + ->assertSee($first->description) + ->assertDontSee($last->description); +}); + +it('cal load more', function () { + $items = Item::factory(2) + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $first = $items->first(); + $last = $items->last(); + + $first->update(['name' => 'Abcdef']); + $last->update(['name' => 'Bcdefg']); + + livewire(Index::class) + ->set('limit', 1) + ->call('item', $category) + ->assertSee($first->name) + ->call('more') + ->assertEmitted('frontend::load::more') + ->call('item', $category) + ->assertSee($last->name); +}); + +it('can view in correct order', function () { + $items = Item::factory(2) + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $first = $items->first(); + $last = $items->last(); + + $first->update(['name' => 'Abcdef']); + $last->update(['name' => 'Bcdefg']); + + livewire(Index::class) + ->call('item', $category) + ->assertSeeInOrder([ + $first->name, + $last->name, + ]); +}); diff --git a/tests/Feature/Http/Livewire/Frontend/SignatureTest.php b/tests/Feature/Http/Livewire/Frontend/SignatureTest.php index 5c47418..7eb6e55 100644 --- a/tests/Feature/Http/Livewire/Frontend/SignatureTest.php +++ b/tests/Feature/Http/Livewire/Frontend/SignatureTest.php @@ -102,6 +102,19 @@ Notification::assertSentTo($item, SignatureCreated::class); }); +it('can view item reference', function () { + $item = Item::factory() + ->activated() + ->quotable(1) + ->create(['reference' => $url = fake()->url()]); + + livewire(Signature::class) + ->set('item', $item) + ->set('modal', true) + ->assertSee($url) + ->assertSee('Veja um modelo do item desejado clicando aqui.'); +}); + it('cannot create out of quantity', function () { Notification::fake(); diff --git a/tests/Feature/Http/Livewire/Item/FilterTest.php b/tests/Feature/Http/Livewire/Item/FilterTest.php new file mode 100644 index 0000000..135dbc4 --- /dev/null +++ b/tests/Feature/Http/Livewire/Item/FilterTest.php @@ -0,0 +1,47 @@ + createTestUser()); + +it('can filter category', function () { + Item::factory() + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + livewire(Filter::class) + ->set('category', $category->id) + ->call('filter') + ->assertEmittedUp('item::index::filter', [ + 'category' => $category->id, + ]); +}); + +it('cannot filter using zero filters', function () { + livewire(Filter::class) + ->call('filter') + ->assertDispatchedBrowserEvent('wireui:notification') + ->assertNotEmitted('item::index::filter'); +}); + +it('can view filtered', function () { + $one = Item::factory() + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $two = Item::factory() + ->activated() + ->create(); + + livewire(Index::class) + ->call('filter', [ + 'category' => $category->id, + ]) + ->assertSee($one->name) + ->assertDontSee($two->name); +}); diff --git a/tests/Feature/Http/Livewire/Signature/FilterTest.php b/tests/Feature/Http/Livewire/Signature/FilterTest.php index f494018..428d4a1 100644 --- a/tests/Feature/Http/Livewire/Signature/FilterTest.php +++ b/tests/Feature/Http/Livewire/Signature/FilterTest.php @@ -1,6 +1,6 @@ assertDispatchedBrowserEvent('wireui:notification') ->assertNotEmitted('signature::index::filter'); }); + +it('can view filtered by item', function () { + $one = Item::factory() + ->forCategory() + ->activated() + ->create(); + + $two = Item::factory() + ->activated() + ->create(); + + Signature::factory() + ->for($one) + ->create(); + + Signature::factory() + ->for($two) + ->create(); + + livewire(Index::class) + ->call('filter', [ + 'item' => $one->id, + ]) + ->assertSee($one->name) + ->assertDontSee($two->name); +}); + +it('can view filtered by category', function () { + $one = Item::factory() + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $two = Item::factory() + ->activated() + ->create(); + + Signature::factory() + ->for($one) + ->create(); + + Signature::factory() + ->for($two) + ->create(); + + livewire(Index::class) + ->call('filter', [ + 'category' => $category->id, + ]) + ->assertSee($one->name) + ->assertDontSee($two->name); +}); + +it('can view filtered by dates', function () { + $one = Item::factory() + ->for($category = Category::factory()->activated()->create()) + ->activated() + ->create(); + + $two = Item::factory() + ->activated() + ->create(); + + Signature::factory() + ->for($one) + ->create([ + 'created_at' => now()->subDays(10), + ]); + + Signature::factory() + ->for($two) + ->create([ + 'created_at' => now()->addDays(5), + ]); + + livewire(Index::class) + ->call('filter', [ + 'start' => now()->subDays(10)->format('Y-m-d'), + 'end' => now()->subDays(1)->format('Y-m-d'), + ]) + ->assertSee($one->name) + ->assertDontSee($two->name); +});