2019-12-26 22:10:19 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import AddRequest from '~/performance_bar/components/add_request.vue';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('add request form', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallowMount(AddRequest);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the input on load', () => {
|
|
|
|
expect(wrapper.find('input').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when clicking the button', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.find('button').trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick();
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('shows the form', () => {
|
|
|
|
expect(wrapper.find('input').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when pressing escape', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.find('input').trigger('keyup.esc');
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick();
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the input', () => {
|
|
|
|
expect(wrapper.find('input').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when submitting the form', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.find('input').setValue('http://gitlab.example.com/users/root/calendar.json');
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
wrapper.find('input').trigger('keyup.enter');
|
|
|
|
return wrapper.vm.$nextTick();
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('emits an event to add the request', () => {
|
|
|
|
expect(wrapper.emitted()['add-request']).toBeTruthy();
|
|
|
|
expect(wrapper.emitted()['add-request'][0]).toEqual([
|
|
|
|
'http://gitlab.example.com/users/root/calendar.json',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('hides the input', () => {
|
|
|
|
expect(wrapper.find('input').exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('clears the value for next time', () => {
|
|
|
|
wrapper.find('button').trigger('click');
|
2020-03-13 15:44:24 +05:30
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(wrapper.find('input').text()).toEqual('');
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|