import React from 'react'; import Tabs from '..'; import { resetWarned } from '../../_util/warning'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; import { fireEvent, render } from '../../../tests/utils'; import ConfigProvider from '../../config-provider'; const { TabPane } = Tabs; describe('Tabs', () => { mountTest(() => ( )); rtlTest(() => ( )); describe('editable-card', () => { let handleEdit: jest.Mock; let wrapper: ReturnType['container']; beforeEach(() => { handleEdit = jest.fn(); const { container } = render( foo {undefined} {null} {false} , ); wrapper = container; }); it('add card', () => { fireEvent.click(wrapper.querySelector('.ant-tabs-nav-add')!); expect(handleEdit.mock.calls[0][1]).toBe('add'); }); it('remove card', () => { fireEvent.click(wrapper.querySelector('.anticon-close')!); expect(handleEdit).toHaveBeenCalledWith('1', 'remove'); }); it('validateElement', () => { expect(wrapper.querySelectorAll('.ant-tabs-tab').length).toBe(1); }); }); describe('tabPosition', () => { it('remove card', () => { const { container } = render( foo , ); expect(container.firstChild).toMatchSnapshot(); }); }); describe('renderTabBar', () => { it('custom-tab-bar', () => { const { container } = render(
custom-tab-bar
}> foo
, ); expect(container.firstChild).toMatchSnapshot(); }); }); it('warning for onNextClick', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const onNextClick = { onNextClick() {} } as any; render(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tabs] `onPrevClick` and `onNextClick` has been removed. Please use `onTabScroll` instead.', ); errorSpy.mockRestore(); }); it('tabBarGutter should work', () => { const { container: wrapper } = render( , ); expect(wrapper.firstChild).toMatchSnapshot(); const { container: wrapper2 } = render( , ); expect(wrapper2.firstChild).toMatchSnapshot(); }); it('deprecated warning', () => { resetWarned(); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); const { container } = render( invalidate , ); expect(container.querySelectorAll('.ant-tabs-tab')).toHaveLength(1); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tabs] `Tabs.TabPane` is deprecated. Please use `items` instead.', ); errorSpy.mockRestore(); }); it('indicator in ConfigProvider should work', () => { const { container } = render( , ); expect(container.querySelector('.Tabs_1 .ant-tabs-ink-bar')).toHaveStyle({ width: 12 }); expect(container.querySelector('.Tabs_2 .ant-tabs-ink-bar')).toHaveStyle({ width: 12 }); expect(container.querySelector('.Tabs_3 .ant-tabs-ink-bar')).toHaveStyle({ width: 4 }); }); it('warning for indicatorSize', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); render(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Tabs] `indicatorSize` has been deprecated. Please use `indicator={{ size: ... }}` instead.', ); errorSpy.mockRestore(); }); });