Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afonic committed Jan 26, 2025
1 parent ec1f2ab commit 590256b
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/Feature/LfCheckboxFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,19 @@ public function it_clears_the_value_when_clear_option_is_fired()
->assertSet('selected', []);
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfCheckboxFilter::class, ['field' => 'item_options', 'blueprint' => 'pages.pages', 'condition' => 'is'])
->set('selected', ['option1', 'option2'])
->dispatch('clear-all-filters')
->assertSet('selected', [])
->assertDispatched('clear-filter',
field: 'item_options',
condition: 'is'
);
}

/** @test */
public function it_can_reorder_term_filter_values_by_slug()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/LfDateFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public function it_clears_the_value_when_clear_option_is_fired()
->assertSet('selected', '');
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfDateFilter::class, ['field' => 'item_from', 'collection' => 'pages', 'blueprint' => 'pages.pages', 'condition' => 'is_after'])
->set('selected', '2024-03-01')
->dispatch('clear-all-filters')
->assertSet('selected', '')
->assertDispatched('clear-filter',
field: 'item_from',
condition: 'is_after'
);
}

/** @test */
public function it_loads_a_param_that_is_preset()
{
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/LfDualRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ public function it_clears_a_filter_using_the_clear_option_event()
);
}

#[Test]
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfDualRangeFilter::class, [
'field' => 'cabins',
'blueprint' => 'yachts.yachts',
'condition' => 'dual_range',
'min' => 2,
'max' => 10,
'minRange' => 2,
])
->set('selectedMin', 5)
->dispatch('clear-all-filters')
->assertSet('selectedMin', 2)
->assertDispatched('clear-filter',
field: 'cabins',
condition: 'dual_range'
);
}

#[Test]
public function collection_component_handles_different_conditions_by_modifier()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/LfRadioFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ public function it_clears_the_value_when_clear_option_is_fired()
->assertSet('selected', '');
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfRadioFilter::class, ['field' => 'item_options', 'blueprint' => 'pages.pages', 'condition' => 'is'])
->set('selected', 'option1')
->dispatch('clear-all-filters')
->assertSet('selected', '')
->assertDispatched('clear-filter',
field: 'item_options',
condition: 'is'
);
}

protected function makeEntry($collection, $slug)
{
return EntryFactory::id($slug)->collection($collection)->slug($slug)->make();
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/LfRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ public function it_can_be_reset_using_the_clear_option_event()
);
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfRangeFilter::class, [
'field' => 'max_items',
'blueprint' => 'pages.pages',
'condition' => 'gte',
'min' => 1,
'max' => 4,
'default' => 2,
])
->set('selected', 3)
->dispatch('clear-all-filters')
->assertSet('selected', 2)
->assertDispatched('clear-filter',
field: 'max_items',
condition: 'gte'
);
}

/** @test */
public function it_loads_a_param_that_is_preset()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/LfSelectFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ public function it_clears_the_value_when_clear_option_is_fired()
->assertSet('selected', '');
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfSelectFilter::class, ['field' => 'item_options', 'collection' => 'pages', 'blueprint' => 'pages.pages', 'condition' => 'is'])
->set('selected', 'option1')
->dispatch('clear-all-filters')
->assertSet('selected', '')
->assertDispatched('clear-filter',
field: 'item_options',
condition: 'is'
);
}

protected function makeEntry($collection, $slug)
{
return EntryFactory::id($slug)->collection($collection)->slug($slug)->make();
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/LfTextFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ public function it_clears_the_value_when_clear_option_is_fired()
->assertSet('selected', '');
}

/** @test */
public function it_clears_the_value_when_clear_all_filters_event_is_fired()
{
Livewire::test(LfTextFilter::class, ['field' => 'item_options', 'collection' => 'pages', 'blueprint' => 'pages.pages', 'condition' => 'is'])
->set('selected', 'option1')
->dispatch('clear-all-filters')
->assertSet('selected', '')
->assertDispatched('clear-filter',
field: 'item_options',
condition: 'is'
);
}

protected function makeEntry($collection, $slug)
{
return EntryFactory::id($slug)->collection($collection)->slug($slug)->make();
Expand Down

0 comments on commit 590256b

Please sign in to comment.