Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Apr 17, 2024
1 parent 9a6498c commit 286371f
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions test/components/views/messages/DecryptionFailureBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
import React from "react";
import { render } from "@testing-library/react";
import { MatrixEvent } from "matrix-js-sdk/src/matrix";
import { mkDecryptionFailureMatrixEvent } from "matrix-js-sdk/src/testing";
import { DecryptionFailureCode } from "matrix-js-sdk/src/crypto-api";

import { mkEvent } from "../../../test-utils";
import { DecryptionFailureBody } from "../../../../src/components/views/messages/DecryptionFailureBody";
import { LocalDeviceVerificationStateContext } from "../../../../src/contexts/LocalDeviceVerificationStateContext";

describe("DecryptionFailureBody", () => {
function customRender(event: MatrixEvent) {
return render(<DecryptionFailureBody mxEvent={event} />);
function customRender(event: MatrixEvent, localDeviceVerified: boolean = false) {
return render(
<LocalDeviceVerificationStateContext.Provider value={localDeviceVerified}>
<DecryptionFailureBody mxEvent={event} />
</LocalDeviceVerificationStateContext.Provider>,
);
}

it(`Should display "Unable to decrypt message"`, () => {
Expand Down Expand Up @@ -60,4 +67,42 @@ describe("DecryptionFailureBody", () => {
// Then
expect(container).toMatchSnapshot();
});

it("should handle historical messages with no key backup", async () => {
// When
const event = await mkDecryptionFailureMatrixEvent({
code: DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP,
msg: "No backup",
roomId: "fakeroom",
sender: "fakesender",
});
const { container } = customRender(event);

// Then
expect(container).toHaveTextContent("Historical messages are not available on this device");
});

describe.each([true, false])(
"should handle historical messages when there is a backup and device verification is",
(verified) => {
it.each([
[DecryptionFailureCode.HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED],
[DecryptionFailureCode.HISTORICAL_MESSAGE_WORKING_BACKUP],
])("Error code %s", async (code) => {
// When
const event = await mkDecryptionFailureMatrixEvent({
code,
msg: "Failure",
roomId: "fakeroom",
sender: "fakesender",
});
const { container } = customRender(event, verified);

// Then
expect(container).toHaveTextContent(

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 1: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 2: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check failure on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 1: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_WORKING_BACKUP

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 2: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_WORKING_BACKUP

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check failure on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_WORKING_BACKUP

expect(element).toHaveTextContent() Expected element to have text content: You need to verify this device for access to historical messages Received: Unable to decrypt message at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 1: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: Unable to decrypt Received: You need to verify this device for access to historical messages at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 2: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: Unable to decrypt Received: You need to verify this device for access to historical messages at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check failure on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED

expect(element).toHaveTextContent() Expected element to have text content: Unable to decrypt Received: You need to verify this device for access to historical messages at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check warning on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

RETRY 1: DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_WORKING_BACKUP

expect(element).toHaveTextContent() Expected element to have text content: Unable to decrypt Received: You need to verify this device for access to historical messages at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)

Check failure on line 102 in test/components/views/messages/DecryptionFailureBody-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (2)

DecryptionFailureBody › should handle historical messages when there is a backup and device verification is › Error code HISTORICAL_MESSAGE_WORKING_BACKUP

expect(element).toHaveTextContent() Expected element to have text content: Unable to decrypt Received: You need to verify this device for access to historical messages at toHaveTextContent (test/components/views/messages/DecryptionFailureBody-test.tsx:102:35)
verified ? "You need to verify this device for access to historical messages" : "Unable to decrypt",
);
});
},
);
});

0 comments on commit 286371f

Please sign in to comment.