2022-10-13 16:53:20 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
|
2022-10-19 10:45:51 +00:00
|
|
|
import { FormattingButtons } from "../../../../../src/components/views/rooms/wysiwyg_composer/components/FormattingButtons";
|
2022-10-13 16:53:20 +00:00
|
|
|
|
|
|
|
describe('FormattingButtons', () => {
|
|
|
|
const wysiwyg = {
|
|
|
|
bold: jest.fn(),
|
|
|
|
italic: jest.fn(),
|
|
|
|
underline: jest.fn(),
|
|
|
|
strikeThrough: jest.fn(),
|
|
|
|
} as any;
|
|
|
|
|
|
|
|
const formattingStates = {
|
|
|
|
bold: 'reversed',
|
|
|
|
italic: 'reversed',
|
|
|
|
underline: 'enabled',
|
|
|
|
strikeThrough: 'enabled',
|
|
|
|
} as any;
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should have the correspond CSS classes', () => {
|
|
|
|
// When
|
2022-10-14 08:56:34 +00:00
|
|
|
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
2022-10-13 16:53:20 +00:00
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(screen.getByLabelText('Bold')).toHaveClass('mx_FormattingButtons_active');
|
|
|
|
expect(screen.getByLabelText('Italic')).toHaveClass('mx_FormattingButtons_active');
|
|
|
|
expect(screen.getByLabelText('Underline')).not.toHaveClass('mx_FormattingButtons_active');
|
|
|
|
expect(screen.getByLabelText('Strikethrough')).not.toHaveClass('mx_FormattingButtons_active');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should call wysiwyg function on button click', () => {
|
|
|
|
// When
|
2022-10-14 08:56:34 +00:00
|
|
|
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
2022-10-13 16:53:20 +00:00
|
|
|
screen.getByLabelText('Bold').click();
|
|
|
|
screen.getByLabelText('Italic').click();
|
|
|
|
screen.getByLabelText('Underline').click();
|
|
|
|
screen.getByLabelText('Strikethrough').click();
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(wysiwyg.bold).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wysiwyg.italic).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wysiwyg.underline).toHaveBeenCalledTimes(1);
|
|
|
|
expect(wysiwyg.strikeThrough).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should display the tooltip on mouse over', async () => {
|
|
|
|
// When
|
|
|
|
const user = userEvent.setup();
|
2022-10-14 08:56:34 +00:00
|
|
|
render(<FormattingButtons composer={wysiwyg} formattingStates={formattingStates} />);
|
2022-10-13 16:53:20 +00:00
|
|
|
await user.hover(screen.getByLabelText('Bold'));
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(await screen.findByText('Bold')).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|