-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
158 additions
and
52 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import { | ||
DialogType, | ||
DialogData, | ||
BasicDialog, | ||
dialogDetails, | ||
} from "./BasicDialog"; | ||
|
||
const getExpectedTitle = (type: DialogType) => { | ||
const { title, icon } = dialogDetails[type]; | ||
return icon + " " + title; | ||
}; | ||
|
||
const message = "Test message"; | ||
|
||
describe("BasicDialog", () => { | ||
it("renders info message", () => { | ||
const type = DialogType.INFO; | ||
const dialogData = new DialogData(message, type); | ||
const { getByText } = render( | ||
<BasicDialog dialogData={dialogData} onConfirm={() => {}} />, | ||
); | ||
const dialogTitle = getExpectedTitle(type); | ||
expect(getByText(dialogTitle)).toBeInTheDocument(); | ||
expect(getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders warning message", () => { | ||
const type = DialogType.WARNING; | ||
const dialogData = new DialogData(message, type); | ||
const { getByText } = render( | ||
<BasicDialog dialogData={dialogData} onConfirm={() => {}} />, | ||
); | ||
const dialogTitle = getExpectedTitle(type); | ||
expect(getByText(dialogTitle)).toBeInTheDocument(); | ||
expect(getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders error message", () => { | ||
const type = DialogType.ERROR; | ||
const dialogData = new DialogData(message, type); | ||
const { getByText } = render( | ||
<BasicDialog dialogData={dialogData} onConfirm={() => {}} />, | ||
); | ||
const dialogTitle = getExpectedTitle(type); | ||
expect(getByText(dialogTitle)).toBeInTheDocument(); | ||
expect(getByText(message)).toBeInTheDocument(); | ||
}); | ||
|
||
it("calls onConfirm when confirm button is clicked", () => { | ||
const dialogData = new DialogData(message, DialogType.INFO); | ||
const onConfirm = jest.fn(); | ||
const { getByText } = render( | ||
<BasicDialog dialogData={dialogData} onConfirm={onConfirm} />, | ||
); | ||
fireEvent.click(getByText("Confirm")); | ||
expect(onConfirm).toHaveBeenCalled(); | ||
}); | ||
}); |
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
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