Commit 578d8700 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'xanf-vtu-30-trigger' into 'master'

Wrap trigger into nextTick calls

Closes #192019

See merge request gitlab-org/gitlab!22324
parents 88b4580b 8be8343a
...@@ -27,8 +27,10 @@ describe('AddStageButton', () => { ...@@ -27,8 +27,10 @@ describe('AddStageButton', () => {
wrapper = createComponent(); wrapper = createComponent();
expect(wrapper.emitted().showform).toBeUndefined(); expect(wrapper.emitted().showform).toBeUndefined();
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().showform.length).toBe(1); expect(wrapper.emitted().showform.length).toBe(1);
}); });
});
it('does not have the active class', () => { it('does not have the active class', () => {
expect(wrapper.classes('active')).toBe(false); expect(wrapper.classes('active')).toBe(false);
......
...@@ -362,6 +362,7 @@ describe('CustomStageForm', () => { ...@@ -362,6 +362,7 @@ describe('CustomStageForm', () => {
return Vue.nextTick(() => { return Vue.nextTick(() => {
selectDropdownOption(wrapper, sel.endEvent, 1); selectDropdownOption(wrapper, sel.endEvent, 1);
return Vue.nextTick();
}); });
}); });
...@@ -394,9 +395,14 @@ describe('CustomStageForm', () => { ...@@ -394,9 +395,14 @@ describe('CustomStageForm', () => {
selectDropdownOption(wrapper, sel.startEvent, startEventIndex); selectDropdownOption(wrapper, sel.startEvent, startEventIndex);
return Vue.nextTick(() => { return Vue.nextTick()
.then(() => {
selectDropdownOption(wrapper, sel.endEvent, stopEventIndex); selectDropdownOption(wrapper, sel.endEvent, stopEventIndex);
return Vue.nextTick();
})
.then(() => {
wrapper.find(sel.name).setValue('Cool stage'); wrapper.find(sel.name).setValue('Cool stage');
return Vue.nextTick();
}); });
}); });
...@@ -437,11 +443,13 @@ describe('CustomStageForm', () => { ...@@ -437,11 +443,13 @@ describe('CustomStageForm', () => {
]; ];
wrapper.find(sel.submit).trigger('click'); wrapper.find(sel.submit).trigger('click');
return Vue.nextTick().then(() => {
event = findEvent(STAGE_ACTIONS.CREATE); event = findEvent(STAGE_ACTIONS.CREATE);
expect(event[0]).toEqual(res); expect(event[0]).toEqual(res);
}); });
}); });
}); });
});
describe('Cancel button', () => { describe('Cancel button', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -50,9 +50,11 @@ describe('Cycle Analytics LabelsSelector', () => { ...@@ -50,9 +50,11 @@ describe('Cycle Analytics LabelsSelector', () => {
const elem = wrapper.findAll('.dropdown-item').at(2); const elem = wrapper.findAll('.dropdown-item').at(2);
elem.trigger('click'); elem.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('selectLabel').length > 0).toBe(true); expect(wrapper.emitted('selectLabel').length > 0).toBe(true);
expect(wrapper.emitted('selectLabel')[0]).toContain(groupLabels[1].id); expect(wrapper.emitted('selectLabel')[0]).toContain(groupLabels[1].id);
}); });
});
it('will emit the "clearLabel" event if it is the default item', () => { it('will emit the "clearLabel" event if it is the default item', () => {
expect(wrapper.emitted('clearLabel')).toBeUndefined(); expect(wrapper.emitted('clearLabel')).toBeUndefined();
...@@ -60,10 +62,12 @@ describe('Cycle Analytics LabelsSelector', () => { ...@@ -60,10 +62,12 @@ describe('Cycle Analytics LabelsSelector', () => {
const elem = wrapper.findAll('.dropdown-item').at(0); const elem = wrapper.findAll('.dropdown-item').at(0);
elem.trigger('click'); elem.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('clearLabel').length > 0).toBe(true); expect(wrapper.emitted('clearLabel').length > 0).toBe(true);
}); });
}); });
}); });
});
describe('with selectedLabelId set', () => { describe('with selectedLabelId set', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -62,6 +62,7 @@ describe('StageDropdownFilter component', () => { ...@@ -62,6 +62,7 @@ describe('StageDropdownFilter component', () => {
item.trigger('click'); item.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -70,6 +71,7 @@ describe('StageDropdownFilter component', () => { ...@@ -70,6 +71,7 @@ describe('StageDropdownFilter component', () => {
]); ]);
}); });
}); });
});
describe('clicking a deselected stage', () => { describe('clicking a deselected stage', () => {
it('should add to selection', () => { it('should add to selection', () => {
...@@ -77,10 +79,15 @@ describe('StageDropdownFilter component', () => { ...@@ -77,10 +79,15 @@ describe('StageDropdownFilter component', () => {
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
findDropdownItems() findDropdownItems()
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -94,4 +101,5 @@ describe('StageDropdownFilter component', () => { ...@@ -94,4 +101,5 @@ describe('StageDropdownFilter component', () => {
}); });
}); });
}); });
});
}); });
...@@ -57,6 +57,7 @@ describe('Daterange component', () => { ...@@ -57,6 +57,7 @@ describe('Daterange component', () => {
input.setValue('2019-01-01'); input.setValue('2019-01-01');
input.trigger('change'); input.trigger('change');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'change', name: 'change',
...@@ -66,6 +67,7 @@ describe('Daterange component', () => { ...@@ -66,6 +67,7 @@ describe('Daterange component', () => {
}); });
}); });
}); });
});
describe('computed', () => { describe('computed', () => {
describe('dateRange', () => { describe('dateRange', () => {
......
...@@ -142,6 +142,7 @@ describe('GroupsDropdownFilter component', () => { ...@@ -142,6 +142,7 @@ describe('GroupsDropdownFilter component', () => {
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -149,12 +150,14 @@ describe('GroupsDropdownFilter component', () => { ...@@ -149,12 +150,14 @@ describe('GroupsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('should change selection when new group is clicked', () => { it('should change selection when new group is clicked', () => {
findDropdownItems() findDropdownItems()
.at(1) .at(1)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -162,6 +165,7 @@ describe('GroupsDropdownFilter component', () => { ...@@ -162,6 +165,7 @@ describe('GroupsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('renders an avatar in the dropdown button when the group has an avatar_url', done => { it('renders an avatar in the dropdown button when the group has an avatar_url', done => {
findDropdownItems() findDropdownItems()
......
...@@ -175,6 +175,7 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -175,6 +175,7 @@ describe('ProjectsDropdownFilter component', () => {
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -182,12 +183,14 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -182,12 +183,14 @@ describe('ProjectsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('should change selection when new project is clicked', () => { it('should change selection when new project is clicked', () => {
findDropdownItems() findDropdownItems()
.at(1) .at(1)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -195,12 +198,14 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -195,12 +198,14 @@ describe('ProjectsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('selection should be emptied when a project is deselected', () => { it('selection should be emptied when a project is deselected', () => {
const project = findDropdownItems().at(0); const project = findDropdownItems().at(0);
project.trigger('click'); project.trigger('click');
project.trigger('click'); project.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -212,6 +217,7 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -212,6 +217,7 @@ describe('ProjectsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('renders an avatar in the dropdown button when the project has an avatar_url', done => { it('renders an avatar in the dropdown button when the project has an avatar_url', done => {
findDropdownItems() findDropdownItems()
...@@ -294,10 +300,15 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -294,10 +300,15 @@ describe('ProjectsDropdownFilter component', () => {
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
findDropdownItems() findDropdownItems()
.at(1) .at(1)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -309,6 +320,7 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -309,6 +320,7 @@ describe('ProjectsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('should remove from selection when clicked again', () => { it('should remove from selection when clicked again', () => {
const item = findDropdownItems().at(0); const item = findDropdownItems().at(0);
...@@ -316,6 +328,7 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -316,6 +328,7 @@ describe('ProjectsDropdownFilter component', () => {
item.trigger('click'); item.trigger('click');
item.trigger('click'); item.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
...@@ -327,17 +340,21 @@ describe('ProjectsDropdownFilter component', () => { ...@@ -327,17 +340,21 @@ describe('ProjectsDropdownFilter component', () => {
}, },
]); ]);
}); });
});
it('renders the correct placeholder text when multiple projects are selected', done => { it('renders the correct placeholder text when multiple projects are selected', done => {
findDropdownItems() findDropdownItems()
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
findDropdownItems() findDropdownItems()
.at(1) .at(1)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick();
wrapper.vm.$nextTick(() => { })
.then(() => {
expect(findDropdownButton().text()).toBe('2 projects selected'); expect(findDropdownButton().text()).toBe('2 projects selected');
done(); done();
}); });
......
...@@ -45,17 +45,21 @@ describe('Design reply form component', () => { ...@@ -45,17 +45,21 @@ describe('Design reply form component', () => {
ctrlKey: true, ctrlKey: true,
}); });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeFalsy(); expect(wrapper.emitted('submitForm')).toBeFalsy();
}); });
});
it('does not emit submitForm event on textarea meta+enter keydown', () => { it('does not emit submitForm event on textarea meta+enter keydown', () => {
findTextarea().trigger('keydown.enter', { findTextarea().trigger('keydown.enter', {
metaKey: true, metaKey: true,
}); });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeFalsy(); expect(wrapper.emitted('submitForm')).toBeFalsy();
}); });
}); });
});
describe('when form has text', () => { describe('when form has text', () => {
beforeEach(() => { beforeEach(() => {
...@@ -71,35 +75,45 @@ describe('Design reply form component', () => { ...@@ -71,35 +75,45 @@ describe('Design reply form component', () => {
it('emits submitForm event on button click', () => { it('emits submitForm event on button click', () => {
findSubmitButton().trigger('click'); findSubmitButton().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeTruthy(); expect(wrapper.emitted('submitForm')).toBeTruthy();
}); });
});
it('emits submitForm event on textarea ctrl+enter keydown', () => { it('emits submitForm event on textarea ctrl+enter keydown', () => {
findTextarea().trigger('keydown.enter', { findTextarea().trigger('keydown.enter', {
ctrlKey: true, ctrlKey: true,
}); });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeTruthy(); expect(wrapper.emitted('submitForm')).toBeTruthy();
}); });
});
it('emits submitForm event on textarea meta+enter keydown', () => { it('emits submitForm event on textarea meta+enter keydown', () => {
findTextarea().trigger('keydown.enter', { findTextarea().trigger('keydown.enter', {
metaKey: true, metaKey: true,
}); });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('submitForm')).toBeTruthy(); expect(wrapper.emitted('submitForm')).toBeTruthy();
}); });
});
it('emits input event on changing textarea content', () => { it('emits input event on changing textarea content', () => {
findTextarea().setValue('test2'); findTextarea().setValue('test2');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('input')).toBeTruthy(); expect(wrapper.emitted('input')).toBeTruthy();
}); });
});
it('emits cancelForm event on pressing escape button on textarea', () => { it('emits cancelForm event on pressing escape button on textarea', () => {
findTextarea().trigger('keyup.esc'); findTextarea().trigger('keyup.esc');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('cancelForm')).toBeTruthy(); expect(wrapper.emitted('cancelForm')).toBeTruthy();
}); });
}); });
});
}); });
...@@ -53,8 +53,10 @@ describe('Design overlay component', () => { ...@@ -53,8 +53,10 @@ describe('Design overlay component', () => {
createComponent(); createComponent();
wrapper.find('.image-diff-overlay-add-comment').trigger('click', { offsetX: 10, offsetY: 10 }); wrapper.find('.image-diff-overlay-add-comment').trigger('click', { offsetX: 10, offsetY: 10 });
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('openCommentForm')).toEqual([[{ x: 10, y: 10 }]]); expect(wrapper.emitted('openCommentForm')).toEqual([[{ x: 10, y: 10 }]]);
}); });
});
describe('when has notes', () => { describe('when has notes', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -322,11 +322,17 @@ describe('Design management index page', () => { ...@@ -322,11 +322,17 @@ describe('Design management index page', () => {
findDesignCheckboxes() findDesignCheckboxes()
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
findDesignCheckboxes() findDesignCheckboxes()
.at(1) .at(1)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick();
})
.then(() => {
expect(findDeleteButton().exists()).toBe(true); expect(findDeleteButton().exists()).toBe(true);
expect(findSelectAllButton().text()).toBe('Deselect all'); expect(findSelectAllButton().text()).toBe('Deselect all');
findDeleteButton().vm.$emit('deleteSelectedDesigns'); findDeleteButton().vm.$emit('deleteSelectedDesigns');
...@@ -352,9 +358,13 @@ describe('Design management index page', () => { ...@@ -352,9 +358,13 @@ describe('Design management index page', () => {
findDesignCheckboxes() findDesignCheckboxes()
.at(0) .at(0)
.trigger('click'); .trigger('click');
findSelectAllButton().vm.$emit('click');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm
.$nextTick()
.then(() => {
findSelectAllButton().vm.$emit('click');
})
.then(() => {
expect(findDeleteButton().props().hasSelectedDesigns).toBe(false); expect(findDeleteButton().props().hasSelectedDesigns).toBe(false);
expect(findSelectAllButton().text()).toBe('Select all'); expect(findSelectAllButton().text()).toBe('Select all');
expect(wrapper.vm.selectedDesigns).toEqual([]); expect(wrapper.vm.selectedDesigns).toEqual([]);
......
...@@ -109,6 +109,7 @@ describe('dashboard', () => { ...@@ -109,6 +109,7 @@ describe('dashboard', () => {
describe('project selector modal', () => { describe('project selector modal', () => {
beforeEach(() => { beforeEach(() => {
wrapper.find(GlButton).trigger('click'); wrapper.find(GlButton).trigger('click');
return wrapper.vm.$nextTick();
}); });
it('should fire the add projects action on ok', () => { it('should fire the add projects action on ok', () => {
......
...@@ -200,8 +200,11 @@ describe('SidebarDatePicker', () => { ...@@ -200,8 +200,11 @@ describe('SidebarDatePicker', () => {
createComponent({ canUpdate: true }); createComponent({ canUpdate: true });
wrapper.find('input').trigger('click'); wrapper.find('input').trigger('click');
return wrapper.vm.$nextTick(() => {
expect(wrapper.emitted().toggleDateType).toStrictEqual([[true]]); expect(wrapper.emitted().toggleDateType).toStrictEqual([[true]]);
}); });
});
it('emits `toggleCollapse` event when toggle-sidebar emits `toggle` event', () => { it('emits `toggleCollapse` event when toggle-sidebar emits `toggle` event', () => {
createComponent({ showToggleSidebar: true }); createComponent({ showToggleSidebar: true });
......
...@@ -303,25 +303,33 @@ describe('feature flag form', () => { ...@@ -303,25 +303,33 @@ describe('feature flag form', () => {
it('should emit handleSubmit with the updated data', () => { it('should emit handleSubmit with the updated data', () => {
wrapper.find('#feature-flag-name').setValue('feature_flag_2'); wrapper.find('#feature-flag-name').setValue('feature_flag_2');
return wrapper.vm
.$nextTick()
.then(() => {
wrapper wrapper
.find('.js-new-scope-name') .find('.js-new-scope-name')
.find(EnvironmentsDropdown) .find(EnvironmentsDropdown)
.vm.$emit('selectEnvironment', 'review'); .vm.$emit('selectEnvironment', 'review');
return wrapper.vm.$nextTick();
})
.then(() => {
wrapper wrapper
.find('.js-add-new-scope') .find('.js-add-new-scope')
.find(ToggleButton) .find(ToggleButton)
.vm.$emit('change', true); .vm.$emit('change', true);
})
.then(() => {
wrapper.find(ToggleButton).vm.$emit('change', true); wrapper.find(ToggleButton).vm.$emit('change', true);
return wrapper.vm.$nextTick();
return wrapper.vm })
.$nextTick()
.then(() => { .then(() => {
selectFirstRolloutStrategyOption(0); selectFirstRolloutStrategyOption(0);
return wrapper.vm.$nextTick();
})
.then(() => {
selectFirstRolloutStrategyOption(2); selectFirstRolloutStrategyOption(2);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}) })
.then(() => { .then(() => {
......
...@@ -66,10 +66,12 @@ describe('EE IDE TerminalSession', () => { ...@@ -66,10 +66,12 @@ describe('EE IDE TerminalSession', () => {
const button = wrapper.find('button'); const button = wrapper.find('button');
button.trigger('click'); button.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(button.text()).toEqual('Stop Terminal'); expect(button.text()).toEqual('Stop Terminal');
expect(actions.stopSession).toHaveBeenCalled(); expect(actions.stopSession).toHaveBeenCalled();
}); });
}); });
});
[STOPPING, STOPPED].forEach(status => { [STOPPING, STOPPED].forEach(status => {
it(`show stop button when status is ${status}`, () => { it(`show stop button when status is ${status}`, () => {
...@@ -79,8 +81,10 @@ describe('EE IDE TerminalSession', () => { ...@@ -79,8 +81,10 @@ describe('EE IDE TerminalSession', () => {
const button = wrapper.find('button'); const button = wrapper.find('button');
button.trigger('click'); button.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(button.text()).toEqual('Restart Terminal'); expect(button.text()).toEqual('Restart Terminal');
expect(actions.restartSession).toHaveBeenCalled(); expect(actions.restartSession).toHaveBeenCalled();
}); });
}); });
});
}); });
...@@ -102,11 +102,16 @@ describe('MavenInstallation', () => { ...@@ -102,11 +102,16 @@ describe('MavenInstallation', () => {
it('should track when the installation tab is clicked', () => { it('should track when the installation tab is clicked', () => {
setupTab().trigger('click'); setupTab().trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
installationTab().trigger('click'); installationTab().trigger('click');
})
.then(() => {
expect(eventSpy).toHaveBeenCalledWith(undefined, TrackingActions.INSTALLATION, { expect(eventSpy).toHaveBeenCalledWith(undefined, TrackingActions.INSTALLATION, {
label, label,
}); });
}); });
}); });
});
}); });
...@@ -97,11 +97,17 @@ describe('NpmInstallation', () => { ...@@ -97,11 +97,17 @@ describe('NpmInstallation', () => {
it('should track when the installation tab is clicked', () => { it('should track when the installation tab is clicked', () => {
setupTab().trigger('click'); setupTab().trigger('click');
installationTab().trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
installationTab().trigger('click');
})
.then(() => {
expect(eventSpy).toHaveBeenCalledWith(undefined, TrackingActions.INSTALLATION, { expect(eventSpy).toHaveBeenCalledWith(undefined, TrackingActions.INSTALLATION, {
label, label,
}); });
}); });
}); });
});
}); });
...@@ -81,9 +81,11 @@ describe('RelatedIssuableInput', () => { ...@@ -81,9 +81,11 @@ describe('RelatedIssuableInput', () => {
wrapper.find('li').trigger('click'); wrapper.find('li').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(document.activeElement).toBe(wrapper.find({ ref: 'input' }).element); expect(document.activeElement).toBe(wrapper.find({ ref: 'input' }).element);
}); });
}); });
});
describe('when filling in the input', () => { describe('when filling in the input', () => {
it('emits addIssuableFormInput with data', () => { it('emits addIssuableFormInput with data', () => {
......
...@@ -95,7 +95,9 @@ describe('Project List component', () => { ...@@ -95,7 +95,9 @@ describe('Project List component', () => {
getFirstRemoveButton().trigger('click'); getFirstRemoveButton().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('projectRemoved')).toHaveLength(1); expect(wrapper.emitted('projectRemoved')).toHaveLength(1);
expect(wrapper.emitted('projectRemoved')).toEqual([[projectData]]); expect(wrapper.emitted('projectRemoved')).toEqual([[projectData]]);
}); });
});
}); });
...@@ -146,9 +146,11 @@ describe('EE MRWidget approvals footer', () => { ...@@ -146,9 +146,11 @@ describe('EE MRWidget approvals footer', () => {
button.trigger('click'); button.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emittedByOrder()).toEqual([{ name: 'input', args: [true] }]); expect(wrapper.emittedByOrder()).toEqual([{ name: 'input', args: [true] }]);
}); });
}); });
});
it('renders avatar list', () => { it('renders avatar list', () => {
const avatars = findAvatars(); const avatars = findAvatars();
......
...@@ -223,16 +223,19 @@ describe('ReadyToMerge', () => { ...@@ -223,16 +223,19 @@ describe('ReadyToMerge', () => {
dialog.vm.show = jest.fn(); dialog.vm.show = jest.fn();
vm.handleMergeButtonClick = jest.fn(); vm.handleMergeButtonClick = jest.fn();
findMergeButtonDropdown().trigger('click'); findMergeButtonDropdown().trigger('click');
return wrapper.vm.$nextTick().then(() => {
findMergeImmediatelyButton().trigger('click'); findMergeImmediatelyButton().trigger('click');
return wrapper.vm.$nextTick();
});
}; };
it('should show a warning dialog asking for confirmation if the user is trying to skip the merge train', () => { it('should show a warning dialog asking for confirmation if the user is trying to skip the merge train', () => {
factory({ preferredAutoMergeStrategy: MT_MERGE_STRATEGY }); factory({ preferredAutoMergeStrategy: MT_MERGE_STRATEGY });
clickMergeImmediately(); return clickMergeImmediately().then(() => {
expect(dialog.vm.show).toHaveBeenCalled(); expect(dialog.vm.show).toHaveBeenCalled();
expect(vm.handleMergeButtonClick).not.toHaveBeenCalled(); expect(vm.handleMergeButtonClick).not.toHaveBeenCalled();
}); });
});
it('should perform the merge when the user confirms their intent to merge immediately', () => { it('should perform the merge when the user confirms their intent to merge immediately', () => {
factory({ preferredAutoMergeStrategy: MT_MERGE_STRATEGY }); factory({ preferredAutoMergeStrategy: MT_MERGE_STRATEGY });
...@@ -245,12 +248,12 @@ describe('ReadyToMerge', () => { ...@@ -245,12 +248,12 @@ describe('ReadyToMerge', () => {
it('should not ask for confirmation in non-merge train scenarios', () => { it('should not ask for confirmation in non-merge train scenarios', () => {
factory({ isPipelineActive: true, onlyAllowMergeIfPipelineSucceeds: false }); factory({ isPipelineActive: true, onlyAllowMergeIfPipelineSucceeds: false });
clickMergeImmediately(); return clickMergeImmediately().then(() => {
expect(dialog.vm.show).not.toHaveBeenCalled(); expect(dialog.vm.show).not.toHaveBeenCalled();
expect(vm.handleMergeButtonClick).toHaveBeenCalled(); expect(vm.handleMergeButtonClick).toHaveBeenCalled();
}); });
}); });
});
describe('cannot merge', () => { describe('cannot merge', () => {
describe('when isMergeAllowed=false', () => { describe('when isMergeAllowed=false', () => {
......
...@@ -23,8 +23,10 @@ describe('DismissalButton', () => { ...@@ -23,8 +23,10 @@ describe('DismissalButton', () => {
it('should emit dismiss vulnerabilty when clicked', () => { it('should emit dismiss vulnerabilty when clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().dismissVulnerability).toBeTruthy(); expect(wrapper.emitted().dismissVulnerability).toBeTruthy();
}); });
});
it('should render the dismiss with comment button', () => { it('should render the dismiss with comment button', () => {
expect(wrapper.find('.js-dismiss-with-comment').exists()).toBe(true); expect(wrapper.find('.js-dismiss-with-comment').exists()).toBe(true);
...@@ -32,9 +34,11 @@ describe('DismissalButton', () => { ...@@ -32,9 +34,11 @@ describe('DismissalButton', () => {
it('should emit openDismissalCommentBox when clicked', () => { it('should emit openDismissalCommentBox when clicked', () => {
wrapper.find('.js-dismiss-with-comment').trigger('click'); wrapper.find('.js-dismiss-with-comment').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().openDismissalCommentBox).toBeTruthy(); expect(wrapper.emitted().openDismissalCommentBox).toBeTruthy();
}); });
}); });
});
describe('with a dismissed vulnerability', () => { describe('with a dismissed vulnerability', () => {
beforeEach(() => { beforeEach(() => {
...@@ -50,8 +54,10 @@ describe('DismissalButton', () => { ...@@ -50,8 +54,10 @@ describe('DismissalButton', () => {
it('should emit revertDismissVulnerabilty when clicked', () => { it('should emit revertDismissVulnerabilty when clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().revertDismissVulnerability).toBeTruthy(); expect(wrapper.emitted().revertDismissVulnerability).toBeTruthy();
}); });
});
it('should not render the dismiss with comment button', () => { it('should not render the dismiss with comment button', () => {
expect(wrapper.find('.js-dismiss-with-comment').exists()).toBe(false); expect(wrapper.find('.js-dismiss-with-comment').exists()).toBe(false);
......
...@@ -23,8 +23,10 @@ describe('DismissalCommentBox', () => { ...@@ -23,8 +23,10 @@ describe('DismissalCommentBox', () => {
metaKey: true, metaKey: true,
}); });
return wrapper.vm.$nextTick(() => {
expect(wrapper.emitted().submit).toBeTruthy(); expect(wrapper.emitted().submit).toBeTruthy();
}); });
});
it('should render the error message', () => { it('should render the error message', () => {
const errorMessage = 'You did something wrong'; const errorMessage = 'You did something wrong';
......
...@@ -31,18 +31,23 @@ describe('DismissalCommentModalFooter', () => { ...@@ -31,18 +31,23 @@ describe('DismissalCommentModalFooter', () => {
it('should emit the "addCommentAndDismiss" event when clicked', () => { it('should emit the "addCommentAndDismiss" event when clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().addCommentAndDismiss).toBeTruthy(); expect(wrapper.emitted().addCommentAndDismiss).toBeTruthy();
expect(Tracking.event).toHaveBeenCalledWith( expect(Tracking.event).toHaveBeenCalledWith(
'_track_category_', '_track_category_',
'click_add_comment_and_dismiss', 'click_add_comment_and_dismiss',
); );
}); });
});
it('should emit the cancel event when the cancel button is clicked', () => { it('should emit the cancel event when the cancel button is clicked', () => {
wrapper.find('.js-cancel').trigger('click'); wrapper.find('.js-cancel').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().cancel).toBeTruthy(); expect(wrapper.emitted().cancel).toBeTruthy();
}); });
}); });
});
describe('with an already dismissed vulnerability', () => { describe('with an already dismissed vulnerability', () => {
describe('and adding a comment', () => { describe('and adding a comment', () => {
...@@ -60,10 +65,12 @@ describe('DismissalCommentModalFooter', () => { ...@@ -60,10 +65,12 @@ describe('DismissalCommentModalFooter', () => {
it('should emit the "addCommentAndDismiss" event when clicked', () => { it('should emit the "addCommentAndDismiss" event when clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().addDismissalComment).toBeTruthy(); expect(wrapper.emitted().addDismissalComment).toBeTruthy();
expect(Tracking.event).toHaveBeenCalledWith('_track_category_', 'click_add_comment'); expect(Tracking.event).toHaveBeenCalledWith('_track_category_', 'click_add_comment');
}); });
}); });
});
describe('and editing a comment', () => { describe('and editing a comment', () => {
beforeEach(() => { beforeEach(() => {
...@@ -81,9 +88,11 @@ describe('DismissalCommentModalFooter', () => { ...@@ -81,9 +88,11 @@ describe('DismissalCommentModalFooter', () => {
it('should emit the "addCommentAndDismiss" event when clicked', () => { it('should emit the "addCommentAndDismiss" event when clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().addDismissalComment).toBeTruthy(); expect(wrapper.emitted().addDismissalComment).toBeTruthy();
expect(Tracking.event).toHaveBeenCalledWith('_track_category_', 'click_edit_comment'); expect(Tracking.event).toHaveBeenCalledWith('_track_category_', 'click_edit_comment');
}); });
}); });
}); });
});
}); });
...@@ -84,10 +84,16 @@ describe('Event Item', () => { ...@@ -84,10 +84,16 @@ describe('Event Item', () => {
it('emits the button events when clicked', () => { it('emits the button events when clicked', () => {
const buttons = wrapper.findAll('.action-buttons > button'); const buttons = wrapper.findAll('.action-buttons > button');
buttons.at(0).trigger('click'); buttons.at(0).trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
buttons.at(1).trigger('click'); buttons.at(1).trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.emitted().fooEvent.length).toEqual(1); expect(wrapper.emitted().fooEvent.length).toEqual(1);
expect(wrapper.emitted().barEvent.length).toEqual(1); expect(wrapper.emitted().barEvent.length).toEqual(1);
}); });
}); });
});
}); });
...@@ -32,9 +32,12 @@ describe('Security Reports modal footer', () => { ...@@ -32,9 +32,12 @@ describe('Security Reports modal footer', () => {
it('emits createIssue when create issue button is clicked', () => { it('emits createIssue when create issue button is clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().createNewIssue).toBeTruthy(); expect(wrapper.emitted().createNewIssue).toBeTruthy();
}); });
}); });
});
describe('can only create merge request', () => { describe('can only create merge request', () => {
beforeEach(() => { beforeEach(() => {
...@@ -52,9 +55,12 @@ describe('Security Reports modal footer', () => { ...@@ -52,9 +55,12 @@ describe('Security Reports modal footer', () => {
it('emits createMergeRequest when create merge request button is clicked', () => { it('emits createMergeRequest when create merge request button is clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().createMergeRequest).toBeTruthy(); expect(wrapper.emitted().createMergeRequest).toBeTruthy();
}); });
}); });
});
describe('can download download patch', () => { describe('can download download patch', () => {
beforeEach(() => { beforeEach(() => {
...@@ -72,9 +78,12 @@ describe('Security Reports modal footer', () => { ...@@ -72,9 +78,12 @@ describe('Security Reports modal footer', () => {
it('emits downloadPatch when download patch button is clicked', () => { it('emits downloadPatch when download patch button is clicked', () => {
wrapper.find(LoadingButton).trigger('click'); wrapper.find(LoadingButton).trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().downloadPatch).toBeTruthy(); expect(wrapper.emitted().downloadPatch).toBeTruthy();
}); });
}); });
});
describe('can create merge request and issue', () => { describe('can create merge request and issue', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -61,10 +61,15 @@ describe('ClusterFormDropdown', () => { ...@@ -61,10 +61,15 @@ describe('ClusterFormDropdown', () => {
beforeEach(() => { beforeEach(() => {
vm.setProps({ items, multiple: true, value }); vm.setProps({ items, multiple: true, value });
return vm.vm.$nextTick().then(() => { return vm.vm
.$nextTick()
.then(() => {
vm.findAll('.js-dropdown-item') vm.findAll('.js-dropdown-item')
.at(0) .at(0)
.trigger('click'); .trigger('click');
return vm.vm.$nextTick();
})
.then(() => {
vm.findAll('.js-dropdown-item') vm.findAll('.js-dropdown-item')
.at(1) .at(1)
.trigger('click'); .trigger('click');
......
...@@ -92,9 +92,11 @@ describe('StageNavItem', () => { ...@@ -92,9 +92,11 @@ describe('StageNavItem', () => {
it('emits the `select` event when clicked', () => { it('emits the `select` event when clicked', () => {
expect(wrapper.emitted().select).toBeUndefined(); expect(wrapper.emitted().select).toBeUndefined();
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick(() => {
expect(wrapper.emitted().select.length).toBe(1); expect(wrapper.emitted().select.length).toBe(1);
}); });
}); });
});
describe('User does not have access', () => { describe('User does not have access', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -117,8 +117,11 @@ describe('DiffFileHeader component', () => { ...@@ -117,8 +117,11 @@ describe('DiffFileHeader component', () => {
it('when header is clicked emits toggleFile', () => { it('when header is clicked emits toggleFile', () => {
createComponent(); createComponent();
findHeader().trigger('click'); findHeader().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleFile).toBeDefined(); expect(wrapper.emitted().toggleFile).toBeDefined();
}); });
});
it('when collapseIcon is clicked emits toggleFile', () => { it('when collapseIcon is clicked emits toggleFile', () => {
createComponent({ collapsible: true }); createComponent({ collapsible: true });
...@@ -129,8 +132,11 @@ describe('DiffFileHeader component', () => { ...@@ -129,8 +132,11 @@ describe('DiffFileHeader component', () => {
it('when other element in header is clicked does not emits toggleFile', () => { it('when other element in header is clicked does not emits toggleFile', () => {
createComponent({ collapsible: true }); createComponent({ collapsible: true });
findTitleLink().trigger('click'); findTitleLink().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleFile).not.toBeDefined(); expect(wrapper.emitted().toggleFile).not.toBeDefined();
}); });
});
it('displays a copy to clipboard button', () => { it('displays a copy to clipboard button', () => {
createComponent(); createComponent();
......
...@@ -42,9 +42,11 @@ describe('DiffGutterAvatars', () => { ...@@ -42,9 +42,11 @@ describe('DiffGutterAvatars', () => {
it('should emit toggleDiscussions event on button click', () => { it('should emit toggleDiscussions event on button click', () => {
findCollapseButton().trigger('click'); findCollapseButton().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy(); expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
}); });
}); });
});
describe('when collapsed', () => { describe('when collapsed', () => {
beforeEach(() => { beforeEach(() => {
...@@ -72,15 +74,19 @@ describe('DiffGutterAvatars', () => { ...@@ -72,15 +74,19 @@ describe('DiffGutterAvatars', () => {
.at(0) .at(0)
.trigger('click'); .trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy(); expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
}); });
});
it('should emit toggleDiscussions event on more count text click', () => { it('should emit toggleDiscussions event on more count text click', () => {
findMoreCount().trigger('click'); findMoreCount().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy(); expect(wrapper.emitted().toggleLineDiscussions).toBeTruthy();
}); });
}); });
});
it('renders an empty more count string if there are no discussions', () => { it('renders an empty more count string if there are no discussions', () => {
createComponent({ createComponent({
......
...@@ -36,8 +36,10 @@ describe('EditButton', () => { ...@@ -36,8 +36,10 @@ describe('EditButton', () => {
}); });
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeTruthy(); expect(wrapper.emitted('showForkMessage')).toBeTruthy();
}); });
});
it('doesnt emit a show fork message event if current user cannot fork', () => { it('doesnt emit a show fork message event if current user cannot fork', () => {
createComponent({ createComponent({
...@@ -46,8 +48,10 @@ describe('EditButton', () => { ...@@ -46,8 +48,10 @@ describe('EditButton', () => {
}); });
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeFalsy(); expect(wrapper.emitted('showForkMessage')).toBeFalsy();
}); });
});
it('doesnt emit a show fork message event if current user can modify blob', () => { it('doesnt emit a show fork message event if current user can modify blob', () => {
createComponent({ createComponent({
...@@ -57,6 +61,8 @@ describe('EditButton', () => { ...@@ -57,6 +61,8 @@ describe('EditButton', () => {
}); });
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('showForkMessage')).toBeFalsy(); expect(wrapper.emitted('showForkMessage')).toBeFalsy();
}); });
});
}); });
...@@ -90,9 +90,14 @@ describe('IDE error message component', () => { ...@@ -90,9 +90,14 @@ describe('IDE error message component', () => {
it('does not dispatch action when already loading', () => { it('does not dispatch action when already loading', () => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
actionMock.mockReset(); actionMock.mockReset();
return wrapper.vm.$nextTick(() => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(actionMock).not.toHaveBeenCalled(); expect(actionMock).not.toHaveBeenCalled();
}); });
});
});
it('shows loading icon when loading', () => { it('shows loading icon when loading', () => {
let resolveAction; let resolveAction;
......
...@@ -62,8 +62,10 @@ describe('IDE file templates dropdown component', () => { ...@@ -62,8 +62,10 @@ describe('IDE file templates dropdown component', () => {
const item = findItemButtons().at(0); const item = findItemButtons().at(0);
item.trigger('click'); item.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().click[0][0]).toBe(itemData); expect(wrapper.emitted().click[0][0]).toBe(itemData);
}); });
});
it('renders dropdown title', () => { it('renders dropdown title', () => {
const title = 'Test title'; const title = 'Test title';
......
...@@ -52,8 +52,11 @@ describe('IDE pipeline stage', () => { ...@@ -52,8 +52,11 @@ describe('IDE pipeline stage', () => {
const id = 5; const id = 5;
createComponent({ stage: { ...defaultProps.stage, id } }); createComponent({ stage: { ...defaultProps.stage, id } });
findHeader().trigger('click'); findHeader().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleCollapsed[0][0]).toBe(id); expect(wrapper.emitted().toggleCollapsed[0][0]).toBe(id);
}); });
});
it('emits clickViewLog entity with job', () => { it('emits clickViewLog entity with job', () => {
const [job] = defaultProps.stage.jobs; const [job] = defaultProps.stage.jobs;
......
...@@ -339,8 +339,10 @@ describe('Issuable component', () => { ...@@ -339,8 +339,10 @@ describe('Issuable component', () => {
findBulkCheckbox().trigger('click'); findBulkCheckbox().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().select).toEqual([[{ issuable, selected: !selected }]]); expect(wrapper.emitted().select).toEqual([[{ issuable, selected: !selected }]]);
}); });
}); });
}); });
});
}); });
...@@ -68,6 +68,9 @@ describe('Job Log Collapsible Section', () => { ...@@ -68,6 +68,9 @@ describe('Job Log Collapsible Section', () => {
}); });
findCollapsibleLine().trigger('click'); findCollapsibleLine().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('onClickCollapsibleLine').length).toBe(1); expect(wrapper.emitted('onClickCollapsibleLine').length).toBe(1);
}); });
});
}); });
...@@ -79,9 +79,11 @@ describe('Job Log Header Line', () => { ...@@ -79,9 +79,11 @@ describe('Job Log Header Line', () => {
it('emits toggleLine event', () => { it('emits toggleLine event', () => {
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleLine.length).toBe(1); expect(wrapper.emitted().toggleLine.length).toBe(1);
}); });
}); });
});
describe('with duration', () => { describe('with duration', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -58,8 +58,9 @@ describe('DateTimePickerInput', () => { ...@@ -58,8 +58,9 @@ describe('DateTimePickerInput', () => {
it('input event is emitted when focus is lost', () => { it('input event is emitted when focus is lost', () => {
createComponent(); createComponent();
jest.spyOn(wrapper.vm, '$emit'); jest.spyOn(wrapper.vm, '$emit');
wrapper.find('input').setValue(inputValue); const input = wrapper.find('input');
wrapper.find('input').trigger('blur'); input.setValue(inputValue);
input.trigger('blur');
expect(wrapper.vm.$emit).toHaveBeenCalledWith('input', inputValue); expect(wrapper.vm.$emit).toHaveBeenCalledWith('input', inputValue);
}); });
......
...@@ -18,7 +18,10 @@ describe('DateTimePicker', () => { ...@@ -18,7 +18,10 @@ describe('DateTimePicker', () => {
const cancelButtonElement = () => dateTimePicker.find('button.btn-secondary').element; const cancelButtonElement = () => dateTimePicker.find('button.btn-secondary').element;
const fillInputAndBlur = (input, val) => { const fillInputAndBlur = (input, val) => {
dateTimePicker.find(input).setValue(val); dateTimePicker.find(input).setValue(val);
return dateTimePicker.vm.$nextTick().then(() => {
dateTimePicker.find(input).trigger('blur'); dateTimePicker.find(input).trigger('blur');
return dateTimePicker.vm.$nextTick();
});
}; };
const createComponent = props => { const createComponent = props => {
...@@ -103,43 +106,44 @@ describe('DateTimePicker', () => { ...@@ -103,43 +106,44 @@ describe('DateTimePicker', () => {
it('displays inline error message if custom time range inputs are invalid', done => { it('displays inline error message if custom time range inputs are invalid', done => {
createComponent(); createComponent();
fillInputAndBlur('#custom-time-from', '2019-10-01abc'); fillInputAndBlur('#custom-time-from', '2019-10-01abc')
fillInputAndBlur('#custom-time-to', '2019-10-10abc'); .then(() => fillInputAndBlur('#custom-time-to', '2019-10-10abc'))
.then(() => {
dateTimePicker.vm.$nextTick(() => {
expect(dateTimePicker.findAll('.invalid-feedback').length).toBe(2); expect(dateTimePicker.findAll('.invalid-feedback').length).toBe(2);
done(); done();
}); })
.catch(done);
}); });
it('keeps apply button disabled with invalid custom time range inputs', done => { it('keeps apply button disabled with invalid custom time range inputs', done => {
createComponent(); createComponent();
fillInputAndBlur('#custom-time-from', '2019-10-01abc'); fillInputAndBlur('#custom-time-from', '2019-10-01abc')
fillInputAndBlur('#custom-time-to', '2019-09-19'); .then(() => fillInputAndBlur('#custom-time-to', '2019-09-19'))
.then(() => {
dateTimePicker.vm.$nextTick(() => {
expect(applyButtonElement().getAttribute('disabled')).toBe('disabled'); expect(applyButtonElement().getAttribute('disabled')).toBe('disabled');
done(); done();
}); })
.catch(done);
}); });
it('enables apply button with valid custom time range inputs', done => { it('enables apply button with valid custom time range inputs', done => {
createComponent(); createComponent();
fillInputAndBlur('#custom-time-from', '2019-10-01'); fillInputAndBlur('#custom-time-from', '2019-10-01')
fillInputAndBlur('#custom-time-to', '2019-10-19'); .then(() => fillInputAndBlur('#custom-time-to', '2019-10-19'))
.then(() => {
dateTimePicker.vm.$nextTick(() => { dateTimePicker.vm.$nextTick(() => {
expect(applyButtonElement().getAttribute('disabled')).toBeNull(); expect(applyButtonElement().getAttribute('disabled')).toBeNull();
done(); done();
}); });
})
.catch(done);
}); });
it('returns an object when apply is clicked', done => { it('returns an object when apply is clicked', done => {
createComponent(); createComponent();
fillInputAndBlur('#custom-time-from', '2019-10-01'); fillInputAndBlur('#custom-time-from', '2019-10-01')
fillInputAndBlur('#custom-time-to', '2019-10-19'); .then(() => fillInputAndBlur('#custom-time-to', '2019-10-19'))
.then(() => {
dateTimePicker.vm.$nextTick(() => {
jest.spyOn(dateTimePicker.vm, '$emit'); jest.spyOn(dateTimePicker.vm, '$emit');
applyButtonElement().click(); applyButtonElement().click();
...@@ -148,7 +152,8 @@ describe('DateTimePicker', () => { ...@@ -148,7 +152,8 @@ describe('DateTimePicker', () => {
start: '2019-10-01T00:00:00Z', start: '2019-10-01T00:00:00Z',
}); });
done(); done();
}); })
.catch(done);
}); });
it('hides the popover with cancel button', done => { it('hides the popover with cancel button', done => {
......
...@@ -24,7 +24,9 @@ describe('JumpToNextDiscussionButton', () => { ...@@ -24,7 +24,9 @@ describe('JumpToNextDiscussionButton', () => {
button.trigger('click'); button.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().onClick).toBeTruthy(); expect(wrapper.emitted().onClick).toBeTruthy();
expect(wrapper.emitted().onClick.length).toBe(1); expect(wrapper.emitted().onClick.length).toBe(1);
}); });
});
}); });
...@@ -25,10 +25,12 @@ describe('ReplyPlaceholder', () => { ...@@ -25,10 +25,12 @@ describe('ReplyPlaceholder', () => {
it('emits onClick even on button click', () => { it('emits onClick even on button click', () => {
findButton().trigger('click'); findButton().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted()).toEqual({ expect(wrapper.emitted()).toEqual({
onClick: [[]], onClick: [[]],
}); });
}); });
});
it('should render reply button', () => { it('should render reply button', () => {
expect(findButton().text()).toEqual(buttonText); expect(findButton().text()).toEqual(buttonText);
......
...@@ -33,10 +33,12 @@ describe('resolveDiscussionButton', () => { ...@@ -33,10 +33,12 @@ describe('resolveDiscussionButton', () => {
button.trigger('click'); button.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted()).toEqual({ expect(wrapper.emitted()).toEqual({
onClick: [[]], onClick: [[]],
}); });
}); });
});
it('should contain the provided button title', () => { it('should contain the provided button title', () => {
const button = wrapper.find({ ref: 'button' }); const button = wrapper.find({ ref: 'button' });
......
...@@ -290,9 +290,12 @@ describe('note_app', () => { ...@@ -290,9 +290,12 @@ describe('note_app', () => {
it('should not render quick actions docs url', () => { it('should not render quick actions docs url', () => {
wrapper.find('.js-note-edit').trigger('click'); wrapper.find('.js-note-edit').trigger('click');
const { quickActionsDocsPath } = mockData.notesDataMock; const { quickActionsDocsPath } = mockData.notesDataMock;
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find(`.edit-note a[href="${quickActionsDocsPath}"]`).exists()).toBe(false); expect(wrapper.find(`.edit-note a[href="${quickActionsDocsPath}"]`).exists()).toBe(false);
}); });
}); });
});
describe('emoji awards', () => { describe('emoji awards', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -19,6 +19,7 @@ describe('add request form', () => { ...@@ -19,6 +19,7 @@ describe('add request form', () => {
describe('when clicking the button', () => { describe('when clicking the button', () => {
beforeEach(() => { beforeEach(() => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return wrapper.vm.$nextTick();
}); });
it('shows the form', () => { it('shows the form', () => {
...@@ -28,6 +29,7 @@ describe('add request form', () => { ...@@ -28,6 +29,7 @@ describe('add request form', () => {
describe('when pressing escape', () => { describe('when pressing escape', () => {
beforeEach(() => { beforeEach(() => {
wrapper.find('input').trigger('keyup.esc'); wrapper.find('input').trigger('keyup.esc');
return wrapper.vm.$nextTick();
}); });
it('hides the input', () => { it('hides the input', () => {
...@@ -38,7 +40,10 @@ describe('add request form', () => { ...@@ -38,7 +40,10 @@ describe('add request form', () => {
describe('when submitting the form', () => { describe('when submitting the form', () => {
beforeEach(() => { beforeEach(() => {
wrapper.find('input').setValue('http://gitlab.example.com/users/root/calendar.json'); wrapper.find('input').setValue('http://gitlab.example.com/users/root/calendar.json');
return wrapper.vm.$nextTick().then(() => {
wrapper.find('input').trigger('keyup.enter'); wrapper.find('input').trigger('keyup.enter');
return wrapper.vm.$nextTick();
});
}); });
it('emits an event to add the request', () => { it('emits an event to add the request', () => {
...@@ -54,9 +59,10 @@ describe('add request form', () => { ...@@ -54,9 +59,10 @@ describe('add request form', () => {
it('clears the value for next time', () => { it('clears the value for next time', () => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find('input').text()).toEqual(''); expect(wrapper.find('input').text()).toEqual('');
}); });
}); });
}); });
});
}); });
...@@ -53,9 +53,12 @@ describe('Evidence Block', () => { ...@@ -53,9 +53,12 @@ describe('Evidence Block', () => {
it('renders the long sha after expansion', () => { it('renders the long sha after expansion', () => {
wrapper.find('.js-text-expander-prepend').trigger('click'); wrapper.find('.js-text-expander-prepend').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.find('.js-expanded').text()).toBe(release.evidence_sha); expect(wrapper.find('.js-expanded').text()).toBe(release.evidence_sha);
}); });
}); });
});
describe('copy to clipboard button', () => { describe('copy to clipboard button', () => {
it('renders button', () => { it('renders button', () => {
......
...@@ -65,9 +65,11 @@ describe('Assignee component', () => { ...@@ -65,9 +65,11 @@ describe('Assignee component', () => {
jest.spyOn(wrapper.vm, '$emit'); jest.spyOn(wrapper.vm, '$emit');
wrapper.find('.assign-yourself .btn-link').trigger('click'); wrapper.find('.assign-yourself .btn-link').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('assign-self')).toBeTruthy(); expect(wrapper.emitted('assign-self')).toBeTruthy();
}); });
}); });
});
describe('One assignee/user', () => { describe('One assignee/user', () => {
it('displays one assignee icon when collapsed', () => { it('displays one assignee icon when collapsed', () => {
......
...@@ -60,8 +60,10 @@ describe('SidebarTodo', () => { ...@@ -60,8 +60,10 @@ describe('SidebarTodo', () => {
createComponent(); createComponent();
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().toggleTodo).toBeTruthy(); expect(wrapper.emitted().toggleTodo).toBeTruthy();
}); });
});
it('renders component container element with proper data attributes', () => { it('renders component container element with proper data attributes', () => {
createComponent({ createComponent({
......
...@@ -42,6 +42,7 @@ describe('Merge Request Collapsible Extension', () => { ...@@ -42,6 +42,7 @@ describe('Merge Request Collapsible Extension', () => {
describe('onClick', () => { describe('onClick', () => {
beforeEach(() => { beforeEach(() => {
wrapper.find('button').trigger('click'); wrapper.find('button').trigger('click');
return wrapper.vm.$nextTick();
}); });
it('rendes the provided slot', () => { it('rendes the provided slot', () => {
......
...@@ -55,10 +55,12 @@ describe('Commits edit component', () => { ...@@ -55,10 +55,12 @@ describe('Commits edit component', () => {
findTextarea().element.value = changedCommitMessage; findTextarea().element.value = changedCommitMessage;
findTextarea().trigger('input'); findTextarea().trigger('input');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().input[0]).toEqual([changedCommitMessage]); expect(wrapper.emitted().input[0]).toEqual([changedCommitMessage]);
expect(findTextarea().element.value).toBe(changedCommitMessage); expect(findTextarea().element.value).toBe(changedCommitMessage);
}); });
}); });
});
describe('when slots are present', () => { describe('when slots are present', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -136,8 +136,11 @@ describe('Expand button', () => { ...@@ -136,8 +136,11 @@ describe('Expand button', () => {
it('clicking hides itself and shows prepend', () => { it('clicking hides itself and shows prepend', () => {
expect(expanderAppendEl().isVisible()).toBe(true); expect(expanderAppendEl().isVisible()).toBe(true);
expanderAppendEl().trigger('click'); expanderAppendEl().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(expanderPrependEl().isVisible()).toBe(true); expect(expanderPrependEl().isVisible()).toBe(true);
}); });
});
it('clicking hides expanded text', () => { it('clicking hides expanded text', () => {
expect( expect(
...@@ -147,6 +150,8 @@ describe('Expand button', () => { ...@@ -147,6 +150,8 @@ describe('Expand button', () => {
.trim(), .trim(),
).toBe(text.expanded); ).toBe(text.expanded);
expanderAppendEl().trigger('click'); expanderAppendEl().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect( expect(
wrapper wrapper
.find(ExpandButton) .find(ExpandButton)
...@@ -154,6 +159,7 @@ describe('Expand button', () => { ...@@ -154,6 +159,7 @@ describe('Expand button', () => {
.trim(), .trim(),
).not.toBe(text.expanded); ).not.toBe(text.expanded);
}); });
});
describe('when short text is provided', () => { describe('when short text is provided', () => {
beforeEach(done => { beforeEach(done => {
...@@ -176,6 +182,8 @@ describe('Expand button', () => { ...@@ -176,6 +182,8 @@ describe('Expand button', () => {
.trim(), .trim(),
).toBe(text.expanded); ).toBe(text.expanded);
expanderAppendEl().trigger('click'); expanderAppendEl().trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect( expect(
wrapper wrapper
.find(ExpandButton) .find(ExpandButton)
...@@ -185,4 +193,5 @@ describe('Expand button', () => { ...@@ -185,4 +193,5 @@ describe('Expand button', () => {
}); });
}); });
}); });
});
}); });
...@@ -192,10 +192,12 @@ describe('RelatedIssuableItem', () => { ...@@ -192,10 +192,12 @@ describe('RelatedIssuableItem', () => {
it('triggers onRemoveRequest when clicked', () => { it('triggers onRemoveRequest when clicked', () => {
removeBtn.trigger('click'); removeBtn.trigger('click');
return wrapper.vm.$nextTick().then(() => {
const { relatedIssueRemoveRequest } = wrapper.emitted(); const { relatedIssueRemoveRequest } = wrapper.emitted();
expect(relatedIssueRemoveRequest.length).toBe(1); expect(relatedIssueRemoveRequest.length).toBe(1);
expect(relatedIssueRemoveRequest[0]).toEqual([props.idKey]); expect(relatedIssueRemoveRequest[0]).toEqual([props.idKey]);
}); });
}); });
});
}); });
...@@ -80,8 +80,10 @@ describe('LoadingButton', () => { ...@@ -80,8 +80,10 @@ describe('LoadingButton', () => {
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('click')).toBeTruthy(); expect(wrapper.emitted('click')).toBeTruthy();
}); });
});
it('does not call given callback when disabled because of loading', () => { it('does not call given callback when disabled because of loading', () => {
buildWrapper({ buildWrapper({
...@@ -90,7 +92,9 @@ describe('LoadingButton', () => { ...@@ -90,7 +92,9 @@ describe('LoadingButton', () => {
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted('click')).toBeFalsy(); expect(wrapper.emitted('click')).toBeFalsy();
}); });
}); });
});
}); });
...@@ -66,12 +66,18 @@ describe('Markdown field header component', () => { ...@@ -66,12 +66,18 @@ describe('Markdown field header component', () => {
it('emits toggle markdown event when clicking preview', () => { it('emits toggle markdown event when clicking preview', () => {
wrapper.find('.js-preview-link').trigger('click'); wrapper.find('.js-preview-link').trigger('click');
return wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.emitted('preview-markdown').length).toEqual(1); expect(wrapper.emitted('preview-markdown').length).toEqual(1);
wrapper.find('.js-write-link').trigger('click'); wrapper.find('.js-write-link').trigger('click');
return wrapper.vm.$nextTick();
})
.then(() => {
expect(wrapper.emitted('write-markdown').length).toEqual(1); expect(wrapper.emitted('write-markdown').length).toEqual(1);
}); });
});
it('does not emit toggle markdown event when triggered from another form', () => { it('does not emit toggle markdown event when triggered from another form', () => {
$(document).triggerHandler('markdown-preview:show', [ $(document).triggerHandler('markdown-preview:show', [
......
...@@ -29,14 +29,20 @@ describe('modal copy button', () => { ...@@ -29,14 +29,20 @@ describe('modal copy button', () => {
removeAllRanges: jest.fn(), removeAllRanges: jest.fn(),
})); }));
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().success).not.toBeEmpty(); expect(wrapper.emitted().success).not.toBeEmpty();
expect(document.execCommand).toHaveBeenCalledWith('copy'); expect(document.execCommand).toHaveBeenCalledWith('copy');
}); });
});
it("should propagate the clipboard error event if execCommand doesn't work", () => { it("should propagate the clipboard error event if execCommand doesn't work", () => {
document.execCommand = jest.fn(() => false); document.execCommand = jest.fn(() => false);
wrapper.trigger('click'); wrapper.trigger('click');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted().error).not.toBeEmpty(); expect(wrapper.emitted().error).not.toBeEmpty();
expect(document.execCommand).toHaveBeenCalledWith('copy'); expect(document.execCommand).toHaveBeenCalledWith('copy');
}); });
}); });
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment