-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Alert, Button, Card } from "antd"; | ||
import React from "react"; | ||
|
||
const FallbackComponent: React.FC = () => { | ||
return ( | ||
<Card style={{ width: "500px" }}> | ||
<Alert | ||
message={"Something went wrong"} | ||
description={ | ||
<> | ||
<Button | ||
onClick={() => | ||
window.location.assign(window.location.pathname) | ||
} | ||
> | ||
Refresh | ||
</Button> | ||
</> | ||
} | ||
type="error" | ||
showIcon | ||
/> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default FallbackComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { describe, test } from "vitest"; | ||
import QRcode from "."; | ||
|
||
describe("QRCODE", () => { | ||
test("render component without crash", () => { | ||
render(<QRcode />); | ||
}); | ||
|
||
test("textarea input providation", () => { | ||
render(<QRcode />); | ||
|
||
const textarea = screen.getByPlaceholderText("Enter input"); | ||
|
||
fireEvent.change(textarea, { target: { value: "Test text" } }); | ||
|
||
expect(textarea).toHaveValue("Test text"); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
ui/src/pages/Generator/QRcode/components/QRCodeErrorBoundary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import ErrorComponent from "components/General/ErrorComponent"; | ||
import { Component, ReactNode } from "react"; | ||
|
||
type ErrorBoundaryProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
type ErrorBoundaryState = { | ||
hasError: boolean; | ||
}; | ||
|
||
class QRCodeErrorBoundary extends Component< | ||
ErrorBoundaryProps, | ||
ErrorBoundaryState | ||
> { | ||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
componentDidCatch() { | ||
this.setState({ hasError: true }); | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return ( | ||
<ErrorComponent | ||
category="Input Error" | ||
reasons={["Input text is too long"]} | ||
solutions={[ | ||
"Input should be small", | ||
"Compressing the data before generating the QR code", | ||
"truncate or split the text and generate multiple QR Code", | ||
]} | ||
/> | ||
); | ||
} | ||
return this.props.children; | ||
} | ||
} | ||
|
||
export default QRCodeErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters