Commit 3410de39 authored by Phil Hughes's avatar Phil Hughes

Merge branch...

Merge branch '202533-dashboard-specs-should-remove-done-in-favor-of-returning-promises' into 'master'

Remove `done()` from dashboard specs and return promises

Closes #202726 and #202533

See merge request gitlab-org/gitlab!24730
parents 7809c533 49a9f4f6
...@@ -131,20 +131,17 @@ describe('DashboardsDropdown', () => { ...@@ -131,20 +131,17 @@ describe('DashboardsDropdown', () => {
expect(findModal().contains(DuplicateDashboardForm)).toBe(true); expect(findModal().contains(DuplicateDashboardForm)).toBe(true);
}); });
it('saves a new dashboard', done => { it('saves a new dashboard', () => {
findModal().vm.$emit('ok', okEvent); findModal().vm.$emit('ok', okEvent);
waitForPromises() return waitForPromises().then(() => {
.then(() => { expect(okEvent.preventDefault).toHaveBeenCalled();
expect(okEvent.preventDefault).toHaveBeenCalled();
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); expect(wrapper.vm.$refs.duplicateDashboardModal.hide).toHaveBeenCalled();
expect(wrapper.vm.$refs.duplicateDashboardModal.hide).toHaveBeenCalled(); expect(wrapper.emitted().selectDashboard).toBeTruthy();
expect(wrapper.emitted().selectDashboard).toBeTruthy(); expect(findAlert().exists()).toBe(false);
expect(findAlert().exists()).toBe(false); });
done();
})
.catch(done.fail);
}); });
describe('when a new dashboard is saved succesfully', () => { describe('when a new dashboard is saved succesfully', () => {
...@@ -167,52 +164,42 @@ describe('DashboardsDropdown', () => { ...@@ -167,52 +164,42 @@ describe('DashboardsDropdown', () => {
findModal().vm.$emit('ok', okEvent); findModal().vm.$emit('ok', okEvent);
}; };
it('to the default branch, redirects to the new dashboard', done => { it('to the default branch, redirects to the new dashboard', () => {
submitForm({ submitForm({
branch: defaultBranch, branch: defaultBranch,
}); });
waitForPromises() return waitForPromises().then(() => {
.then(() => { expect(wrapper.emitted().selectDashboard[0][0]).toEqual(newDashboard);
expect(wrapper.emitted().selectDashboard[0][0]).toEqual(newDashboard); });
done();
})
.catch(done.fail);
}); });
it('to a new branch refreshes in the current dashboard', done => { it('to a new branch refreshes in the current dashboard', () => {
submitForm({ submitForm({
branch: 'another-branch', branch: 'another-branch',
}); });
waitForPromises() return waitForPromises().then(() => {
.then(() => { expect(wrapper.emitted().selectDashboard[0][0]).toEqual(dashboardGitResponse[0]);
expect(wrapper.emitted().selectDashboard[0][0]).toEqual(dashboardGitResponse[0]); });
done();
})
.catch(done.fail);
}); });
}); });
it('handles error when a new dashboard is not saved', done => { it('handles error when a new dashboard is not saved', () => {
const errMsg = 'An error occurred'; const errMsg = 'An error occurred';
duplicateDashboardAction.mockRejectedValueOnce(errMsg); duplicateDashboardAction.mockRejectedValueOnce(errMsg);
findModal().vm.$emit('ok', okEvent); findModal().vm.$emit('ok', okEvent);
waitForPromises() return waitForPromises().then(() => {
.then(() => { expect(okEvent.preventDefault).toHaveBeenCalled();
expect(okEvent.preventDefault).toHaveBeenCalled();
expect(findAlert().exists()).toBe(true);
expect(findAlert().text()).toBe(errMsg);
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); expect(findAlert().exists()).toBe(true);
expect(wrapper.vm.$refs.duplicateDashboardModal.hide).not.toHaveBeenCalled(); expect(findAlert().text()).toBe(errMsg);
done(); expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
}) expect(wrapper.vm.$refs.duplicateDashboardModal.hide).not.toHaveBeenCalled();
.catch(done.fail); });
}); });
it('id is correct, as the value of modal directive binding matches modal id', () => { it('id is correct, as the value of modal directive binding matches modal id', () => {
......
...@@ -44,30 +44,27 @@ describe('DuplicateDashboardForm', () => { ...@@ -44,30 +44,27 @@ describe('DuplicateDashboardForm', () => {
describe('validates the file name', () => { describe('validates the file name', () => {
const findInvalidFeedback = () => findByRef('fileNameFormGroup').find('.invalid-feedback'); const findInvalidFeedback = () => findByRef('fileNameFormGroup').find('.invalid-feedback');
it('when is empty', done => { it('when is empty', () => {
setValue('fileName', ''); setValue('fileName', '');
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findByRef('fileNameFormGroup').is('.is-valid')).toBe(true); expect(findByRef('fileNameFormGroup').is('.is-valid')).toBe(true);
expect(findInvalidFeedback().exists()).toBe(false); expect(findInvalidFeedback().exists()).toBe(false);
done();
}); });
}); });
it('when is valid', done => { it('when is valid', () => {
setValue('fileName', 'my_dashboard.yml'); setValue('fileName', 'my_dashboard.yml');
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findByRef('fileNameFormGroup').is('.is-valid')).toBe(true); expect(findByRef('fileNameFormGroup').is('.is-valid')).toBe(true);
expect(findInvalidFeedback().exists()).toBe(false); expect(findInvalidFeedback().exists()).toBe(false);
done();
}); });
}); });
it('when is not valid', done => { it('when is not valid', () => {
setValue('fileName', 'my_dashboard.exe'); setValue('fileName', 'my_dashboard.exe');
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findByRef('fileNameFormGroup').is('.is-invalid')).toBe(true); expect(findByRef('fileNameFormGroup').is('.is-invalid')).toBe(true);
expect(findInvalidFeedback().text()).toBeTruthy(); expect(findInvalidFeedback().text()).toBeTruthy();
done();
}); });
}); });
}); });
...@@ -124,30 +121,26 @@ describe('DuplicateDashboardForm', () => { ...@@ -124,30 +121,26 @@ describe('DuplicateDashboardForm', () => {
}); });
}); });
it('when a `default` branch option is set, branch input is invisible and ignored', done => { it('when a `default` branch option is set, branch input is invisible and ignored', () => {
setChecked(wrapper.vm.$options.radioVals.DEFAULT); setChecked(wrapper.vm.$options.radioVals.DEFAULT);
setValue('branchName', 'a-new-branch'); setValue('branchName', 'a-new-branch');
expect(lastChange()).resolves.toMatchObject({ expect(lastChange()).resolves.toMatchObject({
branch: defaultBranch, branch: defaultBranch,
}); });
wrapper.vm.$nextTick(() => {
return wrapper.vm.$nextTick(() => {
expect(findByRef('branchName').isVisible()).toBe(false); expect(findByRef('branchName').isVisible()).toBe(false);
done();
}); });
}); });
it('when `new` branch option is chosen, focuses on the branch name input', done => { it('when `new` branch option is chosen, focuses on the branch name input', () => {
setChecked(wrapper.vm.$options.radioVals.NEW); setChecked(wrapper.vm.$options.radioVals.NEW);
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() wrapper.find('form').trigger('change');
.then(() => { expect(findByRef('branchName').is(':focus')).toBe(true);
wrapper.find('form').trigger('change'); });
expect(findByRef('branchName').is(':focus')).toBe(true);
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
...@@ -32,25 +32,23 @@ describe('Graph group component', () => { ...@@ -32,25 +32,23 @@ describe('Graph group component', () => {
expect(findCaretIcon().props('name')).toBe('angle-down'); expect(findCaretIcon().props('name')).toBe('angle-down');
}); });
it('should show the angle-right caret icon when the user collapses the group', done => { it('should show the angle-right caret icon when the user collapses the group', () => {
wrapper.vm.collapse(); wrapper.vm.collapse();
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findContent().isVisible()).toBe(false); expect(findContent().isVisible()).toBe(false);
expect(findCaretIcon().props('name')).toBe('angle-right'); expect(findCaretIcon().props('name')).toBe('angle-right');
done();
}); });
}); });
it('should show the open the group when collapseGroup is set to true', done => { it('should show the open the group when collapseGroup is set to true', () => {
wrapper.setProps({ wrapper.setProps({
collapseGroup: true, collapseGroup: true,
}); });
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findContent().isVisible()).toBe(true); expect(findContent().isVisible()).toBe(true);
expect(findCaretIcon().props('name')).toBe('angle-down'); expect(findCaretIcon().props('name')).toBe('angle-down');
done();
}); });
}); });
...@@ -102,13 +100,12 @@ describe('Graph group component', () => { ...@@ -102,13 +100,12 @@ describe('Graph group component', () => {
expect(findCaretIcon().exists()).toBe(false); expect(findCaretIcon().exists()).toBe(false);
}); });
it('should show the panel content when clicked', done => { it('should show the panel content when clicked', () => {
wrapper.vm.collapse(); wrapper.vm.collapse();
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findContent().isVisible()).toBe(true); expect(findContent().isVisible()).toBe(true);
expect(findCaretIcon().exists()).toBe(false); expect(findCaretIcon().exists()).toBe(false);
done();
}); });
}); });
}); });
......
...@@ -28,6 +28,8 @@ describe('Panel Type component', () => { ...@@ -28,6 +28,8 @@ describe('Panel Type component', () => {
const exampleText = 'example_text'; const exampleText = 'example_text';
const findCopyLink = () => wrapper.find({ ref: 'copyChartLink' });
const createWrapper = props => { const createWrapper = props => {
wrapper = shallowMount(PanelType, { wrapper = shallowMount(PanelType, {
propsData: { propsData: {
...@@ -96,8 +98,7 @@ describe('Panel Type component', () => { ...@@ -96,8 +98,7 @@ describe('Panel Type component', () => {
}); });
it('sets no clipboard copy link on dropdown by default', () => { it('sets no clipboard copy link on dropdown by default', () => {
const link = () => wrapper.find({ ref: 'copyChartLink' }); expect(findCopyLink().exists()).toBe(false);
expect(link().exists()).toBe(false);
}); });
describe('Time Series Chart panel type', () => { describe('Time Series Chart panel type', () => {
...@@ -204,7 +205,6 @@ describe('Panel Type component', () => { ...@@ -204,7 +205,6 @@ describe('Panel Type component', () => {
}); });
describe('when cliboard data is available', () => { describe('when cliboard data is available', () => {
const link = () => wrapper.find({ ref: 'copyChartLink' });
const clipboardText = 'A value to copy.'; const clipboardText = 'A value to copy.';
beforeEach(() => { beforeEach(() => {
...@@ -219,16 +219,16 @@ describe('Panel Type component', () => { ...@@ -219,16 +219,16 @@ describe('Panel Type component', () => {
}); });
it('sets clipboard text on the dropdown', () => { it('sets clipboard text on the dropdown', () => {
expect(link().exists()).toBe(true); expect(findCopyLink().exists()).toBe(true);
expect(link().element.dataset.clipboardText).toBe(clipboardText); expect(findCopyLink().element.dataset.clipboardText).toBe(clipboardText);
}); });
it('adds a copy button to the dropdown', () => { it('adds a copy button to the dropdown', () => {
expect(link().text()).toContain('Generate link to chart'); expect(findCopyLink().text()).toContain('Generate link to chart');
}); });
it('opens a toast on click', () => { it('opens a toast on click', () => {
link().vm.$emit('click'); findCopyLink().vm.$emit('click');
expect(wrapper.vm.$toast.show).toHaveBeenCalled(); expect(wrapper.vm.$toast.show).toHaveBeenCalled();
}); });
......
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