Skip to content

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

matt-dahlgren
Copy link
Contributor

@matt-dahlgren matt-dahlgren commented Jul 13, 2025

Proposed Changes

Added the ErrorBoundary and created an ErrorBoundary fallback component to render if/when Graph fails to render.

...

Screenshot 2025-07-13 at 3 57 30 PM

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency) X
🔧 Internal (change that only affects developers or continuous integration)

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:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@coveralls
Copy link

coveralls commented Jul 14, 2025

Pull Request Test Coverage Report for Build b735c2dd-d113-4bb4-aaf5-be6f8ceeb9d3

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 50.769%

Totals Coverage Status
Change from base Build 8897d2ec-2414-448c-8905-d5b770524b98: 0.02%
Covered Lines: 1774
Relevant Lines: 3553

💛 - Coveralls

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 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

Copy link
Contributor

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`
Copy link
Contributor

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

import { ErrorBoundary } from "react-error-boundary"
import GraphFallback from "../graph/GraphFallback"

function sendEmail() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is unused

<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
Copy link
Contributor

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.

<div className="error-boundary-box">
<div className="error-boundary-text">
<FontAwesomeIcon icon={faTriangleExclamation} id="error-svg" />
<p style={{ marginBottom: "0.5rem" }} id="graph-fallback">
Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor

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.

@@ -126,7 +126,7 @@ export class Graph extends React.Component {
}
}

getGraph = () => {
getGraph() {
Copy link
Contributor

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(() => {
Copy link
Contributor

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'"
Copy link
Contributor

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 {
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants