mirror of https://github.com/vector-im/riot-web
Add more tests for `ReadReceiptGroup.tsx`
parent
b6132db68f
commit
8f07672da1
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React, { ComponentProps } from "react";
|
||||||
import { render, screen, waitFor } from "@testing-library/react";
|
import { render, screen, waitFor } from "@testing-library/react";
|
||||||
import { RoomMember } from "matrix-js-sdk/src/matrix";
|
import { RoomMember } from "matrix-js-sdk/src/matrix";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
@ -26,6 +26,8 @@ import {
|
||||||
} from "../../../../src/components/views/rooms/ReadReceiptGroup";
|
} from "../../../../src/components/views/rooms/ReadReceiptGroup";
|
||||||
import * as languageHandler from "../../../../src/languageHandler";
|
import * as languageHandler from "../../../../src/languageHandler";
|
||||||
import { stubClient } from "../../../test-utils";
|
import { stubClient } from "../../../test-utils";
|
||||||
|
import dispatcher from "../../../../src/dispatcher/dispatcher";
|
||||||
|
import { Action } from "../../../../src/dispatcher/actions";
|
||||||
|
|
||||||
describe("ReadReceiptGroup", () => {
|
describe("ReadReceiptGroup", () => {
|
||||||
describe("TooltipText", () => {
|
describe("TooltipText", () => {
|
||||||
|
@ -100,11 +102,15 @@ describe("ReadReceiptGroup", () => {
|
||||||
member.rawDisplayName = "Alice";
|
member.rawDisplayName = "Alice";
|
||||||
member.getMxcAvatarUrl = () => "http://placekitten.com/400/400";
|
member.getMxcAvatarUrl = () => "http://placekitten.com/400/400";
|
||||||
|
|
||||||
const renderReadReceipt = () => {
|
const renderReadReceipt = (props?: Partial<ComponentProps<typeof ReadReceiptPerson>>) => {
|
||||||
const currentDate = new Date(2024, 4, 15).getTime();
|
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", () => {
|
it("should render", () => {
|
||||||
const { container } = renderReadReceipt();
|
const { container } = renderReadReceipt();
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
|
@ -119,5 +125,21 @@ describe("ReadReceiptGroup", () => {
|
||||||
expect(tooltip).toMatchSnapshot();
|
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 New Issue