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

Update to React 17 #3388

Merged
merged 2 commits into from
Sep 10, 2021
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
8 changes: 4 additions & 4 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ajv": "^8.6.2",
"axios": "^0.21.4",
"connected-react-router": "^6.9.1",
"enzyme-adapter-react-16": "^1.15.6",
"fast-json-patch": "^3.1.0",
"fstream": "^1.0.12",
"google-protobuf": "^3.17.3",
Expand All @@ -28,12 +27,12 @@
"protobufjs": "^6.11.2",
"qs": "^6.10.1",
"raf": "^3.4.1",
"react": "^16.14.0",
"react": "^17.0.2",
"react-ace": "^9.4.3",
"react-compound-slider": "^3.3.1",
"react-copy-to-clipboard": "^5.0.4",
"react-diff-viewer": "^3.1.1",
"react-dom": "^16.14.0",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
"react-intl": "^5.20.10",
"react-jsonschema-form": "^1.8.1",
Expand All @@ -44,7 +43,7 @@
"react-router-hash-link": "^2.4.3",
"react-switch": "^6.0.0",
"react-tabs": "^3.2.2",
"react-test-renderer": "^16.14.0",
"react-test-renderer": "^17.0.2",
"react-tooltip": "^4.2.21",
"react-transition-group": "^4.4.2",
"redux": "^4.1.1",
Expand Down Expand Up @@ -114,6 +113,7 @@
"@types/react-transition-group": "^4.4.2",
"@types/redux-mock-store": "^1.0.3",
"@types/swagger-ui-react": "^3.35.2",
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.3",
"enzyme": "^3.11.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const useOutsideClick = (callback, refs, enabled = true) => {

useEffect(() => {
if (enabled) {
document.addEventListener("mousedown", memoizeClick);
document.addEventListener("mousedown", memoizeClick, { capture: true });
}
return () => document.removeEventListener("mousedown", memoizeClick);
}, [memoizeClick, enabled]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,27 @@ describe(useOutsideClick, () => {
it("should attach the event to the global event listener", () => {
// Mock addEventListener
const listeners = {};
document.addEventListener = jest.fn((event, cb) => {
listeners[event] = cb;
});
document.addEventListener = jest.fn(
(event, cb) => {
listeners[event] = cb;
},
{ capture: true },
);

mount(<TestComponent />);
expect(Object.keys(listeners).length).toBe(1);
expect(Object.keys(listeners).length).toBe(2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but it has something to do with the changes in the event delegation [1], but I just manually confirmed the hook was working as expected (that is, clicking outside the context switcher and right menu is working as expected), but I performed this change for the tests to pass.

[1] https://reactjs.org/blog/2020/10/20/react-v17.html#changes-to-event-delegation

expect(listeners["mousedown"]).toBeDefined();
});

it("should attach the event only when enabled is true", async () => {
// Mock addEventListener
const listeners = {};
document.addEventListener = jest.fn((event, cb) => {
listeners[event] = cb;
});
document.addEventListener = jest.fn(
(event, cb) => {
listeners[event] = cb;
},
{ capture: true },
);

const wrapper = mount(<TestComponent enabled={false} />);
expect(Object.keys(listeners).length).toBe(0);
Expand Down
7 changes: 4 additions & 3 deletions dashboard/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import Enzyme from "enzyme";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";

import "jest-enzyme";
import { WebSocket } from "mock-socket";
import "raf/polyfill"; // polyfill for requestAnimationFrame

configure({ adapter: new Adapter() });
Enzyme.configure({ adapter: new Adapter() });

// Mock browser specific APIs like localstorage or Websocket
jest.spyOn(window.localStorage.__proto__, "clear");
Expand Down
Loading