|
| 1 | +<?php |
| 2 | + |
| 3 | +use PowerComponents\LivewirePowerGrid\Facades\Filter; |
| 4 | +use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\DishesTable; |
| 5 | + |
| 6 | +use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; |
| 7 | + |
| 8 | +use PowerComponents\LivewirePowerGrid\Themes\{Bootstrap5, Tailwind}; |
| 9 | + |
| 10 | +$component = new class () extends DishesTable { |
| 11 | + public string $tableName = 'filter-date-picker-test'; |
| 12 | + |
| 13 | + public function filters(): array |
| 14 | + { |
| 15 | + return [ |
| 16 | + Filter::datepicker('produced_at'), |
| 17 | + ]; |
| 18 | + } |
| 19 | +}; |
| 20 | + |
| 21 | +it('should dispatch "pg:datePicker-{tableName}" with date format', function (string $component, object $params) { |
| 22 | + $component = livewire($component) |
| 23 | + ->call('setTestThemeClass', $params->theme) |
| 24 | + ->dispatch( |
| 25 | + 'pg:datePicker-filter-date-picker-test', |
| 26 | + selectedDates: ['2024-11-06', '2021-02-02'], |
| 27 | + field: 'produced_at', |
| 28 | + dateStr: '2021-01-01 to 2021-02-02', |
| 29 | + label: 'Produced At', |
| 30 | + type: 'datetime', |
| 31 | + timezone: 'UTC' |
| 32 | + ) |
| 33 | + ->assertSee('Peixada'); |
| 34 | + |
| 35 | + expect($component->filters) |
| 36 | + ->toBe([ |
| 37 | + 'datetime' => [ |
| 38 | + 'produced_at' => [ |
| 39 | + 'start' => 'Fri Jan 01 2021 00:00:00 GMT+0000', |
| 40 | + 'end' => 'Tue Feb 02 2021 23:59:59 GMT+0000', |
| 41 | + 'formatted' => '2021-01-01 to 2021-02-02', |
| 42 | + ], |
| 43 | + ], |
| 44 | + ]); |
| 45 | +})->with('filterComponent'); |
| 46 | + |
| 47 | +it('should filter "pg:datePicker-{tableName}" with date format', function (string $component, object $params) { |
| 48 | + livewire($component) |
| 49 | + ->call('setTestThemeClass', $params->theme) |
| 50 | + ->assertSee('Peixada') |
| 51 | + ->dispatch( |
| 52 | + 'pg:datePicker-filter-date-picker-test', |
| 53 | + selectedDates: ['2021-03-03', '2021-05-05'], |
| 54 | + field: 'produced_at', |
| 55 | + dateStr: '2021-03-03 to 2021-05-05', |
| 56 | + label: 'Produced At', |
| 57 | + type: 'date', |
| 58 | + timezone: 'UTC' |
| 59 | + ) |
| 60 | + ->assertDontSee('Peixada'); |
| 61 | +})->with('filterComponent'); |
| 62 | + |
| 63 | +it('should filter "pg:datePicker-{tableName}" with datetime format', function (string $component, object $params) { |
| 64 | + livewire($component) |
| 65 | + ->call('setTestThemeClass', $params->theme) |
| 66 | + ->assertSee('Peixada', 'Pastel de Nata') |
| 67 | + ->dispatch( |
| 68 | + 'pg:datePicker-filter-date-picker-test', |
| 69 | + selectedDates: ['2021-01-01', '2021-02-02'], |
| 70 | + field: 'produced_at', |
| 71 | + dateStr: '2021-01-01 00:00:00 to 2021-02-02 04:00:00', |
| 72 | + label: 'Produced At', |
| 73 | + type: 'datetime', |
| 74 | + timezone: 'UTC' |
| 75 | + ) |
| 76 | + ->assertSee('Pastel de Nata') |
| 77 | + ->assertDontSee('Peixada'); |
| 78 | +})->with('filterComponent'); |
| 79 | + |
| 80 | +it('should dispatch "pg:datePicker-{tableName}" with datetime format', function (string $component, object $params) { |
| 81 | + $component = livewire($component) |
| 82 | + ->call('setTestThemeClass', $params->theme) |
| 83 | + ->dispatch( |
| 84 | + 'pg:datePicker-filter-date-picker-test', |
| 85 | + selectedDates: ['2024-11-06', '2021-02-02'], |
| 86 | + field: 'produced_at', |
| 87 | + dateStr: '2021-01-01 03:00:00 to 2021-02-02 05:00:00', |
| 88 | + label: 'Produced At', |
| 89 | + type: 'datetime', |
| 90 | + timezone: 'UTC' |
| 91 | + ) |
| 92 | + ->assertSee('Peixada'); |
| 93 | + |
| 94 | + expect($component->filters) |
| 95 | + ->toBe([ |
| 96 | + 'datetime' => [ |
| 97 | + 'produced_at' => [ |
| 98 | + 'start' => 'Fri Jan 01 2021 03:00:00 GMT+0000', |
| 99 | + 'end' => 'Tue Feb 02 2021 05:00:00 GMT+0000', |
| 100 | + 'formatted' => '2021-01-01 03:00:00 to 2021-02-02 05:00:00', |
| 101 | + ], |
| 102 | + ], |
| 103 | + ]); |
| 104 | +})->with('filterComponent'); |
| 105 | + |
| 106 | +dataset('filterComponent', [ |
| 107 | + 'tailwind -> id' => [$component::class, (object) ['theme' => Tailwind::class]], |
| 108 | + 'bootstrap -> id' => [$component::class, (object) ['theme' => Bootstrap5::class]], |
| 109 | +]); |
0 commit comments