-
Notifications
You must be signed in to change notification settings - Fork 7
/
QuestionCommentIcon.test.js
77 lines (64 loc) · 2.86 KB
/
QuestionCommentIcon.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from "react";
import QuestionCommentIcon from "../../src/components/comment/QuestionCommentIcon";
import { cleanup, render } from "@testing-library/react";
import { composeStories } from "@storybook/testing-react";
import { fireEvent } from "@storybook/testing-library";
import { expect } from "@storybook/jest";
import * as stories from "../../src/stories/QuestionCommentIcon.stories";
describe("QuestionCommentIcon", () => {
afterEach(() => {
cleanup();
});
const { Default, WithComment } = composeStories(stories);
it("should have empty comment list", async () => {
const component = render(<Default {...Default.args} />);
fireEvent.click(component.container.querySelector(".comment-bubble"));
await expect(component.queryByRole("tooltip")).toBeInTheDocument();
await expect(component.queryByText("Comment")).not.toBeInTheDocument();
});
it("should have two comments", async () => {
const component = render(<WithComment {...WithComment.args} />);
fireEvent.click(component.container.querySelector(".comment-bubble"));
await expect(component.queryByRole("tooltip")).toBeInTheDocument();
const comments = await component.findAllByText("Comment");
await expect(comments).toHaveLength(2);
});
it("should show link icon when hover author comment", async () => {
const component = render(<WithComment {...WithComment.args} />);
fireEvent.click(component.container.querySelector(".comment-bubble"));
const authors = await component.queryAllByText("Unknown author");
const author = authors[0];
await expect(component.queryByRole("link")).not.toBeInTheDocument();
fireEvent.mouseOver(author);
await expect(component.queryByRole("link")).toBeInTheDocument();
});
it("should delete comment when click on recycle bin", async () => {
const component = render(<WithComment {...WithComment.args} />);
fireEvent.click(component.container.querySelector(".comment-bubble"));
const authors = await component.queryAllByText("Unknown author");
const author = authors[0];
await expect(
component.container.querySelector(".comment-delete")
).not.toBeInTheDocument();
fireEvent.mouseOver(author);
await expect(
component.container.querySelector(".comment-delete")
).toBeInTheDocument();
await expect(
component.queryByTestId("rings-loading")
).not.toBeInTheDocument();
fireEvent.click(component.container.querySelector(".comment-delete"));
await expect(component.queryByTestId("rings-loading")).toBeInTheDocument();
await new Promise((resolve) => {
setTimeout(() => {
console.log("time is up");
resolve();
}, 2000);
});
await expect(
component.queryByTestId("rings-loading")
).not.toBeInTheDocument();
const comments = await component.findAllByText("Comment");
await expect(comments).toHaveLength(1);
});
});