-
-
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
3 changed files
with
51 additions
and
6 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
47 changes: 45 additions & 2 deletions
47
ui/src/pages/Markdown/TableOfContent/__tests__/TableOfContent.test.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 |
---|---|---|
@@ -1,9 +1,52 @@ | ||
import { render } from "@testing-library/react"; | ||
import { TableOfContent } from "pages/pages"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import { describe, test } from "vitest"; | ||
import TableOfContent from ".."; | ||
|
||
describe("Table Of content", () => { | ||
test("Render component without crash", () => { | ||
render(<TableOfContent />); | ||
}); | ||
|
||
test("show empty text when there is no value", () => { | ||
render(<TableOfContent />); | ||
|
||
const text = screen.getByText( | ||
"There is no data for TOC, please provide data first." | ||
); | ||
|
||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
test("write test based on url", () => { | ||
render(<TableOfContent />); | ||
|
||
const url = `https://raw.githubusercontent.com/lifeparticle/JS-Cheatsheet/main/README.md`; | ||
const inputElement = screen.getByPlaceholderText(/url/i); | ||
|
||
fireEvent.change(inputElement, { | ||
target: { | ||
value: url, | ||
}, | ||
}); | ||
|
||
expect(inputElement).toBeInTheDocument(); | ||
expect(inputElement).toHaveValue(url); | ||
}); | ||
|
||
test("Update the table of contents when the markdown content changes", () => { | ||
render(<TableOfContent />); | ||
const tocInput = screen.getByTestId("toc-input"); | ||
expect(tocInput).toBeInTheDocument(); | ||
|
||
fireEvent.change(tocInput, { | ||
target: { value: "# New Heading 1\n## New Heading 2" }, | ||
}); | ||
|
||
const tocOutput = screen.getByTestId("toc-output"); | ||
|
||
expect(tocOutput).toBeInTheDocument(); | ||
expect(tocOutput).not.toHaveValue( | ||
"[New Heading 1](#new-heading-1)\n[New Heading 2](#new-heading-2)" | ||
); | ||
}); | ||
}); |
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