2022-10-26 11:04:16 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import React from "react";
|
|
|
|
import { fireEvent, render } from "@testing-library/react";
|
2022-10-26 11:04:16 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
import LearnMore from "../../../../src/components/views/elements/LearnMore";
|
|
|
|
import Modal from "../../../../src/Modal";
|
|
|
|
import InfoDialog from "../../../../src/components/views/dialogs/InfoDialog";
|
2022-10-26 11:04:16 +02:00
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
describe("<LearnMore />", () => {
|
2022-10-26 11:04:16 +02:00
|
|
|
const defaultProps = {
|
2022-12-12 12:24:14 +01:00
|
|
|
title: "Test",
|
|
|
|
description: "test test test",
|
|
|
|
["data-testid"]: "testid",
|
2022-10-26 11:04:16 +02:00
|
|
|
};
|
2022-12-12 12:24:14 +01:00
|
|
|
const getComponent = (props = {}) => <LearnMore {...defaultProps} {...props} />;
|
2022-10-26 11:04:16 +02:00
|
|
|
|
2023-02-16 10:38:44 +01:00
|
|
|
const modalSpy = jest.spyOn(Modal, "createDialog").mockReturnValue({
|
|
|
|
finished: new Promise(() => {}),
|
|
|
|
close: jest.fn(),
|
|
|
|
});
|
2022-10-26 11:04:16 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("renders button", () => {
|
2022-10-26 11:04:16 +02:00
|
|
|
const { container } = render(getComponent());
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2022-12-12 12:24:14 +01:00
|
|
|
it("opens modal on click", async () => {
|
2022-10-26 11:04:16 +02:00
|
|
|
const { getByTestId } = render(getComponent());
|
2022-12-12 12:24:14 +01:00
|
|
|
fireEvent.click(getByTestId("testid"));
|
|
|
|
|
|
|
|
expect(modalSpy).toHaveBeenCalledWith(InfoDialog, {
|
|
|
|
button: "Got it",
|
|
|
|
description: defaultProps.description,
|
|
|
|
hasCloseButton: true,
|
|
|
|
title: defaultProps.title,
|
|
|
|
});
|
2022-10-26 11:04:16 +02:00
|
|
|
});
|
|
|
|
});
|