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,24 +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 { mount } from "enzyme";
import { act } from "react-dom/test-utils";
import LabelledCheckbox from "../../../../src/components/views/elements/LabelledCheckbox";
// Fake random strings to give a predictable snapshot for checkbox IDs
jest.mock(
'matrix-js-sdk/src/randomstring',
() => {
return {
randomString: () => "abdefghi",
};
},
);
jest.mock("matrix-js-sdk/src/randomstring", () => {
return {
randomString: () => "abdefghi",
};
});
describe('<LabelledCheckbox />', () => {
describe("<LabelledCheckbox />", () => {
type CompProps = React.ComponentProps<typeof LabelledCheckbox>;
const getComponent = (props: CompProps) => mount(<LabelledCheckbox {...props} />);
type CompClass = ReturnType<typeof getComponent>;
@@ -42,29 +39,26 @@ describe('<LabelledCheckbox />', () => {
const isChecked = (checkbox: ReturnType<typeof getCheckbox>) => checkbox.is(`[checked=true]`);
const isDisabled = (checkbox: ReturnType<typeof getCheckbox>) => checkbox.is(`[disabled=true]`);
const getText = (span: ReturnType<typeof getLabel>) => span.length > 0 ? span.at(0).text() : null;
const getText = (span: ReturnType<typeof getLabel>) => (span.length > 0 ? span.at(0).text() : null);
test.each([null, "this is a byline"])(
"should render with byline of %p",
(byline) => {
const props: CompProps = {
label: "Hello world",
value: true,
byline: byline,
onChange: jest.fn(),
};
const component = getComponent(props);
const checkbox = getCheckbox(component);
test.each([null, "this is a byline"])("should render with byline of %p", (byline) => {
const props: CompProps = {
label: "Hello world",
value: true,
byline: byline,
onChange: jest.fn(),
};
const component = getComponent(props);
const checkbox = getCheckbox(component);
expect(component).toMatchSnapshot();
expect(isChecked(checkbox)).toBe(true);
expect(isDisabled(checkbox)).toBe(false);
expect(getText(getLabel(component))).toBe(props.label);
expect(getText(getByline(component))).toBe(byline);
},
);
expect(component).toMatchSnapshot();
expect(isChecked(checkbox)).toBe(true);
expect(isDisabled(checkbox)).toBe(false);
expect(getText(getLabel(component))).toBe(props.label);
expect(getText(getByline(component))).toBe(byline);
});
it('should support unchecked by default', () => {
it("should support unchecked by default", () => {
const props: CompProps = {
label: "Hello world",
value: false,
@@ -75,7 +69,7 @@ describe('<LabelledCheckbox />', () => {
expect(isChecked(getCheckbox(component))).toBe(false);
});
it('should be possible to disable the checkbox', () => {
it("should be possible to disable the checkbox", () => {
const props: CompProps = {
label: "Hello world",
value: false,
@@ -87,7 +81,7 @@ describe('<LabelledCheckbox />', () => {
expect(isDisabled(getCheckbox(component))).toBe(true);
});
it('should emit onChange calls', () => {
it("should emit onChange calls", () => {
const props: CompProps = {
label: "Hello world",
value: false,
@@ -98,13 +92,13 @@ describe('<LabelledCheckbox />', () => {
expect(props.onChange).not.toHaveBeenCalled();
act(() => {
getCheckbox(component).simulate('change');
getCheckbox(component).simulate("change");
});
expect(props.onChange).toHaveBeenCalledTimes(1);
});
it('should react to value and disabled prop changes', () => {
it("should react to value and disabled prop changes", () => {
const props: CompProps = {
label: "Hello world",
value: false,