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
|
@ -17,10 +17,13 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { EventEmitter } from "events";
|
||||
import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
|
||||
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
|
||||
import { UserTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning";
|
||||
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
import {
|
||||
Phase as VerificationPhase,
|
||||
VerificationRequest,
|
||||
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import MKeyVerificationConclusion from "../../../../src/components/views/messages/MKeyVerificationConclusion";
|
||||
|
@ -38,27 +41,32 @@ describe("MKeyVerificationConclusion", () => {
|
|||
});
|
||||
|
||||
const getMockVerificationRequest = ({
|
||||
pending,
|
||||
cancelled,
|
||||
done,
|
||||
pending = false,
|
||||
phase = VerificationPhase.Unsent,
|
||||
otherUserId,
|
||||
cancellingUserId,
|
||||
}: {
|
||||
pending?: boolean;
|
||||
cancelled?: boolean;
|
||||
done?: boolean;
|
||||
phase?: VerificationPhase;
|
||||
otherUserId?: string;
|
||||
cancellingUserId?: string;
|
||||
}) => {
|
||||
class MockVerificationRequest extends EventEmitter {
|
||||
constructor(
|
||||
public readonly pending?: boolean,
|
||||
public readonly cancelled?: boolean,
|
||||
public readonly done?: boolean,
|
||||
public readonly pending: boolean,
|
||||
public readonly phase: VerificationPhase,
|
||||
public readonly otherUserId?: string,
|
||||
public readonly cancellingUserId?: string,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
return new MockVerificationRequest(pending, cancelled, done, otherUserId) as unknown as VerificationRequest;
|
||||
return new MockVerificationRequest(
|
||||
pending,
|
||||
phase,
|
||||
otherUserId,
|
||||
cancellingUserId,
|
||||
) as unknown as VerificationRequest;
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -85,14 +93,14 @@ describe("MKeyVerificationConclusion", () => {
|
|||
|
||||
it("shouldn't render if the event type is cancel but the request type isn't", () => {
|
||||
const event = new MatrixEvent({ type: EventType.KeyVerificationCancel });
|
||||
event.verificationRequest = getMockVerificationRequest({ cancelled: false });
|
||||
event.verificationRequest = getMockVerificationRequest({});
|
||||
const { container } = render(<MKeyVerificationConclusion mxEvent={event} />);
|
||||
expect(container).toBeEmpty();
|
||||
});
|
||||
|
||||
it("shouldn't render if the event type is done but the request type isn't", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
||||
event.verificationRequest = getMockVerificationRequest({ done: false });
|
||||
event.verificationRequest = getMockVerificationRequest({});
|
||||
const { container } = render(<MKeyVerificationConclusion mxEvent={event} />);
|
||||
expect(container).toBeEmpty();
|
||||
});
|
||||
|
@ -101,7 +109,7 @@ describe("MKeyVerificationConclusion", () => {
|
|||
mockClient.checkUserTrust.mockReturnValue(untrustworthy);
|
||||
|
||||
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
||||
event.verificationRequest = getMockVerificationRequest({ done: true });
|
||||
event.verificationRequest = getMockVerificationRequest({ phase: VerificationPhase.Done });
|
||||
const { container } = render(<MKeyVerificationConclusion mxEvent={event} />);
|
||||
expect(container).toBeEmpty();
|
||||
});
|
||||
|
@ -110,7 +118,10 @@ describe("MKeyVerificationConclusion", () => {
|
|||
mockClient.checkUserTrust.mockReturnValue(untrustworthy);
|
||||
|
||||
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
||||
event.verificationRequest = getMockVerificationRequest({ done: true, otherUserId: "@someuser:domain" });
|
||||
event.verificationRequest = getMockVerificationRequest({
|
||||
phase: VerificationPhase.Done,
|
||||
otherUserId: "@someuser:domain",
|
||||
});
|
||||
const { container } = render(<MKeyVerificationConclusion mxEvent={event} />);
|
||||
expect(container).toBeEmpty();
|
||||
|
||||
|
@ -132,4 +143,14 @@ describe("MKeyVerificationConclusion", () => {
|
|||
);
|
||||
expect(container).not.toBeEmpty();
|
||||
});
|
||||
|
||||
it("should render appropriately if we cancelled the verification", () => {
|
||||
const event = new MatrixEvent({ type: "m.key.verification.cancel" });
|
||||
event.verificationRequest = getMockVerificationRequest({
|
||||
phase: VerificationPhase.Cancelled,
|
||||
cancellingUserId: userId,
|
||||
});
|
||||
const { container } = render(<MKeyVerificationConclusion mxEvent={event} />);
|
||||
expect(container).toHaveTextContent("You cancelled verifying");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue