From bd743e2f4dde378f9577be7cae492d7d54a47cb1 Mon Sep 17 00:00:00 2001 From: larrywhitefie1 Date: Mon, 1 Jul 2019 11:10:36 -0700 Subject: [PATCH] Refactor Tooltip into a function component (#355) ## This change includes: - Refactoring Tooltip to be a function component, using hooks for state and effects - Remove the intermediary EscapableTooltip (Fixes #354) - Update all the unit tests to avoid using `setState()` and `state()` in favour of simulating clicks and asserting the DOM directly. This is compatible with hooks, and is a better design of black-box testing - Split out server tests and run them in Jest's server environment - Upgrade Enzyme (only a minor version bump) to support new Hooks testing features (see https://github.com/airbnb/enzyme/issues/2073) --- .eslintrc.js | 2 +- package.json | 4 +- packages/thumbprint-react/CHANGELOG.md | 1 + .../Tooltip/__snapshots__/test.jsx.snap | 863 +++++++--------- .../components/Tooltip/index.jsx | 330 +++--- .../components/Tooltip/server.test.jsx | 40 + .../components/Tooltip/test.jsx | 971 +++++++++--------- yarn.lock | 35 +- 8 files changed, 1076 insertions(+), 1170 deletions(-) create mode 100644 packages/thumbprint-react/components/Tooltip/server.test.jsx diff --git a/.eslintrc.js b/.eslintrc.js index 4fb03ca..d13271e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,7 +38,7 @@ module.exports = { // Since this code must run in IE11, it has stricter constraints than other parts of // this repo. files: ['packages/thumbprint-react/**/*'], - excludedFiles: ['test.jsx', '*.config.js'], + excludedFiles: ['*test.jsx', '*.config.js'], rules: { // Check for uses of browser/DOM APIs that are not available in our supported browsers. 'compat/compat': 'error', diff --git a/package.json b/package.json index b695e5f..dae4cfc 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "babel-jest": "^24.0.0", "babel-plugin-dynamic-import-node": "^2.2.0", "babel-plugin-external-helpers": "^6.22.0", - "enzyme": "^3.9.0", - "enzyme-adapter-react-16": "^1.12.1", + "enzyme": "^3.10.0", + "enzyme-adapter-react-16": "^1.14.0", "enzyme-to-json": "^3.3.4", "eslint": "^5.9.0", "eslint-config-airbnb": "^17.1.0", diff --git a/packages/thumbprint-react/CHANGELOG.md b/packages/thumbprint-react/CHANGELOG.md index b80cf7b..36d39f8 100644 --- a/packages/thumbprint-react/CHANGELOG.md +++ b/packages/thumbprint-react/CHANGELOG.md @@ -13,6 +13,7 @@ - [Patch] Refactor ModalCurtain to be a function component and use hooks. - [Patch] Refactor Tooltip to use the new hooks. - [Patch] Refactor Popover to use the new hooks. +- [Patch] Refactor Tooltip to be a functional component and update its tests. ### Fixed diff --git a/packages/thumbprint-react/components/Tooltip/__snapshots__/test.jsx.snap b/packages/thumbprint-react/components/Tooltip/__snapshots__/test.jsx.snap index 4cf9171..9301eec 100644 --- a/packages/thumbprint-react/components/Tooltip/__snapshots__/test.jsx.snap +++ b/packages/thumbprint-react/components/Tooltip/__snapshots__/test.jsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`adds \`zIndex\` 1`] = ` +exports[`Tooltip adds \`zIndex\` 1`] = ` - - - + +