Browse Source

test: Fix test case

pull/23852/head
zombiej 5 years ago
parent
commit
d3e6fd8090
  1. 24
      components/date-picker/__tests__/focus.test.js
  2. 5
      components/form/__tests__/label.test.js
  3. 4
      components/input/__tests__/Password.test.js
  4. 6
      components/input/__tests__/index.test.js
  5. 4
      components/table/__tests__/__snapshots__/demo.test.js.snap
  6. 5
      tests/shared/focusTest.js

24
components/date-picker/__tests__/focus.test.js

@ -18,22 +18,24 @@ describe('DatePicker', () => {
});
it('should focus trigger input after select date in DatePicker', () => {
const wrapper = mount(<DatePicker />);
const wrapper = mount(<DatePicker />, { attachTo: document.body });
openPanel(wrapper);
selectDate(wrapper, moment('2016-11-23'));
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement);
wrapper.unmount();
});
it('should focus trigger input after select date in RangePicker', () => {
const wrapper = mount(<RangePicker />);
const wrapper = mount(<RangePicker />, { attachTo: document.body });
openPanel(wrapper);
selectDate(wrapper, moment('2016-11-23'), 0);
selectDate(wrapper, moment('2016-11-28'), 1);
expect(wrapper.find('.ant-calendar-picker').getDOMNode()).toBe(document.activeElement);
wrapper.unmount();
});
it('should focus trigger input after select date in MonthPicker', () => {
const wrapper = mount(<MonthPicker />);
const wrapper = mount(<MonthPicker />, { attachTo: document.body });
openPanel(wrapper);
wrapper
.find('.ant-calendar-month-panel-month')
@ -44,46 +46,52 @@ describe('DatePicker', () => {
.at(6)
.hasClass('ant-calendar-month-panel-selected-cell');
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement);
wrapper.unmount();
});
it('should focus trigger input after select date in WeekPicker', () => {
const wrapper = mount(<WeekPicker />);
const wrapper = mount(<WeekPicker />, { attachTo: document.body });
openPanel(wrapper);
selectDate(wrapper, moment('2016-11-23'));
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).toBe(document.activeElement);
wrapper.unmount();
});
it('should not auto focus trigger input when open prop is true in DatePicker', () => {
const wrapper = mount(<DatePicker open />);
const wrapper = mount(<DatePicker open />, { attachTo: document.body });
const wrapperInput = mount(<Input />);
wrapperInput.instance().select();
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe(
document.activeElement,
);
wrapper.unmount();
});
it('should not auto focus trigger input when open prop is true in RangePicker', () => {
const wrapper = mount(<RangePicker open />);
const wrapper = mount(<RangePicker open />, { attachTo: document.body });
const wrapperInput = mount(<Input />);
wrapperInput.instance().select();
expect(wrapper.find('.ant-calendar-picker').getDOMNode()).not.toBe(document.activeElement);
wrapper.unmount();
});
it('should not auto focus trigger input when open prop is true in WeekPicker', () => {
const wrapper = mount(<WeekPicker open />);
const wrapper = mount(<WeekPicker open />, { attachTo: document.body });
const wrapperInput = mount(<Input />);
wrapperInput.instance().select();
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe(
document.activeElement,
);
wrapper.unmount();
});
it('should not auto focus trigger input when open prop is true in MonthPicker', () => {
const wrapper = mount(<MonthPicker open />);
const wrapper = mount(<MonthPicker open />, { attachTo: document.body });
const wrapperInput = mount(<Input />);
wrapperInput.instance().select();
expect(wrapper.find('.ant-calendar-picker-input').getDOMNode()).not.toBe(
document.activeElement,
);
wrapper.unmount();
});
});

5
components/form/__tests__/label.test.js

