[MM-23408] Migrate "components/setting_item_max.test.jsx" to Typescript (#24938)

Этот коммит содержится в:
Ritesh Mukim
2023-10-17 14:57:25 +05:30
коммит произвёл GitHub
родитель 83b4ad458a
Коммит fb1234667b
2 изменённых файлов: 61 добавлений и 38 удалений

Просмотреть файл

@@ -24,36 +24,28 @@ describe('components/SettingItemMax', () => {
}; };
test('should match snapshot', () => { test('should match snapshot', () => {
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...baseProps}/>);
<SettingItemMax {...baseProps}/>,
);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
test('should match snapshot, without submit', () => { test('should match snapshot, without submit', () => {
const props = {...baseProps, submit: null}; const props = {...baseProps, submit: null};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>,
);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
test('should match snapshot, on clientError', () => { test('should match snapshot, on clientError', () => {
const props = {...baseProps, clientError: 'clientError'}; const props = {...baseProps, clientError: 'clientError'};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>,
);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
test('should match snapshot, on serverError', () => { test('should match snapshot, on serverError', () => {
const props = {...baseProps, serverError: 'serverError'}; const props = {...baseProps, serverError: 'serverError'};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>,
);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
@@ -61,11 +53,14 @@ describe('components/SettingItemMax', () => {
test('should have called updateSection on handleUpdateSection with section', () => { test('should have called updateSection on handleUpdateSection with section', () => {
const updateSection = jest.fn(); const updateSection = jest.fn();
const props = {...baseProps, updateSection}; const props = {...baseProps, updateSection};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>, const instance = wrapper.instance() as SettingItemMax;
); const event = {
preventDefault: jest.fn(),
} as unknown as React.MouseEvent<HTMLButtonElement>;
instance.handleUpdateSection(event);
wrapper.instance().handleUpdateSection({preventDefault: jest.fn()});
expect(updateSection).toHaveBeenCalled(); expect(updateSection).toHaveBeenCalled();
expect(updateSection).toHaveBeenCalledWith('section'); expect(updateSection).toHaveBeenCalledWith('section');
}); });
@@ -73,11 +68,15 @@ describe('components/SettingItemMax', () => {
test('should have called updateSection on handleUpdateSection with empty string', () => { test('should have called updateSection on handleUpdateSection with empty string', () => {
const updateSection = jest.fn(); const updateSection = jest.fn();
const props = {...baseProps, updateSection, section: ''}; const props = {...baseProps, updateSection, section: ''};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>,
); const instance = wrapper.instance() as SettingItemMax;
const event = {
preventDefault: jest.fn(),
} as unknown as React.MouseEvent<HTMLButtonElement>;
instance.handleUpdateSection(event);
wrapper.instance().handleUpdateSection({preventDefault: jest.fn()});
expect(updateSection).toHaveBeenCalled(); expect(updateSection).toHaveBeenCalled();
expect(updateSection).toHaveBeenCalledWith(''); expect(updateSection).toHaveBeenCalledWith('');
}); });
@@ -85,11 +84,14 @@ describe('components/SettingItemMax', () => {
test('should have called submit on handleSubmit with setting', () => { test('should have called submit on handleSubmit with setting', () => {
const submit = jest.fn(); const submit = jest.fn();
const props = {...baseProps, submit}; const props = {...baseProps, submit};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>, const instance = wrapper.instance() as SettingItemMax;
); const event = {
preventDefault: jest.fn(),
} as unknown as React.MouseEvent<HTMLButtonElement>;
instance.handleSubmit(event);
wrapper.instance().handleSubmit({preventDefault: jest.fn()});
expect(submit).toHaveBeenCalled(); expect(submit).toHaveBeenCalled();
expect(submit).toHaveBeenCalledWith('setting'); expect(submit).toHaveBeenCalledWith('setting');
}); });
@@ -97,11 +99,14 @@ describe('components/SettingItemMax', () => {
test('should have called submit on handleSubmit with empty string', () => { test('should have called submit on handleSubmit with empty string', () => {
const submit = jest.fn(); const submit = jest.fn();
const props = {...baseProps, submit, setting: ''}; const props = {...baseProps, submit, setting: ''};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>, const instance = wrapper.instance() as SettingItemMax;
); const event = {
preventDefault: jest.fn(),
} as unknown as React.MouseEvent<HTMLButtonElement>;
instance.handleSubmit(event);
wrapper.instance().handleSubmit({preventDefault: jest.fn()});
expect(submit).toHaveBeenCalled(); expect(submit).toHaveBeenCalled();
expect(submit).toHaveBeenCalledWith(); expect(submit).toHaveBeenCalledWith();
}); });
@@ -109,25 +114,43 @@ describe('components/SettingItemMax', () => {
it('should have called submit on handleSubmit onKeyDown ENTER', () => { it('should have called submit on handleSubmit onKeyDown ENTER', () => {
const submit = jest.fn(); const submit = jest.fn();
const props = {...baseProps, submit}; const props = {...baseProps, submit};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>, const instance = wrapper.instance() as SettingItemMax;
);
const instance = wrapper.instance(); instance.onKeyDown({
preventDefault: jest.fn(),
key: Constants.KeyCodes.ENTER[0],
target: {
tagName: 'SELECT',
classList: {contains: jest.fn()},
parentElement: {className: 'react-select__input'},
},
} as unknown as KeyboardEvent);
instance.onKeyDown({preventDefault: jest.fn(), key: Constants.KeyCodes.ENTER[0], target: {tagName: 'SELECT', classList: {contains: jest.fn()}, parentElement: {className: 'react-select__input'}}});
expect(submit).toHaveBeenCalledTimes(0); expect(submit).toHaveBeenCalledTimes(0);
instance.settingList.current = {contains: jest.fn(() => true)}; instance.settingList = {
instance.onKeyDown({preventDefault: jest.fn(), key: Constants.KeyCodes.ENTER[0], target: {tagName: '', classList: {contains: jest.fn()}, parentElement: {className: ''}}}); current: {
contains: jest.fn(() => true),
} as unknown as HTMLDivElement,
};
instance.onKeyDown({
preventDefault: jest.fn(),
key: Constants.KeyCodes.ENTER[0],
target: {
tagName: '',
classList: {contains: jest.fn()},
parentElement: {className: ''},
},
} as unknown as KeyboardEvent);
expect(submit).toHaveBeenCalledTimes(1); expect(submit).toHaveBeenCalledTimes(1);
expect(submit).toHaveBeenCalledWith('setting'); expect(submit).toHaveBeenCalledWith('setting');
}); });
test('should match snapshot, with new saveTextButton', () => { test('should match snapshot, with new saveTextButton', () => {
const props = {...baseProps, saveButtonText: 'CustomText'}; const props = {...baseProps, saveButtonText: 'CustomText'};
const wrapper = shallow( const wrapper = shallow(<SettingItemMax {...props}/>);
<SettingItemMax {...props}/>,
);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });