|
65 | 65 | expect(sharp()->context()->globalFilterValue('test'))->toEqual('two'); |
66 | 66 | }); |
67 | 67 |
|
68 | | -// TODO test multiple filters |
| 68 | +it('redirects to route with correct filterKeys when missing and multiple global filters are defined', function () { |
| 69 | + fakeGlobalFilter('test1'); |
| 70 | + fakeGlobalFilter('test2'); |
69 | 71 |
|
70 | | -function fakeGlobalFilter(): void |
| 72 | + $this->get('/sharp/s-list/person') |
| 73 | + ->assertRedirect('/sharp/two~two/s-list/person'); |
| 74 | + |
| 75 | + $this->post(route('code16.sharp.filters.update', 'test1'), ['value' => 'one']); |
| 76 | + $this->post(route('code16.sharp.filters.update', 'test2'), ['value' => 'three']); |
| 77 | + |
| 78 | + $this->get('/sharp/s-list/person/s-show/person/1') |
| 79 | + ->assertRedirect('/sharp/one~three/s-list/person/s-show/person/1'); |
| 80 | +}); |
| 81 | + |
| 82 | +it('sets the current multiple filterKeys according to the URL', function () { |
| 83 | + fakeGlobalFilter('test1'); |
| 84 | + fakeGlobalFilter('test2'); |
| 85 | + |
| 86 | + $this->post(route('code16.sharp.filters.update', 'test1'), ['value' => 'three']); |
| 87 | + $this->post(route('code16.sharp.filters.update', 'test2'), ['value' => 'three']); |
| 88 | + $this->get('/sharp/one~two/s-list/person/s-show/person/1') |
| 89 | + ->assertOk(); |
| 90 | + |
| 91 | + expect(sharp()->context()->globalFilterValue('test1'))->toEqual('one'); |
| 92 | + expect(sharp()->context()->globalFilterValue('test2'))->toEqual('two'); |
| 93 | +}); |
| 94 | + |
| 95 | +function fakeGlobalFilter(string $key = 'test'): void |
71 | 96 | { |
72 | 97 | sharp()->config()->addGlobalFilter( |
73 | | - new class() extends GlobalRequiredFilter |
| 98 | + new class($key) extends GlobalRequiredFilter |
74 | 99 | { |
| 100 | + public function __construct(private string $key) {} |
| 101 | + |
75 | 102 | public function buildFilterConfig(): void |
76 | 103 | { |
77 | | - $this->configureKey('test'); |
| 104 | + $this->configureKey($this->key); |
78 | 105 | } |
79 | 106 |
|
80 | 107 | public function values(): array |
|
0 commit comments