@ -176,6 +176,7 @@ describe('Form', () => {
<Form1 />
<Form2 />
</div>,
{ attachTo: document.body },
);
wrapper
.find('Form label')
@ -197,6 +198,7 @@ describe('Form', () => {
.at(1)
.getDOMNode(),
).toBe(document.activeElement);
wrapper.unmount();
});
// https://github.com/ant-design/ant-design/issues/7693
@ -208,7 +210,7 @@ describe('Form', () => {
</Form.Item>
</Form>
));
const wrapper = mount(<Form1 />);
const wrapper = mount(<Form1 />, { attachTo: document.body });
expect(() => {
wrapper
.find('Form label')
@ -221,6 +223,7 @@ describe('Form', () => {
.at(0)
.getDOMNode(),
).toBe(document.activeElement);
wrapper.unmount();
});
it('should `labelAlign` work in FormItem', () => {

4
components/input/__tests__/Password.test.js

@ -49,7 +49,9 @@ describe('Input.Password', () => {
});
it('should keep focus state', () => {
const wrapper = mount(<Input.Password defaultValue="111" autoFocus />);
const wrapper = mount(<Input.Password defaultValue="111" autoFocus />, {
attachTo: document.body,
});
expect(document.activeElement).toBe(
wrapper
.find('input')

6
components/input/__tests__/index.test.js

@ -299,7 +299,7 @@ describe('Input allowClear', () => {
});
it('should focus input after clear', () => {
const wrapper = mount(<Input allowClear defaultValue="111" />);
const wrapper = mount(<Input allowClear defaultValue="111" />, { attachTo: document.body });
wrapper
.find('.ant-input-clear-icon')
.at(0)
@ -310,6 +310,7 @@ describe('Input allowClear', () => {
.at(0)
.getDOMNode(),
);
wrapper.unmount();
});
['disabled', 'readOnly'].forEach(prop => {
@ -399,7 +400,7 @@ describe('TextArea allowClear', () => {
});
it('should focus textarea after clear', () => {
const wrapper = mount(<TextArea allowClear defaultValue="111" />);
const wrapper = mount(<TextArea allowClear defaultValue="111" />, { attachTo: document.body });
wrapper
.find('.ant-input-textarea-clear-icon')
.at(0)
@ -410,6 +411,7 @@ describe('TextArea allowClear', () => {
.at(0)
.getDOMNode(),
);
wrapper.unmount();
});
it('should not support allowClear when it is disabled', () => {

4
components/table/__tests__/__snapshots__/demo.test.js.snap

@ -11868,7 +11868,6 @@ exports[`renders ./components/table/demo/resizable-column.md correctly 1`] = `
</span>
<span
class="react-resizable-handle react-resizable-handle-se"
style="touch-action:none"
/>
</th>
<th
@ -11890,7 +11889,6 @@ exports[`renders ./components/table/demo/resizable-column.md correctly 1`] = `
</span>
<span
class="react-resizable-handle react-resizable-handle-se"
style="touch-action:none"
/>
</th>
<th
@ -11912,7 +11910,6 @@ exports[`renders ./components/table/demo/resizable-column.md correctly 1`] = `
</span>
<span
class="react-resizable-handle react-resizable-handle-se"
style="touch-action:none"
/>
</th>
<th
@ -11934,7 +11931,6 @@ exports[`renders ./components/table/demo/resizable-column.md correctly 1`] = `
</span>
<span
class="react-resizable-handle react-resizable-handle-se"
style="touch-action:none"
/>
</th>
<th

5
tests/shared/focusTest.js

@ -28,6 +28,7 @@ export default function focusTest(Component) {
wrapper.instance().focus();
jest.runAllTimers();
expect(handleFocus).toHaveBeenCalled();
wrapper.unmount();
});
it('blur() and onBlur', () => {
@ -38,13 +39,15 @@ export default function focusTest(Component) {
wrapper.instance().blur();
jest.runAllTimers();
expect(handleBlur).toHaveBeenCalled();
wrapper.unmount();
});
it('autoFocus', () => {
const handleFocus = jest.fn();
mount(<Component autoFocus onFocus={handleFocus} />, { attachTo: container });
const wrapper = mount(<Component autoFocus onFocus={handleFocus} />, { attachTo: container });
jest.runAllTimers();
expect(handleFocus).toHaveBeenCalled();
wrapper.unmount();
});
});
}

Loading…
Cancel
Save