mirror of https://github.com/vector-im/riot-web
test code cleaned up slightly
parent
150fe7a45a
commit
544479a6ee
|
@ -7,23 +7,14 @@ import { MatrixClientPeg } from '../../../../src/MatrixClientPeg';
|
||||||
import { MatrixEvent } from 'matrix-js-sdk';
|
import { MatrixEvent } from 'matrix-js-sdk';
|
||||||
import MKeyVerificationConclusion from '../../../../src/components/views/messages/MKeyVerificationConclusion';
|
import MKeyVerificationConclusion from '../../../../src/components/views/messages/MKeyVerificationConclusion';
|
||||||
|
|
||||||
class UserTrustLevel {
|
const trustworthy = () => ({ isCrossSigningVerified: () => true });
|
||||||
constructor(cs) {
|
const untrustworthy = () => ({ isCrossSigningVerified: () => false });
|
||||||
this.cs = cs;
|
|
||||||
}
|
|
||||||
|
|
||||||
isCrossSigningVerified() {
|
|
||||||
return this.cs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("MKeyVerificationConclusion", () => {
|
describe("MKeyVerificationConclusion", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestUtils.stubClient();
|
TestUtils.stubClient();
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
|
client.checkUserTrust = trustworthy;
|
||||||
const userTrust = new UserTrustLevel(true);
|
|
||||||
client.checkUserTrust = () => userTrust;
|
|
||||||
|
|
||||||
const emitter = new EventEmitter();
|
const emitter = new EventEmitter();
|
||||||
client.on = emitter.on.bind(emitter);
|
client.on = emitter.on.bind(emitter);
|
||||||
|
@ -71,8 +62,7 @@ describe("MKeyVerificationConclusion", () => {
|
||||||
|
|
||||||
it("shouldn't render if the user isn't actually trusted", () => {
|
it("shouldn't render if the user isn't actually trusted", () => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const userTrust = new UserTrustLevel(false);
|
client.checkUserTrust = untrustworthy;
|
||||||
client.checkUserTrust = () => userTrust;
|
|
||||||
|
|
||||||
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
||||||
event.verificationRequest = new EventEmitter();
|
event.verificationRequest = new EventEmitter();
|
||||||
|
@ -85,8 +75,7 @@ describe("MKeyVerificationConclusion", () => {
|
||||||
|
|
||||||
it("should rerender appropriately if user trust status changes", () => {
|
it("should rerender appropriately if user trust status changes", () => {
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const userTrust = new UserTrustLevel(false);
|
client.checkUserTrust = untrustworthy;
|
||||||
client.checkUserTrust = () => userTrust;
|
|
||||||
|
|
||||||
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
const event = new MatrixEvent({ type: "m.key.verification.done" });
|
||||||
event.verificationRequest = new EventEmitter();
|
event.verificationRequest = new EventEmitter();
|
||||||
|
@ -97,7 +86,7 @@ describe("MKeyVerificationConclusion", () => {
|
||||||
);
|
);
|
||||||
expect(renderer.toJSON()).toBeNull();
|
expect(renderer.toJSON()).toBeNull();
|
||||||
|
|
||||||
client.checkUserTrust = () => new UserTrustLevel(true);
|
client.checkUserTrust = trustworthy;
|
||||||
|
|
||||||
/* Ensure we don't rerender for every trust status change of any user */
|
/* Ensure we don't rerender for every trust status change of any user */
|
||||||
client.emit("userTrustStatusChanged", "@anotheruser:domain");
|
client.emit("userTrustStatusChanged", "@anotheruser:domain");
|
||||||
|
|
Loading…
Reference in New Issue