1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-09 08:42:50 +03:00

Apply prettier formatting

This commit is contained in:
Michael Weimann
2022-12-12 12:24:14 +01:00
parent 1cac306093
commit 526645c791
1576 changed files with 65385 additions and 62478 deletions

View File

@@ -14,22 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React from 'react';
import React from "react";
// eslint-disable-next-line deprecate/import
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { mount } from "enzyme";
import { act } from "react-dom/test-utils";
import AccessibleButton from '../../../../src/components/views/elements/AccessibleButton';
import { Key } from '../../../../src/Keyboard';
import { mockPlatformPeg, unmockPlatformPeg } from '../../../test-utils';
import AccessibleButton from "../../../../src/components/views/elements/AccessibleButton";
import { Key } from "../../../../src/Keyboard";
import { mockPlatformPeg, unmockPlatformPeg } from "../../../test-utils";
describe('<AccessibleButton />', () => {
describe("<AccessibleButton />", () => {
const defaultProps = {
onClick: jest.fn(),
children: 'i am a button',
children: "i am a button",
};
const getComponent = (props = {}) =>
mount(<AccessibleButton {...defaultProps} {...props} />);
const getComponent = (props = {}) => mount(<AccessibleButton {...defaultProps} {...props} />);
beforeEach(() => {
mockPlatformPeg();
@@ -39,66 +38,67 @@ describe('<AccessibleButton />', () => {
unmockPlatformPeg();
});
const makeKeyboardEvent = (key: string) => ({
key,
stopPropagation: jest.fn(),
preventDefault: jest.fn(),
}) as unknown as KeyboardEvent;
const makeKeyboardEvent = (key: string) =>
({
key,
stopPropagation: jest.fn(),
preventDefault: jest.fn(),
} as unknown as KeyboardEvent);
it('renders div with role button by default', () => {
it("renders div with role button by default", () => {
const component = getComponent();
expect(component).toMatchSnapshot();
});
it('renders a button element', () => {
const component = getComponent({ element: 'button' });
it("renders a button element", () => {
const component = getComponent({ element: "button" });
expect(component).toMatchSnapshot();
});
it('renders with correct classes when button has kind', () => {
it("renders with correct classes when button has kind", () => {
const component = getComponent({
kind: 'primary',
kind: "primary",
});
expect(component).toMatchSnapshot();
});
it('disables button correctly', () => {
it("disables button correctly", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
disabled: true,
});
expect(component.find('.mx_AccessibleButton').props().disabled).toBeTruthy();
expect(component.find('.mx_AccessibleButton').props()['aria-disabled']).toBeTruthy();
expect(component.find(".mx_AccessibleButton").props().disabled).toBeTruthy();
expect(component.find(".mx_AccessibleButton").props()["aria-disabled"]).toBeTruthy();
act(() => {
component.simulate('click');
component.simulate("click");
});
expect(onClick).not.toHaveBeenCalled();
act(() => {
const keydownEvent = makeKeyboardEvent(Key.ENTER);
component.simulate('keydown', keydownEvent);
component.simulate("keydown", keydownEvent);
});
expect(onClick).not.toHaveBeenCalled();
});
it('calls onClick handler on button click', () => {
it("calls onClick handler on button click", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
});
act(() => {
component.simulate('click');
component.simulate("click");
});
expect(onClick).toHaveBeenCalled();
});
it('calls onClick handler on button mousedown when triggerOnMousedown is passed', () => {
it("calls onClick handler on button mousedown when triggerOnMousedown is passed", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
@@ -106,14 +106,14 @@ describe('<AccessibleButton />', () => {
});
act(() => {
component.simulate('mousedown');
component.simulate("mousedown");
});
expect(onClick).toHaveBeenCalled();
});
describe('handling keyboard events', () => {
it('calls onClick handler on enter keydown', () => {
describe("handling keyboard events", () => {
it("calls onClick handler on enter keydown", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
@@ -121,13 +121,13 @@ describe('<AccessibleButton />', () => {
const keyboardEvent = makeKeyboardEvent(Key.ENTER);
act(() => {
component.simulate('keydown', keyboardEvent);
component.simulate("keydown", keyboardEvent);
});
expect(onClick).toHaveBeenCalled();
act(() => {
component.simulate('keyup', keyboardEvent);
component.simulate("keyup", keyboardEvent);
});
// handler only called once on keydown
@@ -137,7 +137,7 @@ describe('<AccessibleButton />', () => {
expect(keyboardEvent.preventDefault).toHaveBeenCalledTimes(2);
});
it('calls onClick handler on space keyup', () => {
it("calls onClick handler on space keyup", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
@@ -145,13 +145,13 @@ describe('<AccessibleButton />', () => {
const keyboardEvent = makeKeyboardEvent(Key.SPACE);
act(() => {
component.simulate('keydown', keyboardEvent);
component.simulate("keydown", keyboardEvent);
});
expect(onClick).not.toHaveBeenCalled();
act(() => {
component.simulate('keyup', keyboardEvent);
component.simulate("keyup", keyboardEvent);
});
// handler only called once on keyup
@@ -161,7 +161,7 @@ describe('<AccessibleButton />', () => {
expect(keyboardEvent.preventDefault).toHaveBeenCalledTimes(2);
});
it('calls onKeydown/onKeyUp handlers for keys other than space and enter', () => {
it("calls onKeydown/onKeyUp handlers for keys other than space and enter", () => {
const onClick = jest.fn();
const onKeyDown = jest.fn();
const onKeyUp = jest.fn();
@@ -173,8 +173,8 @@ describe('<AccessibleButton />', () => {
const keyboardEvent = makeKeyboardEvent(Key.K);
act(() => {
component.simulate('keydown', keyboardEvent);
component.simulate('keyup', keyboardEvent);
component.simulate("keydown", keyboardEvent);
component.simulate("keyup", keyboardEvent);
});
expect(onClick).not.toHaveBeenCalled();
@@ -184,7 +184,7 @@ describe('<AccessibleButton />', () => {
expect(keyboardEvent.preventDefault).not.toHaveBeenCalled();
});
it('does nothing on non space/enter key presses when no onKeydown/onKeyUp handlers provided', () => {
it("does nothing on non space/enter key presses when no onKeydown/onKeyUp handlers provided", () => {
const onClick = jest.fn();
const component = getComponent({
onClick,
@@ -192,8 +192,8 @@ describe('<AccessibleButton />', () => {
const keyboardEvent = makeKeyboardEvent(Key.K);
act(() => {
component.simulate('keydown', keyboardEvent);
component.simulate('keyup', keyboardEvent);
component.simulate("keydown", keyboardEvent);
component.simulate("keyup", keyboardEvent);
});
// no onClick call, no problems