-
Notifications
You must be signed in to change notification settings - Fork 43
feat(web): list filters submit once via „Търси" button instead of per-toggle #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiyanaDimitrova
wants to merge
7
commits into
midt-bg:main
Choose a base branch
from
DiyanaDimitrova:feat/filter-rail-submit-once
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33cbf22
feat(web): list filters submit once via „Търси" button instead of per…
DiyanaDimitrova 5a8e70a
fix(web): re-enable pruned „Всички" radios after FilterRail submit (#…
DiyanaDimitrova c7237a2
fix(web): contain filter-rail apply button width on mobile
DiyanaDimitrova 34381c4
style(web): restore trailing newline in layout.css
DiyanaDimitrova c3e1800
fix(web): address #228 review — cache-poisoning + filter-rail a11y
DiyanaDimitrova 402123a
Merge upstream/main into feat/filter-rail-submit-once (#228)
DiyanaDimitrova b0b6c7b
Merge remote-tracking branch 'upstream/main' into feat/filter-rail-su…
DiyanaDimitrova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { | ||
| categorySelectionState, | ||
| filterFormKey, | ||
| preservedParamInputs, | ||
| shouldPruneField, | ||
| } from './filterRail.logic'; | ||
|
|
||
| describe('categorySelectionState', () => { | ||
| it('reports none selected when the intersection is empty', () => { | ||
| const state = categorySelectionState(['a', 'b', 'c'], []); | ||
| expect(state.selectedCount).toBe(0); | ||
| expect(state.someSelected).toBe(false); | ||
| expect(state.allSelected).toBe(false); | ||
| }); | ||
|
|
||
| it('reports a partial (indeterminate) selection', () => { | ||
| const state = categorySelectionState(['a', 'b', 'c'], ['b']); | ||
| expect(state.selectedCount).toBe(1); | ||
| expect(state.someSelected).toBe(true); | ||
| expect(state.allSelected).toBe(false); | ||
| }); | ||
|
|
||
| it('reports all selected when every option is present', () => { | ||
| const state = categorySelectionState(['a', 'b'], ['a', 'b']); | ||
| expect(state.selectedCount).toBe(2); | ||
| expect(state.someSelected).toBe(true); | ||
| expect(state.allSelected).toBe(true); | ||
| }); | ||
|
|
||
| it('ignores selected values outside the category', () => { | ||
| const state = categorySelectionState(['a', 'b'], ['a', 'x', 'y']); | ||
| expect(state.selectedCount).toBe(1); | ||
| expect(state.allSelected).toBe(false); | ||
| expect(state.someSelected).toBe(true); | ||
| }); | ||
|
|
||
| it('is never allSelected for an empty category', () => { | ||
| const state = categorySelectionState([], ['a']); | ||
| expect(state.selectedCount).toBe(0); | ||
| expect(state.allSelected).toBe(false); | ||
| expect(state.someSelected).toBe(false); | ||
| }); | ||
|
|
||
| it('accepts a Set as the selected collection', () => { | ||
| const state = categorySelectionState(['a', 'b'], new Set(['a', 'b'])); | ||
| expect(state.allSelected).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('preservedParamInputs', () => { | ||
| const groupKeys = ['sector', 'procedure', 'year', 'value', 'eu']; | ||
|
|
||
| it('returns nothing when the URL holds only form-owned params', () => { | ||
| const sp = new URLSearchParams('sort=value-desc§or=45&year=2026&cursor=after:x&page=3'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([]); | ||
| }); | ||
|
|
||
| it('preserves the search param `q` so a filter submit cannot erase it (regression #181)', () => { | ||
| const sp = new URLSearchParams('q=път§or=45&sort=value-desc'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([{ key: 'q', value: 'път' }]); | ||
| }); | ||
|
|
||
| it('preserves `bids` so the single-offer view survives a filter submit (regression #181)', () => { | ||
| const sp = new URLSearchParams('bids=1&year=2026&sort=date-desc'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([{ key: 'bids', value: '1' }]); | ||
| }); | ||
|
|
||
| it('preserves the authority/bidder scope params', () => { | ||
| const sp = new URLSearchParams('authority=abc&bidder=xyz§or=45'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([ | ||
| { key: 'authority', value: 'abc' }, | ||
| { key: 'bidder', value: 'xyz' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('never re-emits a group key, sort, cursor or page', () => { | ||
| const sp = new URLSearchParams('sector=45&sort=value-desc&cursor=after:x&page=2&q=x'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([{ key: 'q', value: 'x' }]); | ||
| }); | ||
|
|
||
| it('preserves repeated values of a carried param', () => { | ||
| const sp = new URLSearchParams('bidder=a&bidder=b'); | ||
| expect(preservedParamInputs(sp, groupKeys)).toEqual([ | ||
| { key: 'bidder', value: 'a' }, | ||
| { key: 'bidder', value: 'b' }, | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('shouldPruneField', () => { | ||
| const groupKeys = new Set(['value', 'eu', 'year']); | ||
|
|
||
| it('prunes an empty „Всички" radio (a group-key control)', () => { | ||
| expect(shouldPruneField({ name: 'value', value: '' }, groupKeys)).toBe(true); | ||
| expect(shouldPruneField({ name: 'eu', value: '' }, groupKeys)).toBe(true); | ||
| }); | ||
|
|
||
| it('keeps a group control that carries a value', () => { | ||
| expect(shouldPruneField({ name: 'year', value: '2026' }, groupKeys)).toBe(false); | ||
| }); | ||
|
|
||
| it('never prunes a non-group field, even when empty (hidden sort / preserved q)', () => { | ||
| expect(shouldPruneField({ name: 'sort', value: '' }, groupKeys)).toBe(false); | ||
| expect(shouldPruneField({ name: 'q', value: '' }, groupKeys)).toBe(false); | ||
| }); | ||
|
|
||
| it('never prunes an unnamed control (the submit button)', () => { | ||
| expect(shouldPruneField({ name: '', value: '' }, groupKeys)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('filterFormKey', () => { | ||
| it('changes when a filter param changes (so the form remounts and re-reads defaultChecked)', () => { | ||
| expect(filterFormKey(new URLSearchParams('year=2026'))).not.toBe( | ||
| filterFormKey(new URLSearchParams('year=2025')), | ||
| ); | ||
| }); | ||
|
|
||
| it('is stable across pagination so paging preserves open groups and focus', () => { | ||
| expect(filterFormKey(new URLSearchParams('year=2026&cursor=after:x&page=2'))).toBe( | ||
| filterFormKey(new URLSearchParams('year=2026')), | ||
| ); | ||
| }); | ||
|
|
||
| it('is stable across re-sorting (sort is a view option, not a filter)', () => { | ||
| expect(filterFormKey(new URLSearchParams('year=2026&sort=date-desc'))).toBe( | ||
| filterFormKey(new URLSearchParams('year=2026')), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Достъпност (WCAG 4.1.3):
e.stopPropagation()тук спира change събитието на „Избери всички“ да достигне делегиранияonFormChange(ред 156+), който вдигаdirtyRefи обявява „Има неприложени промени“. Понеже програматичните.checkedзаписвания по децата вonCategoryChangeне пораждат change събития, кликът върху „Избери всички“ променя селекцията, но остава напълно тих за екранния четец — за разлика от превключването на отделен чекбокс.Възможен фикс: маркирайте dirty състоянието директно в
onCategoryChange(напр. извикайте същата логика, която вдигаdirtyRef/setStatus), вместо да разчитате на бълбукането, което тук умишлено спирате.