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
...@@ -91,10 +91,10 @@ describe('Dashboard', () => { ...@@ -91,10 +91,10 @@ describe('Dashboard', () => {
}); });
describe('no data found', () => { describe('no data found', () => {
beforeEach(done => { beforeEach(() => {
createShallowWrapper(); createShallowWrapper();
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('shows the environment selector dropdown', () => { it('shows the environment selector dropdown', () => {
...@@ -118,20 +118,15 @@ describe('Dashboard', () => { ...@@ -118,20 +118,15 @@ describe('Dashboard', () => {
}); });
}); });
it('shows up a loading state', done => { it('shows up a loading state', () => {
createShallowWrapper({ hasMetrics: true }, { methods: {} }); createShallowWrapper({ hasMetrics: true }, { methods: {} });
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() expect(wrapper.vm.emptyState).toEqual('loading');
.then(() => { });
expect(wrapper.vm.emptyState).toEqual('loading');
done();
})
.catch(done.fail);
}); });
it('hides the group panels when showPanels is false', done => { it('hides the group panels when showPanels is false', () => {
createMountedWrapper( createMountedWrapper(
{ hasMetrics: true, showPanels: false }, { hasMetrics: true, showPanels: false },
{ stubs: ['graph-group', 'panel-type'] }, { stubs: ['graph-group', 'panel-type'] },
...@@ -139,15 +134,10 @@ describe('Dashboard', () => { ...@@ -139,15 +134,10 @@ describe('Dashboard', () => {
setupComponentStore(wrapper); setupComponentStore(wrapper);
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() expect(wrapper.vm.showEmptyState).toEqual(false);
.then(() => { expect(wrapper.findAll('.prometheus-panel')).toHaveLength(0);
expect(wrapper.vm.showEmptyState).toEqual(false); });
expect(wrapper.findAll('.prometheus-panel')).toHaveLength(0);
done();
})
.catch(done.fail);
}); });
it('fetches the metrics data with proper time window', () => { it('fetches the metrics data with proper time window', () => {
...@@ -171,43 +161,32 @@ describe('Dashboard', () => { ...@@ -171,43 +161,32 @@ describe('Dashboard', () => {
createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] }); createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] });
setupComponentStore(wrapper); setupComponentStore(wrapper);
return wrapper.vm.$nextTick();
}); });
it('renders the environments dropdown with a number of environments', done => { it('renders the environments dropdown with a number of environments', () => {
wrapper.vm expect(findAllEnvironmentsDropdownItems().length).toEqual(environmentData.length);
.$nextTick()
.then(() => {
expect(findAllEnvironmentsDropdownItems().length).toEqual(environmentData.length);
findAllEnvironmentsDropdownItems().wrappers.forEach((itemWrapper, index) => {
const anchorEl = itemWrapper.find('a');
if (anchorEl.exists() && environmentData[index].metrics_path) {
const href = anchorEl.attributes('href');
expect(href).toBe(environmentData[index].metrics_path);
}
});
done(); findAllEnvironmentsDropdownItems().wrappers.forEach((itemWrapper, index) => {
}) const anchorEl = itemWrapper.find('a');
.catch(done.fail); if (anchorEl.exists() && environmentData[index].metrics_path) {
const href = anchorEl.attributes('href');
expect(href).toBe(environmentData[index].metrics_path);
}
});
}); });
it('renders the environments dropdown with a single active element', done => { it('renders the environments dropdown with a single active element', () => {
wrapper.vm const activeItem = findAllEnvironmentsDropdownItems().wrappers.filter(itemWrapper =>
.$nextTick() itemWrapper.find('.active').exists(),
.then(() => { );
const activeItem = findAllEnvironmentsDropdownItems().wrappers.filter(itemWrapper =>
itemWrapper.find('.active').exists(),
);
expect(activeItem.length).toBe(1); expect(activeItem.length).toBe(1);
done();
})
.catch(done.fail);
}); });
}); });
it('hides the environments dropdown list when there is no environments', done => { it('hides the environments dropdown list when there is no environments', () => {
createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] }); createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] });
wrapper.vm.$store.commit( wrapper.vm.$store.commit(
...@@ -219,35 +198,27 @@ describe('Dashboard', () => { ...@@ -219,35 +198,27 @@ describe('Dashboard', () => {
mockedQueryResultPayload, mockedQueryResultPayload,
); );
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() expect(findAllEnvironmentsDropdownItems()).toHaveLength(0);
.then(() => { });
expect(findAllEnvironmentsDropdownItems()).toHaveLength(0);
done();
})
.catch(done.fail);
}); });
it('renders the datetimepicker dropdown', done => { it('renders the datetimepicker dropdown', () => {
createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] }); createMountedWrapper({ hasMetrics: true }, { stubs: ['graph-group', 'panel-type'] });
setupComponentStore(wrapper); setupComponentStore(wrapper);
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() expect(wrapper.find(DateTimePicker).exists()).toBe(true);
.then(() => { });
expect(wrapper.find(DateTimePicker).exists()).toBe(true);
done();
})
.catch(done.fail);
}); });
describe('when one of the metrics is missing', () => { describe('when one of the metrics is missing', () => {
beforeEach(done => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
setupComponentStore(wrapper); setupComponentStore(wrapper);
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('shows a group empty area', () => { it('shows a group empty area', () => {
...@@ -300,7 +271,7 @@ describe('Dashboard', () => { ...@@ -300,7 +271,7 @@ describe('Dashboard', () => {
const resultEnvs = environmentData.filter(({ name }) => name.indexOf(searchTerm) !== -1); const resultEnvs = environmentData.filter(({ name }) => name.indexOf(searchTerm) !== -1);
setSearchTerm(searchTerm); setSearchTerm(searchTerm);
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick().then(() => {
expect(findAllEnvironmentsDropdownItems().length).toEqual(resultEnvs.length); expect(findAllEnvironmentsDropdownItems().length).toEqual(resultEnvs.length);
}); });
}); });
...@@ -349,12 +320,12 @@ describe('Dashboard', () => { ...@@ -349,12 +320,12 @@ describe('Dashboard', () => {
const findDraggablePanels = () => wrapper.findAll('.js-draggable-panel'); const findDraggablePanels = () => wrapper.findAll('.js-draggable-panel');
const findRearrangeButton = () => wrapper.find('.js-rearrange-button'); const findRearrangeButton = () => wrapper.find('.js-rearrange-button');
beforeEach(done => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
setupComponentStore(wrapper); setupComponentStore(wrapper);
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('wraps vuedraggable', () => { it('wraps vuedraggable', () => {
...@@ -368,9 +339,9 @@ describe('Dashboard', () => { ...@@ -368,9 +339,9 @@ describe('Dashboard', () => {
}); });
describe('when rearrange is enabled', () => { describe('when rearrange is enabled', () => {
beforeEach(done => { beforeEach(() => {
wrapper.setProps({ rearrangePanelsAvailable: true }); wrapper.setProps({ rearrangePanelsAvailable: true });
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('displays rearrange button', () => { it('displays rearrange button', () => {
...@@ -383,9 +354,9 @@ describe('Dashboard', () => { ...@@ -383,9 +354,9 @@ describe('Dashboard', () => {
.at(0) .at(0)
.find('.js-draggable-remove'); .find('.js-draggable-remove');
beforeEach(done => { beforeEach(() => {
findRearrangeButton().vm.$emit('click'); findRearrangeButton().vm.$emit('click');
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('it enables draggables', () => { it('it enables draggables', () => {
...@@ -393,7 +364,7 @@ describe('Dashboard', () => { ...@@ -393,7 +364,7 @@ describe('Dashboard', () => {
expect(findEnabledDraggables()).toEqual(findDraggables()); expect(findEnabledDraggables()).toEqual(findDraggables());
}); });
it('metrics can be swapped', done => { it('metrics can be swapped', () => {
const firstDraggable = findDraggables().at(0); const firstDraggable = findDraggables().at(0);
const mockMetrics = [...metricsDashboardPayload.panel_groups[1].panels]; const mockMetrics = [...metricsDashboardPayload.panel_groups[1].panels];
...@@ -404,33 +375,30 @@ describe('Dashboard', () => { ...@@ -404,33 +375,30 @@ describe('Dashboard', () => {
[mockMetrics[0], mockMetrics[1]] = [mockMetrics[1], mockMetrics[0]]; [mockMetrics[0], mockMetrics[1]] = [mockMetrics[1], mockMetrics[0]];
firstDraggable.vm.$emit('input', mockMetrics); firstDraggable.vm.$emit('input', mockMetrics);
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
const { panels } = wrapper.vm.dashboard.panel_groups[1]; const { panels } = wrapper.vm.dashboard.panel_groups[1];
expect(panels[1].title).toEqual(firstTitle); expect(panels[1].title).toEqual(firstTitle);
expect(panels[0].title).toEqual(secondTitle); expect(panels[0].title).toEqual(secondTitle);
done();
}); });
}); });
it('shows a remove button, which removes a panel', done => { it('shows a remove button, which removes a panel', () => {
expect(findFirstDraggableRemoveButton().isEmpty()).toBe(false); expect(findFirstDraggableRemoveButton().isEmpty()).toBe(false);
expect(findDraggablePanels().length).toEqual(expectedPanelCount); expect(findDraggablePanels().length).toEqual(expectedPanelCount);
findFirstDraggableRemoveButton().trigger('click'); findFirstDraggableRemoveButton().trigger('click');
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findDraggablePanels().length).toEqual(expectedPanelCount - 1); expect(findDraggablePanels().length).toEqual(expectedPanelCount - 1);
done();
}); });
}); });
it('it disables draggables when clicked again', done => { it('it disables draggables when clicked again', () => {
findRearrangeButton().vm.$emit('click'); findRearrangeButton().vm.$emit('click');
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findRearrangeButton().attributes('pressed')).toBeFalsy(); expect(findRearrangeButton().attributes('pressed')).toBeFalsy();
expect(findEnabledDraggables().length).toBe(0); expect(findEnabledDraggables().length).toBe(0);
done();
}); });
}); });
}); });
...@@ -438,13 +406,13 @@ describe('Dashboard', () => { ...@@ -438,13 +406,13 @@ describe('Dashboard', () => {
}); });
describe('cluster health', () => { describe('cluster health', () => {
beforeEach(done => { beforeEach(() => {
mock.onGet(propsData.metricsEndpoint).reply(statusCodes.OK, JSON.stringify({})); mock.onGet(propsData.metricsEndpoint).reply(statusCodes.OK, JSON.stringify({}));
createShallowWrapper({ hasMetrics: true, showHeader: false }); createShallowWrapper({ hasMetrics: true, showHeader: false });
// all_dashboards is not defined in health dashboards // all_dashboards is not defined in health dashboards
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined); wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined);
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('hides dashboard header by default', () => { it('hides dashboard header by default', () => {
...@@ -460,33 +428,29 @@ describe('Dashboard', () => { ...@@ -460,33 +428,29 @@ describe('Dashboard', () => {
describe('dashboard edit link', () => { describe('dashboard edit link', () => {
const findEditLink = () => wrapper.find('.js-edit-link'); const findEditLink = () => wrapper.find('.js-edit-link');
beforeEach(done => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); createShallowWrapper({ hasMetrics: true });
wrapper.vm.$store.commit( wrapper.vm.$store.commit(
`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, `monitoringDashboard/${types.SET_ALL_DASHBOARDS}`,
dashboardGitResponse, dashboardGitResponse,
); );
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('is not present for the default dashboard', () => { it('is not present for the default dashboard', () => {
expect(findEditLink().exists()).toBe(false); expect(findEditLink().exists()).toBe(false);
}); });
it('is present for a custom dashboard, and links to its edit_path', done => { it('is present for a custom dashboard, and links to its edit_path', () => {
const dashboard = dashboardGitResponse[1]; // non-default dashboard const dashboard = dashboardGitResponse[1]; // non-default dashboard
const currentDashboard = dashboard.path; const currentDashboard = dashboard.path;
wrapper.setProps({ currentDashboard }); wrapper.setProps({ currentDashboard });
wrapper.vm return wrapper.vm.$nextTick().then(() => {
.$nextTick() expect(findEditLink().exists()).toBe(true);
.then(() => { expect(findEditLink().attributes('href')).toBe(dashboard.project_blob_path);
expect(findEditLink().exists()).toBe(true); });
expect(findEditLink().attributes('href')).toBe(dashboard.project_blob_path);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -498,18 +462,14 @@ describe('Dashboard', () => { ...@@ -498,18 +462,14 @@ describe('Dashboard', () => {
`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, `monitoringDashboard/${types.SET_ALL_DASHBOARDS}`,
dashboardGitResponse, dashboardGitResponse,
); );
return wrapper.vm.$nextTick();
}); });
it('shows the dashboard dropdown', done => { it('shows the dashboard dropdown', () => {
wrapper.vm const dashboardDropdown = wrapper.find(DashboardsDropdown);
.$nextTick()
.then(() => {
const dashboardDropdown = wrapper.find(DashboardsDropdown);
expect(dashboardDropdown.exists()).toBe(true); expect(dashboardDropdown.exists()).toBe(true);
done();
})
.catch(done.fail);
}); });
}); });
...@@ -524,20 +484,16 @@ describe('Dashboard', () => { ...@@ -524,20 +484,16 @@ describe('Dashboard', () => {
}, },
{ stubs: ['graph-group', 'panel-type'] }, { stubs: ['graph-group', 'panel-type'] },
); );
return wrapper.vm.$nextTick();
}); });
it('shows the link', done => { it('shows the link', () => {
wrapper.vm const externalDashboardButton = wrapper.find('.js-external-dashboard-link');
.$nextTick()
.then(() => {
const externalDashboardButton = wrapper.find('.js-external-dashboard-link');
expect(externalDashboardButton.exists()).toBe(true); expect(externalDashboardButton.exists()).toBe(true);
expect(externalDashboardButton.is(GlButton)).toBe(true); expect(externalDashboardButton.is(GlButton)).toBe(true);
expect(externalDashboardButton.text()).toContain('View full dashboard'); expect(externalDashboardButton.text()).toContain('View full dashboard');
done();
})
.catch(done.fail);
}); });
}); });
...@@ -550,12 +506,12 @@ describe('Dashboard', () => { ...@@ -550,12 +506,12 @@ describe('Dashboard', () => {
.at(i) .at(i)
.props('clipboardText'); .props('clipboardText');
beforeEach(done => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true, currentDashboard }); createShallowWrapper({ hasMetrics: true, currentDashboard });
setupComponentStore(wrapper); setupComponentStore(wrapper);
wrapper.vm.$nextTick(done); return wrapper.vm.$nextTick();
}); });
it('contains a link to the dashboard', () => { it('contains a link to the dashboard', () => {
...@@ -565,23 +521,21 @@ describe('Dashboard', () => { ...@@ -565,23 +521,21 @@ describe('Dashboard', () => {
expect(getClipboardTextAt(0)).toContain(`y_label=`); expect(getClipboardTextAt(0)).toContain(`y_label=`);
}); });
it('strips the undefined parameter', done => { it('strips the undefined parameter', () => {
wrapper.setProps({ currentDashboard: undefined }); wrapper.setProps({ currentDashboard: undefined });
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(getClipboardTextAt(0)).not.toContain(`dashboard=`); expect(getClipboardTextAt(0)).not.toContain(`dashboard=`);
expect(getClipboardTextAt(0)).toContain(`y_label=`); expect(getClipboardTextAt(0)).toContain(`y_label=`);
done();
}); });
}); });
it('null parameter is stripped', done => { it('null parameter is stripped', () => {
wrapper.setProps({ currentDashboard: null }); wrapper.setProps({ currentDashboard: null });
wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(getClipboardTextAt(0)).not.toContain(`dashboard=`); expect(getClipboardTextAt(0)).not.toContain(`dashboard=`);
expect(getClipboardTextAt(0)).toContain(`y_label=`); expect(getClipboardTextAt(0)).toContain(`y_label=`);
done();
}); });
}); });
}); });
......
...@@ -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