mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 01:05:42 +03:00
Add more tests for ReadReceiptGroup.tsx
This commit is contained in:
parent
b6132db68f
commit
8f07672da1
1 changed files with 25 additions and 3 deletions
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import React, { ComponentProps } from "react";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import { RoomMember } from "matrix-js-sdk/src/matrix";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
@ -26,6 +26,8 @@ import {
|
|||
} from "../../../../src/components/views/rooms/ReadReceiptGroup";
|
||||
import * as languageHandler from "../../../../src/languageHandler";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
||||
import { Action } from "../../../../src/dispatcher/actions";
|
||||
|
||||
describe("ReadReceiptGroup", () => {
|
||||
describe("TooltipText", () => {
|
||||
|
@ -100,11 +102,15 @@ describe("ReadReceiptGroup", () => {
|
|||
member.rawDisplayName = "Alice";
|
||||
member.getMxcAvatarUrl = () => "http://placekitten.com/400/400";
|
||||
|
||||
const renderReadReceipt = () => {
|
||||
const renderReadReceipt = (props?: Partial<ComponentProps<typeof ReadReceiptPerson>>) => {
|
||||
const currentDate = new Date(2024, 4, 15).getTime();
|
||||
return render(<ReadReceiptPerson userId={USER_ID} roomMember={member} ts={currentDate} />);
|
||||
return render(<ReadReceiptPerson userId={USER_ID} roomMember={member} ts={currentDate} {...props} />);
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.spyOn(dispatcher, "dispatch");
|
||||
});
|
||||
|
||||
it("should render", () => {
|
||||
const { container } = renderReadReceipt();
|
||||
expect(container).toMatchSnapshot();
|
||||
|
@ -119,5 +125,21 @@ describe("ReadReceiptGroup", () => {
|
|||
expect(tooltip).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it("should send an event when clicked", async () => {
|
||||
const onAfterClick = jest.fn();
|
||||
renderReadReceipt({ onAfterClick });
|
||||
|
||||
screen.getByRole("menuitem").click();
|
||||
|
||||
expect(onAfterClick).toHaveBeenCalled();
|
||||
expect(dispatcher.dispatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
action: Action.ViewUser,
|
||||
member,
|
||||
push: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue