-
Notifications
You must be signed in to change notification settings - Fork 69
Adding ErrorBoundary over Graph #1585
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
base: master
Are you sure you want to change the base?
Adding ErrorBoundary over Graph #1585
Conversation
Pull Request Test Coverage Report for Build b735c2dd-d113-4bb4-aaf5-be6f8ceeb9d3Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was only able to write one test on this file that gets the Graph to fail (and not one where the graph does not fail) as it kept on throwing errors for tests in js/components/generate/__tests__/generate.test.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I don't think you should mock the import of Graph
. Instead, you can mock a Graph
method like fetchData
. Also, do it within a test case rather than globally; this should allow you to implement more test cases.
CHANGELOG.md
Outdated
@@ -8,6 +8,7 @@ | |||
|
|||
- Updated the Zoom In/Zoom Out buttons on the graph page to Awesome Icons from +/- | |||
- Updated the export button on the graph and grid pages to Awesome Icons; also added highlight effect and tooltip popup on hover | |||
- Added the React ErrorBoundary library and implemented an ErrorBoundary for the Graph Component in the Container and `js/components/draw/main.js` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just say "for the Graph component" (note lowercase "c") and don't need to include the part after that
js/components/draw/main.js
Outdated
import { ErrorBoundary } from "react-error-boundary" | ||
import GraphFallback from "../graph/GraphFallback" | ||
|
||
function sendEmail() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is unused
js/components/graph/GraphFallback.js
Outdated
<p style={{ marginBottom: "0.5rem" }} id="graph-fallback"> | ||
Your graph has failed to render. Please reload this page or report this | ||
issue to David Liu at {""} | ||
<span |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit more complicated than it needs to be. You can use an <a>
tag with the appropriate href
attribute, and the formatting should be handled automatically by CSS.
js/components/graph/GraphFallback.js
Outdated
<div className="error-boundary-box"> | ||
<div className="error-boundary-text"> | ||
<FontAwesomeIcon icon={faTriangleExclamation} id="error-svg" /> | ||
<p style={{ marginBottom: "0.5rem" }} id="graph-fallback"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use inline styling, and instead use class-based CSS rules.
describe("Verify that the Error Fallback component is only rendered on a Graph render error", () => { | ||
it("Should render the Fallback component when the Graph fails to render", () => { | ||
const result = render(<Container />) | ||
const foundFallback = result.container.querySelector("#graph-fallback") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, front-end tests should query text that the user sees, and not invisible attributes like ids or classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I don't think you should mock the import of Graph
. Instead, you can mock a Graph
method like fetchData
. Also, do it within a test case rather than globally; this should allow you to implement more test cases.
… into graph-error-boundary zsh:1: command not found: wq
@@ -126,7 +126,7 @@ export class Graph extends React.Component { | |||
} | |||
} | |||
|
|||
getGraph = () => { | |||
getGraph() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert the changes in this file (they are unrelated to your PR)
}) | ||
|
||
it("Should render the Fallback component when the Graph fails to render", async () => { | ||
jest.spyOn(Graph.prototype, "getGraph").mockImplementation(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I think you can try mocking componentDidMount
instead
@@ -11,7 +11,8 @@ | |||
"test": "jest", | |||
"prettier": "prettier --write .", | |||
"eslint": "eslint --fix js", | |||
"prepare": "husky" | |||
"prepare": "husky", | |||
"stylelint": "stylelint '**/*.scss'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change (unrelated to your current task)
font-size: 20px; | ||
} | ||
|
||
#error-svg { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid id-based CSS rules; you can use class-based rules instead
Proposed Changes
Added the ErrorBoundary and created an ErrorBoundary fallback component to render if/when
Graph
fails to render....
Type of Change
(Write an
X
or a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]
into a[x]
in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)