Commit 07ab8b33 authored by Phil Hughes's avatar Phil Hughes

Merge branch '8255-transient-failure-of-dashboard_spec-js' into 'master'

Resolve "Transient failure of dashboard_spec.js"

Closes #8255

See merge request gitlab-org/gitlab-ee!8369
parents 08e5896e f4d58dcc
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import store from 'ee/operations/store/index'; import store from 'ee/operations/store/index';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import Dashboard from 'ee/operations/components/dashboard/dashboard.vue'; import Dashboard from 'ee/operations/components/dashboard/dashboard.vue';
import ProjectSearch from 'ee/operations/components/dashboard/project_search.vue'; import ProjectSearch from 'ee/operations/components/dashboard/project_search.vue';
import DashboardProject from 'ee/operations/components/dashboard/project.vue'; import DashboardProject from 'ee/operations/components/dashboard/project.vue';
...@@ -14,29 +11,28 @@ describe('dashboard component', () => { ...@@ -14,29 +11,28 @@ describe('dashboard component', () => {
const ProjectSearchComponent = Vue.extend(ProjectSearch); const ProjectSearchComponent = Vue.extend(ProjectSearch);
const DashboardProjectComponent = Vue.extend(DashboardProject); const DashboardProjectComponent = Vue.extend(DashboardProject);
const projectTokens = mockProjectData(1); const projectTokens = mockProjectData(1);
const mockListPath = 'mock-listPath';
const mount = () => const mount = () =>
mountComponentWithStore(DashboardComponent, { new DashboardComponent({
store, store,
props: { propsData: {
addPath: 'mock-addPath', addPath: 'mock-addPath',
listPath: mockListPath, listPath: 'mock-listPath',
emptyDashboardSvgPath: '/assets/illustrations/operations-dashboard_empty.svg', emptyDashboardSvgPath: '/assets/illustrations/operations-dashboard_empty.svg',
emptyDashboardHelpPath: '/help/user/operations_dashboard/index.html', emptyDashboardHelpPath: '/help/user/operations_dashboard/index.html',
}, },
}); methods: {
fetchProjects: () => {},
},
}).$mount();
let vm; let vm;
let mockAxios;
beforeEach(() => { beforeEach(() => {
vm = mount(); vm = mount();
mockAxios = new MockAdapter(axios);
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
clearState(store); clearState(store);
mockAxios.restore();
}); });
it('renders dashboard title', () => { it('renders dashboard title', () => {
...@@ -57,7 +53,7 @@ describe('dashboard component', () => { ...@@ -57,7 +53,7 @@ describe('dashboard component', () => {
}); });
it('calls action to add projects on click if projectTokens have been added', () => { it('calls action to add projects on click if projectTokens have been added', () => {
const spy = spyOn(vm, 'addProjectsToDashboard'); const spy = spyOn(vm, 'addProjectsToDashboard').and.stub();
vm.$store.state.projectTokens = projectTokens; vm.$store.state.projectTokens = projectTokens;
button.click(); button.click();
...@@ -65,7 +61,7 @@ describe('dashboard component', () => { ...@@ -65,7 +61,7 @@ describe('dashboard component', () => {
}); });
it('does not call action to add projects on click when projectTokens is empty', () => { it('does not call action to add projects on click when projectTokens is empty', () => {
const spy = spyOn(vm, 'addProjectsToDashboard'); const spy = spyOn(vm, 'addProjectsToDashboard').and.stub();
button.click(); button.click();
expect(spy).not.toHaveBeenCalled(); expect(spy).not.toHaveBeenCalled();
...@@ -102,16 +98,14 @@ describe('dashboard component', () => { ...@@ -102,16 +98,14 @@ describe('dashboard component', () => {
describe('empty state', () => { describe('empty state', () => {
beforeEach(() => { beforeEach(() => {
mockAxios.onGet(mockListPath).replyOnce(200, { data: [] }); store.state.projects = [];
vm = mount(); vm = mount();
}); });
it('renders empty state svg after requesting projects with no results', () => { it('renders empty state svg after requesting projects with no results', () => {
const svgSrc = vm.$el const svgSrc = vm.$el.querySelector('.js-empty-state-svg').src;
.querySelector('.js-empty-state-svg')
.src.slice(-mockText.EMPTY_SVG_SOURCE.length);
expect(svgSrc).toBe(mockText.EMPTY_SVG_SOURCE); expect(svgSrc).toMatch(mockText.EMPTY_SVG_SOURCE);
}); });
it('renders title', () => { it('renders title', () => {
......
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