Skip to content

Commit

Permalink
Change to underscore to match query_string
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Nov 5, 2024
1 parent e0094f2 commit f1dafe1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Http/Livewire/LfDualRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LfDualRangeFilter extends Component

public function mount($defaultMin = null, $defaultMax = null)
{
$this->condition = 'dual-range';
$this->condition = 'dual_range';
$this->selectedMin = $defaultMin ?? $this->min;
$this->selectedMax = $defaultMax ?? $this->max;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Livewire/LivewireCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function filterUpdated($field, $condition, $payload, $command, $modifier)

return;
}
if ($condition === 'dual-range') {
if ($condition === 'dual_range') {
$this->handleDualRangeCondition($field, $payload, $command, $modifier);

return;
Expand Down
45 changes: 21 additions & 24 deletions tests/Feature/LfDualRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function it_enforces_minimum_range_between_handles()
$component = Livewire::test(LfDualRangeFilter::class, [
'field' => 'cabins',
'blueprint' => 'yachts.yachts',
'condition' => 'dual-range',
'condition' => 'dual_range',
'min' => 2,
'max' => 8,
'minRange' => 2,
Expand All @@ -142,15 +142,15 @@ public function it_dispatches_filter_updated_event_when_values_change()
Livewire::test(LfDualRangeFilter::class, [
'field' => 'cabins',
'blueprint' => 'yachts.yachts',
'condition' => 'dual-range',
'condition' => 'dual_range',
'min' => 2,
'max' => 10,
'minRange' => 2,
])
->set('selectedMin', 5)
->assertDispatched('filter-updated',
field: 'cabins',
condition: 'dual-range',
condition: 'dual_range',
payload: ['min' => 5, 'max' => 10],
command: 'replace',
);
Expand All @@ -162,7 +162,7 @@ public function collection_component_handles_dual_range_filter_events()
Livewire::test(LivewireCollection::class, ['params' => ['from' => 'yachts']])
->dispatch('filter-updated',
field: 'cabins',
condition: 'dual-range',
condition: 'dual_range',
payload: ['min' => 5, 'max' => 10],
command: 'replace',
modifier: 'any',
Expand All @@ -173,7 +173,7 @@ public function collection_component_handles_dual_range_filter_events()
])
->dispatch('filter-updated',
field: 'cabins',
condition: 'dual-range',
condition: 'dual_range',
payload: ['min' => 5, 'max' => 8],
command: 'replace',
modifier: 'any',
Expand All @@ -190,7 +190,7 @@ public function collection_component_handles_different_conditions_by_modifier()
Livewire::test(LivewireCollection::class, ['params' => ['from' => 'yachts']])
->dispatch('filter-updated',
field: 'cabins',
condition: 'dual-range',
condition: 'dual_range',
payload: ['min' => 5, 'max' => 10],
command: 'replace',
modifier: 'gt|lt',
Expand All @@ -201,24 +201,21 @@ public function collection_component_handles_different_conditions_by_modifier()
]);
}

// #[Test]
// public function it_loads_preset_params_correctly()
// {
// Livewire::test(LfDualRangeFilter::class, [
// 'field' => 'cabins',
// 'blueprint' => 'yachts.yachts',
// 'condition' => 'between',
// 'min' => 2,
// 'max' => 10,
// 'defaultMin' => 4,
// 'defaultMax' => 8,
// ])
// ->assertSet('selectedMin', 4)
// ->assertSet('selectedMax', 8)
// ->dispatch('preset-params', ['cabins:between' => ['min' => 5, 'max' => 7]])
// ->assertSet('selectedMin', 5)
// ->assertSet('selectedMax', 7);
// }
#[Test]
public function it_loads_preset_params_correctly()
{
Livewire::test(LfDualRangeFilter::class, [
'field' => 'cabins',
'blueprint' => 'yachts.yachts',
'condition' => 'dual_range',
'min' => 2,
'max' => 10,
'minRange' => 2,
])
->dispatch('preset-params', ['cabins:lte' => 5, 'cabins:gte' => 8])
->assertSet('selectedMin', 5)
->assertSet('selectedMax', 8);
}

protected function makeEntry($collection, $slug)
{
Expand Down

0 comments on commit f1dafe1

Please sign in to comment.