Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27d83f9bd0 |
No files matched your search
@@ -309,19 +309,6 @@ test('school type and gender switch straight to another value', async ({ page })
|
|||||||
* School type offers six groups a parent recognises, and Faith sits beside it.
|
* School type offers six groups a parent recognises, and Faith sits beside it.
|
||||||
* Data-invariant: asserts what every returned school is, never how many.
|
* Data-invariant: asserts what every returned school is, never how many.
|
||||||
*/
|
*/
|
||||||
// Clear all once dropped the search with the filters, which sent desktop back
|
|
||||||
// to the home page instead of to the unfiltered results.
|
|
||||||
test('Clear all removes the filters and keeps the search', async ({ page }) => {
|
|
||||||
await page.goto('/?search=school&phase=primary');
|
|
||||||
const row = page.getByRole('group', { name: 'Filters', exact: true });
|
|
||||||
await expect(schoolLinks(page).first()).toBeVisible({ timeout: 15_000 });
|
|
||||||
await row.getByRole('button', { name: 'Clear all', exact: true }).click();
|
|
||||||
await expect(page).not.toHaveURL(/[?&]phase=/);
|
|
||||||
await expect(page).toHaveURL(/[?&]search=school(&|$)/);
|
|
||||||
await expect(schoolLinks(page).first()).toBeVisible();
|
|
||||||
await expect(row.getByRole('button', { name: 'Clear all', exact: true })).toHaveCount(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('school type groups and the faith filter narrow to what they name', async ({ page }) => {
|
test('school type groups and the faith filter narrow to what they name', async ({ page }) => {
|
||||||
await page.goto('/?search=school');
|
await page.goto('/?search=school');
|
||||||
const type = page.getByRole('combobox', { name: 'School type', exact: true });
|
const type = page.getByRole('combobox', { name: 'School type', exact: true });
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { act, fireEvent, render, screen, within } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { HomeView } from '@/components/HomeView';
|
import { HomeView } from '@/components/HomeView';
|
||||||
import { FilterBar } from '@/components/FilterBar';
|
import { FilterBar } from '@/components/FilterBar';
|
||||||
import { fetchSchools } from '@/lib/api';
|
import { fetchSchools } from '@/lib/api';
|
||||||
@@ -175,24 +175,3 @@ describe('the results list', () => {
|
|||||||
expect(screen.queryByText('Search: southmead')).not.toBeInTheDocument();
|
expect(screen.queryByText('Search: southmead')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('the desktop Clear all', () => {
|
|
||||||
const row = () => screen.getByRole('group', { name: 'Filters' });
|
|
||||||
|
|
||||||
it('removes the filters and keeps the search, rather than going home', () => {
|
|
||||||
params = new URLSearchParams('postcode=SW196AR&radius=3&phase=primary&school_type=council&local_authority=Wandsworth');
|
|
||||||
render(<FilterBar filters={filters} />);
|
|
||||||
fireEvent.click(within(row()).getByRole('button', { name: 'Clear all' }));
|
|
||||||
const pushed = push.mock.calls.at(-1)![0] as string;
|
|
||||||
const next = new URLSearchParams(pushed.split('?')[1]);
|
|
||||||
expect(next.get('postcode')).toBe('SW196AR');
|
|
||||||
expect(next.get('radius')).toBe('3');
|
|
||||||
for (const key of ['phase', 'school_type', 'local_authority']) expect(next.get(key)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is not offered when only a search is applied', () => {
|
|
||||||
params = new URLSearchParams('search=southmead');
|
|
||||||
render(<FilterBar filters={filters} />);
|
|
||||||
expect(within(row()).queryByRole('button', { name: /^Clear/ })).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -377,13 +377,31 @@ export function FilterBar({
|
|||||||
updateURL({ ...cleared, [key]: value });
|
updateURL({ ...cleared, [key]: value });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Every filter at once, keeping the search and its distance. The search is
|
// Every filter at once, keeping the search and its distance: what "Clear
|
||||||
// what the results answer, not a filter on them: clearing it too used to
|
// all" means beside the applied filters, where the search is not one of them.
|
||||||
// send desktop back to the home page.
|
|
||||||
const handleClearFilterValues = () => {
|
const handleClearFilterValues = () => {
|
||||||
updateURL(Object.fromEntries(FILTER_KEYS.map((k) => [k, ""])));
|
updateURL(Object.fromEntries(FILTER_KEYS.map((k) => [k, ""])));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClearFilters = () => {
|
||||||
|
setOmniValue("");
|
||||||
|
pendingQueryRef.current = "";
|
||||||
|
startTransition(() => {
|
||||||
|
router.push(pathname);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasActiveFilters =
|
||||||
|
currentSearch ||
|
||||||
|
currentLA ||
|
||||||
|
currentType ||
|
||||||
|
currentFaith ||
|
||||||
|
currentPhase ||
|
||||||
|
currentPostcode ||
|
||||||
|
currentGender ||
|
||||||
|
currentAdmissionsPolicy ||
|
||||||
|
currentHasSixthForm;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A filter's options come from the full lists, not from the results: the
|
* A filter's options come from the full lists, not from the results: the
|
||||||
* results have already been narrowed by that filter, so scoping to them
|
* results have already been narrowed by that filter, so scoping to them
|
||||||
@@ -826,14 +844,14 @@ export function FilterBar({
|
|||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{appliedCount > 0 && (
|
{hasActiveFilters && (
|
||||||
<button
|
<button
|
||||||
onClick={handleClearFilterValues}
|
onClick={handleClearFilters}
|
||||||
className={`btn btn-tertiary ${styles.clearButton}`}
|
className={`btn btn-tertiary ${styles.clearButton}`}
|
||||||
type="button"
|
type="button"
|
||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
>
|
>
|
||||||
Clear all
|
Clear
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -79,7 +79,11 @@
|
|||||||
font-family: var(--font-display);
|
font-family: var(--font-display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 44px, the MOBILE.md touch-target minimum: the 24px icon and its padding
|
||||||
|
came to 40, and the phone filter sheet journey caught it. */
|
||||||
.closeButton {
|
.closeButton {
|
||||||
|
min-width: 2.75rem;
|
||||||
|
min-height: 2.75rem;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border: none;
|
border: none;
|
||||||
|
|||||||
Reference in new issue
Block a user