Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d12d8fc

Browse files
committed
feat: added error boundary
closes #1013
1 parent dfa43fb commit d12d8fc

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { screen } from "@testing-library/react"
2+
import React from "react"
3+
import { render } from "../../testHelpers/renderHelpers"
4+
import { Language as ButtonLanguage } from "./createCtas"
5+
import { Language as RuntimeErrorStateLanguage, RuntimeErrorState } from "./RuntimeErrorState"
6+
7+
describe("RuntimeErrorState", () => {
8+
beforeEach(() => {
9+
// Given
10+
const errorText = "broken!"
11+
const errorStateProps = {
12+
error: new Error(errorText),
13+
}
14+
15+
// When
16+
render(<RuntimeErrorState {...errorStateProps} />)
17+
})
18+
19+
it("should show stack when encountering runtime error", () => {
20+
// Then
21+
const reportError = screen.getByText("broken!")
22+
expect(reportError).toBeDefined()
23+
24+
// Despite appearances, this is the stack trace
25+
const stackTrace = screen.getByText("Unable to get stack trace")
26+
expect(stackTrace).toBeDefined()
27+
})
28+
29+
it("should have a button bar", () => {
30+
// Then
31+
const copyCta = screen.getByText(ButtonLanguage.copyReport)
32+
expect(copyCta).toBeDefined()
33+
34+
const reloadCta = screen.getByText(ButtonLanguage.reloadApp)
35+
expect(reloadCta).toBeDefined()
36+
})
37+
38+
it("should have an email link", () => {
39+
// Then
40+
const emailLink = screen.getByText(RuntimeErrorStateLanguage.link)
41+
expect(emailLink.closest("a")).toHaveAttribute("href", "mailto:[email protected]")
42+
})
43+
})

site/src/components/RuntimeErrorState/RuntimeErrorState.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Box from "@material-ui/core/Box"
2+
import Link from "@material-ui/core/Link"
23
import { makeStyles } from "@material-ui/core/styles"
34
import ErrorOutlineIcon from "@material-ui/icons/ErrorOutline"
45
import React, { useEffect, useReducer } from "react"
5-
import { Link } from "react-router-dom"
66
import { mapStackTrace } from "sourcemapped-stacktrace"
77
import { Margins } from "../Margins/Margins"
88
import { Section } from "../Section/Section"
99
import { Typography } from "../Typography/Typography"
1010
import { reducer, RuntimeErrorReport, stackTraceAvailable, stackTraceUnavailable } from "./RuntimeErrorReport"
1111

12-
const Language = {
12+
export const Language = {
1313
title: "Coder encountered an error",
1414
body: "Please copy the crash log using the button below and",
1515
link: "send it to us.",
@@ -40,14 +40,7 @@ const ErrorStateDescription = () => {
4040
return (
4141
<Typography variant="body2" color="textSecondary">
4242
{Language.body}&nbsp;
43-
<Link
44-
to="#"
45-
onClick={(e) => {
46-
window.location.href = "mailto:[email protected]"
47-
e.preventDefault()
48-
}}
49-
className={styles.link}
50-
>
43+
<Link href="mailto:[email protected]" className={styles.link}>
5144
{Language.link}
5245
</Link>
5346
</Typography>

site/src/components/RuntimeErrorState/createCtas.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import RefreshIcon from "@material-ui/icons/Refresh"
44
import React from "react"
55
import { CopyButton } from "../CopyButton/CopyButton"
66

7-
const Language = {
7+
export const Language = {
88
reloadApp: "Reload Application",
99
copyReport: "Copy Report",
1010
}

0 commit comments

Comments
 (0)