2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Alert from '..';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
describe('Alert', () => {
|
|
|
|
beforeAll(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
afterAll(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('could be closed', () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onClose = jest.fn();
|
|
|
|
const afterClose = jest.fn();
|
2018-09-05 13:28:54 +00:00
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Alert
|
|
|
|
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
|
|
|
|
type="warning"
|
|
|
|
closable
|
|
|
|
onClose={onClose}
|
|
|
|
afterClose={afterClose}
|
|
|
|
ref="alert"
|
|
|
|
/>
|
|
|
|
);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
wrapper.find('.ant-alert-close-icon').trigger('click');
|
|
|
|
expect(onClose).toBeCalled();
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.vm.$refs.alert.animationEnd();
|
|
|
|
expect(afterClose).toBeCalled();
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
describe('data and aria props', () => {
|
|
|
|
it('sets data attributes on input', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Alert data-test="test-id" data-id="12345" />;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
const input = wrapper.find('.ant-alert').element;
|
|
|
|
expect(input.getAttribute('data-test')).toBe('test-id');
|
|
|
|
expect(input.getAttribute('data-id')).toBe('12345');
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('sets aria attributes on input', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Alert aria-describedby="some-label" />;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const input = wrapper.find('.ant-alert').element;
|
|
|
|
expect(input.getAttribute('aria-describedby')).toBe('some-label');
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
it('sets role attribute on input', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <Alert role="status" />;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const input = wrapper.find('.ant-alert').element;
|
|
|
|
expect(input.getAttribute('role')).toBe('status');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|