* Converted [./components/spinner_button.tsx] to functional component * Converted [./components/spinner_button.tsx] to functional component * [./components/spinner_button.tsx]: wrapped the component with react.memo + removed default props + use multi-lines in args * [./components/spinner_button.tsx]: - fix lint errors in spinner button - fix error in missing prop on spinnerButton component * [./components/spinner_button.tsx]: - convert class component to functional component - fix lint errors in spinner button * fix:[spinner_button]: fix lint errors * - fix: [add_emoji.tsx]: add an id selector to the SpinnerButton to fix issue in unit test for this file. - fix: [add_emoji.test.tsx]: find the saveButton with id selector instead of using element directly (was causing test fai) - update test snapshots * fix[add_emoji]: replaced id with data-testid to be used in unit test --------- Co-authored-by: Noha M <33437197+NohaaAa@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
77 строки
2.1 KiB
TypeScript
77 строки
2.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {mount, shallow} from 'enzyme';
|
|
import React from 'react';
|
|
|
|
import SpinnerButton from 'components/spinner_button';
|
|
|
|
describe('components/SpinnerButton', () => {
|
|
test('should match snapshot with required props', () => {
|
|
const wrapper = shallow(
|
|
<SpinnerButton
|
|
spinning={false}
|
|
spinningText='Test'
|
|
/>,
|
|
);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
test('should match snapshot with spinning', () => {
|
|
const wrapper = shallow(
|
|
<SpinnerButton
|
|
spinning={true}
|
|
spinningText='Test'
|
|
/>,
|
|
);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
test('should match snapshot with children', () => {
|
|
const wrapper = shallow(
|
|
<SpinnerButton
|
|
spinning={false}
|
|
spinningText='Test'
|
|
>
|
|
<span id='child1'/>
|
|
<span id='child2'/>
|
|
</SpinnerButton>,
|
|
);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
test('should handle onClick', () => {
|
|
const onClick = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
<SpinnerButton
|
|
spinning={false}
|
|
onClick={onClick}
|
|
spinningText='Test'
|
|
/>,
|
|
);
|
|
|
|
wrapper.find('button').simulate('click');
|
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test('should add properties to underlying button', () => {
|
|
const wrapper = mount(
|
|
<SpinnerButton
|
|
id='my-button-id'
|
|
className='btn btn-success'
|
|
spinningText='Test'
|
|
spinning={false}
|
|
/>,
|
|
);
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
expect(button).not.toBeUndefined();
|
|
expect(button.type()).toEqual('button');
|
|
expect(button.props().id).toEqual('my-button-id');
|
|
expect(button.hasClass('btn')).toBeTruthy();
|
|
expect(button.hasClass('btn-success')).toBeTruthy();
|
|
});
|
|
});
|