Inline VerificationRequest.{invalid,ready,started,done,cancelled}
(#11013)
* Inline `VerificationRequest.{invalid,ready,started,done,cancelled}` These methods are all just shortcuts for checks on `phase`, so let's get rid of them * update test * Add some more tests * even more coverage * fix tests
This commit is contained in:
parent
6fa005dcfc
commit
2801afe570
7 changed files with 210 additions and 35 deletions
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { EventEmitter } from "events";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import {
|
||||
Phase as VerificationPhase,
|
||||
VerificationRequest,
|
||||
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils";
|
||||
import MKeyVerificationRequest from "../../../../src/components/views/messages/MKeyVerificationRequest";
|
||||
|
||||
describe("MKeyVerificationRequest", () => {
|
||||
const userId = "@user:server";
|
||||
const getMockVerificationRequest = (props: Partial<VerificationRequest>) => {
|
||||
const res = new EventEmitter();
|
||||
Object.assign(res, {
|
||||
phase: VerificationPhase.Requested,
|
||||
canAccept: false,
|
||||
initiatedByMe: true,
|
||||
...props,
|
||||
});
|
||||
return res as unknown as VerificationRequest;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
getMockClientWithEventEmitter({
|
||||
...mockClientMethodsUser(userId),
|
||||
getRoom: jest.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.spyOn(MatrixClientPeg, "get").mockRestore();
|
||||
});
|
||||
|
||||
it("should not render if the request is absent", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.request" });
|
||||
const { container } = render(<MKeyVerificationRequest mxEvent={event} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it("should not render if the request is unsent", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.request" });
|
||||
event.verificationRequest = getMockVerificationRequest({
|
||||
phase: VerificationPhase.Unsent,
|
||||
});
|
||||
const { container } = render(<MKeyVerificationRequest mxEvent={event} />);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it("should render appropriately when the request was sent", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.request" });
|
||||
event.verificationRequest = getMockVerificationRequest({});
|
||||
const { container } = render(<MKeyVerificationRequest mxEvent={event} />);
|
||||
expect(container).toHaveTextContent("You sent a verification request");
|
||||
});
|
||||
|
||||
it("should render appropriately when the request was cancelled", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.request" });
|
||||
event.verificationRequest = getMockVerificationRequest({
|
||||
phase: VerificationPhase.Cancelled,
|
||||
cancellingUserId: userId,
|
||||
});
|
||||
const { container } = render(<MKeyVerificationRequest mxEvent={event} />);
|
||||
expect(container).toHaveTextContent("You sent a verification request");
|
||||
expect(container).toHaveTextContent("You cancelled");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue