Skip to content

Commit 18e9f19

Browse files
committed
Updates/tests
1 parent 414f6a2 commit 18e9f19

File tree

7 files changed

+113
-20
lines changed

7 files changed

+113
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
99
### Added
1010

1111
- Added functionality to hide individual filters from popover and slide down views
12+
- Added functionality to hide individual filters from filter pills
13+
- Added functionality to hide individual filters from the active filter count
14+
- Added functionality to say which filters get reset by the clear button
15+
- Added functionality to set filters as secondaryHeader or footer of columns
1216

1317
## [2.6.0] - 2022-05-05
1418

docs/filters/available-methods.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,3 @@ If the filter takes any config options, you can set them with the `config` metho
206206
'max' => '2021-12-31',
207207
])
208208
```
209-
210-
### Hiding filters
211-
212-
If you don't want the filter to be visible in the `ui`, you can use the `hidden` method:
213-
214-
```php
215-
216-
// this filter won't be seen in popover and slide down
217-
SelectFilter::make('Active')
218-
->options([
219-
'' => 'All',
220-
'yes' => 'Yes',
221-
'no' => 'No',
222-
])
223-
->hidden() // hide the filter from popover and slidedown
224-
```

src/Traits/Helpers/FilterHelpers.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function hasFilters(): bool
5858
return $this->getFilters()->count();
5959
}
6060

61-
// TODO: Test
6261
public function hasVisibleFilters(): bool
6362
{
6463
return $this->getFilters()
@@ -124,7 +123,6 @@ public function hasAppliedFiltersWithValues(): bool
124123
return count($this->getAppliedFiltersWithValues());
125124
}
126125

127-
// TODO: Test
128126
public function hasAppliedVisibleFiltersWithValuesThatCanBeCleared(): bool
129127
{
130128
return collect($this->getAppliedFiltersWithValues())

src/Views/Traits/Configuration/FilterConfiguration.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,39 @@ public function setFilterPillValues(array $values): self
4343
return $this;
4444
}
4545

46-
// TODO: Test
46+
/**
47+
* @return $this
48+
*/
4749
public function hiddenFromMenus(): self
4850
{
4951
$this->hiddenFromMenus = true;
5052

5153
return $this;
5254
}
5355

56+
/**
57+
* @return $this
58+
*/
5459
public function hiddenFromPills(): self
5560
{
5661
$this->hiddenFromPills = true;
5762

5863
return $this;
5964
}
6065

66+
/**
67+
* @return $this
68+
*/
6169
public function hiddenFromFilterCount(): self
6270
{
6371
$this->hiddenFromFilterCount = true;
6472

6573
return $this;
6674
}
6775

76+
/**
77+
* @return $this
78+
*/
6879
public function hiddenFromAll(): self
6980
{
7081
$this->hiddenFromMenus = true;
@@ -74,6 +85,9 @@ public function hiddenFromAll(): self
7485
return $this;
7586
}
7687

88+
/**
89+
* @return $this
90+
*/
7791
public function notResetByClearButton(): self
7892
{
7993
$this->resetByClearButton = false;

tests/Views/Traits/Configuration/ColumnConfigurationTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
66
use Rappasoft\LaravelLivewireTables\Views\Column;
7+
use Rappasoft\LaravelLivewireTables\Views\Filter;
78

89
class ColumnConfigurationTest extends TestCase
910
{
@@ -108,4 +109,30 @@ public function can_deselect_column(): void
108109

109110
$this->assertFalse($column->isSelected());
110111
}
112+
113+
/** @test */
114+
public function can_set_secondary_header_as_filter(): void
115+
{
116+
$column = Column::make('Name');
117+
118+
$this->assertFalse($column->hasSecondaryHeader());
119+
120+
$column->secondaryHeader($this->basicTable->getFilterByKey('breed'));
121+
122+
$this->assertTrue($column->hasSecondaryHeader());
123+
$this->assertInstanceOf(Filter::class, $column->getSecondaryHeaderCallback());
124+
}
125+
126+
/** @test */
127+
public function can_set_footer_as_filter(): void
128+
{
129+
$column = Column::make('Name');
130+
131+
$this->assertFalse($column->hasFooter());
132+
133+
$column->footer($this->basicTable->getFilterByKey('breed'));
134+
135+
$this->assertTrue($column->hasFooter());
136+
$this->assertInstanceOf(Filter::class, $column->getFooterCallback());
137+
}
111138
}

tests/Views/Traits/Configuration/FilterConfigurationTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,70 @@ public function filter_pill_values_can_be_set_for_select(): void
6363
$this->assertEquals('Yes', $filter->getFilterPillValue('1'));
6464
$this->assertEquals('Inactive', $filter->getFilterPillValue('0'));
6565
}
66+
67+
/** @test */
68+
public function can_hide_filter_from_menus(): void
69+
{
70+
$filter = SelectFilter::make('Active');
71+
72+
$this->assertFalse($filter->isHiddenFromMenus());
73+
74+
$filter->hiddenFromMenus();
75+
76+
$this->assertTrue($filter->isHiddenFromMenus());
77+
}
78+
79+
/** @test */
80+
public function can_hide_filter_from_pills(): void
81+
{
82+
$filter = SelectFilter::make('Active');
83+
84+
$this->assertFalse($filter->isHiddenFromPills());
85+
86+
$filter->hiddenFromPills();
87+
88+
$this->assertTrue($filter->isHiddenFromPills());
89+
}
90+
91+
/** @test */
92+
public function can_hide_filter_from_filter_count(): void
93+
{
94+
$filter = SelectFilter::make('Active');
95+
96+
$this->assertFalse($filter->isHiddenFromFilterCount());
97+
98+
$filter->hiddenFromFilterCount();
99+
100+
$this->assertTrue($filter->isHiddenFromFilterCount());
101+
}
102+
103+
/** @test */
104+
public function filter_is_not_reset_by_clear_button(): void
105+
{
106+
$filter = SelectFilter::make('Active');
107+
108+
$this->assertTrue($filter->isResetByClearButton());
109+
110+
$filter->notResetByClearButton();
111+
112+
$this->assertFalse($filter->isResetByClearButton());
113+
}
114+
115+
/** @test */
116+
public function can_be_hidden_from_all(): void
117+
{
118+
$filter = SelectFilter::make('Active');
119+
120+
$this->assertFalse($filter->isHiddenFromMenus());
121+
$this->assertFalse($filter->isHiddenFromPills());
122+
$this->assertFalse($filter->isHiddenFromFilterCount());
123+
$this->assertTrue($filter->isResetByClearButton());
124+
125+
$filter->hiddenFromAll();
126+
127+
$this->assertTrue($filter->isHiddenFromMenus());
128+
$this->assertTrue($filter->isHiddenFromPills());
129+
$this->assertTrue($filter->isHiddenFromFilterCount());
130+
$this->assertTrue($filter->isResetByClearButton());
131+
}
66132
}

tests/Views/Traits/Helpers/FilterHelpersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function can_check_filter_config_by_name(): void
138138
}
139139

140140
/** @test */
141-
public function can_check_if_filter_is_hidden(): void
141+
public function can_check_if_filter_is_hidden_from_menus(): void
142142
{
143143
$filter = SelectFilter::make('Active');
144144

0 commit comments

Comments
 (0)