Skip to content
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

Fix filter accordion URL update regression. #1032

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ const MachineListControls = ({
// Handle setting the URL and filter in state whenever search text changes.
// Filtering function is debounced to prevent excessive repaints.
useEffect(() => {
const updateURL = () => {
const filters = getCurrentFilters(searchText);
history.push({ search: filtersToQueryString(filters) });
};

if (debouncing) {
intervalRef.current = setTimeout(() => {
setFilter(searchText);
const filters = getCurrentFilters(searchText);
history.push({ search: filtersToQueryString(filters) });
updateURL();
setDebouncing(false);
}, DEBOUNCE_INTERVAL);
} else {
setFilter(searchText);
updateURL();
}
return () => clearTimeout(intervalRef.current);
}, [debouncing, history, searchText, setFilter]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ describe("MachineListControls", () => {
expect(location.search).toBe("?status=new");
});

it("changes the URL when the filter accordion changes", () => {
let location;
const store = mockStore(initialState);
const wrapper = mount(
<Provider store={store}>
<MemoryRouter
initialEntries={[
{ pathname: "/machines", search: "?q=test+search", key: "testKey" },
]}
>
<MachineListControls
filter=""
grouping="none"
setFilter={jest.fn()}
setGrouping={jest.fn()}
setHiddenGroups={jest.fn()}
/>
<Route
path="*"
render={(props) => {
location = props.location;
return null;
}}
/>
</MemoryRouter>
</Provider>
);
act(() => {
wrapper.find("FilterAccordion").props().setSearchText("status:new");
});
wrapper.update();
expect(location.search).toBe("?status=new");
});

it("displays a spinner while debouncing search box input", () => {
const store = mockStore(initialState);
const wrapper = mount(
Expand Down