diff --git a/packages/code-du-travail-frontend/src/search/Search.js b/packages/code-du-travail-frontend/src/search/Search.js
index 2f61fa93d2..ccb2b84ca0 100755
--- a/packages/code-du-travail-frontend/src/search/Search.js
+++ b/packages/code-du-travail-frontend/src/search/Search.js
@@ -42,7 +42,7 @@ class Search extends React.Component {
});
}
if (this.props.router.query.source) {
- const source = this.props.router.query.source;
+ const source = this.props.router.query.source || "";
const excludeSources = getExcludeSources(source);
this.setState({ source, excludeSources });
}
@@ -62,7 +62,7 @@ class Search extends React.Component {
}
this.setState({
query: this.props.router.query.q,
- source: this.props.router.query.source,
+ source: this.props.router.query.source || "",
coord: coord,
excludeSources: getExcludeSources(this.props.router.query.source || "")
});
@@ -100,6 +100,9 @@ class Search extends React.Component {
});
return;
case "source":
+ if (this.state.source === event.target.value) {
+ return;
+ }
this.setState({
source: event.target.value,
excludeSources: getExcludeSources(event.target.value)
diff --git a/packages/code-du-travail-frontend/src/search/__tests__/Search.test.js b/packages/code-du-travail-frontend/src/search/__tests__/Search.test.js
index b68fc696fe..770b8988f6 100644
--- a/packages/code-du-travail-frontend/src/search/__tests__/Search.test.js
+++ b/packages/code-du-travail-frontend/src/search/__tests__/Search.test.js
@@ -35,6 +35,7 @@ describe("", () => {
await waitForElement(() => getAllByRole("option"));
expect(container).toMatchSnapshot();
});
+
it("should not navigate when user change facet if query is empty", () => {
const { getBySelectText } = renderWithMock();
const select = getBySelectText(/Tous contenus/i);
@@ -42,6 +43,14 @@ describe("", () => {
expect(Router.pushRoute).not.toHaveBeenCalled();
});
+ it("should not navigate when user blur source facet", () => {
+ const { getBySelectText } = renderWithMock(, { query: { q } });
+ const select = getBySelectText(/Tous contenus/i);
+ fireEvent.focus(select);
+ fireEvent.blur(select);
+ expect(Router.pushRoute).not.toHaveBeenCalled();
+ });
+
it("should navigate when user change facet if query is filled", () => {
const { getBySelectText, getByLabelText } = renderWithMock();
const input = getByLabelText(/rechercher/i);