2022-11-02 11:51:20 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-11-02 11:51:20 +01:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-11-02 11:51:20 +01:00
|
|
|
*/
|
|
|
|
|
|
2026-05-25 09:10:10 +02:00
|
|
|
import { render, cleanup } from "jest-matrix-react";
|
2022-11-02 11:51:20 +01:00
|
|
|
import React from "react";
|
|
|
|
|
|
2026-05-25 09:10:10 +02:00
|
|
|
import { mockQRCodeRender, resetQRCodeMock, waitForQRCodeRender } from "../../../../test-utils/qrcode";
|
2024-10-15 14:57:26 +01:00
|
|
|
import QRCode from "../../../../../src/components/views/elements/QRCode";
|
2022-11-02 11:51:20 +01:00
|
|
|
|
|
|
|
|
describe("<QRCode />", () => {
|
|
|
|
|
afterEach(() => {
|
2026-05-25 09:10:10 +02:00
|
|
|
resetQRCodeMock();
|
2022-11-02 11:51:20 +01:00
|
|
|
cleanup();
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-13 14:55:55 +01:00
|
|
|
it("shows a spinner when data is null", async () => {
|
|
|
|
|
const { container } = render(<QRCode data={null} />);
|
|
|
|
|
expect(container.querySelector(".mx_Spinner")).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
2022-11-02 11:51:20 +01:00
|
|
|
it("renders a QR with defaults", async () => {
|
2026-05-25 09:10:10 +02:00
|
|
|
mockQRCodeRender();
|
2022-11-02 11:51:20 +01:00
|
|
|
const { container, getAllByAltText } = render(<QRCode data="asd" />);
|
2026-05-25 09:10:10 +02:00
|
|
|
await waitForQRCodeRender();
|
|
|
|
|
expect(getAllByAltText("QR Code")).toHaveLength(1);
|
2022-11-02 11:51:20 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("renders a QR with high error correction level", async () => {
|
2026-05-25 09:10:10 +02:00
|
|
|
mockQRCodeRender();
|
2022-11-02 11:51:20 +01:00
|
|
|
const { container, getAllByAltText } = render(<QRCode data="asd" errorCorrectionLevel="high" />);
|
2026-05-25 09:10:10 +02:00
|
|
|
await waitForQRCodeRender();
|
|
|
|
|
expect(getAllByAltText("QR Code")).toHaveLength(1);
|
2022-11-02 11:51:20 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|
|
|
|
|
});
|