debian-mirror-gitlab/spec/frontend/error_tracking/components/error_tracking_list_spec.js

119 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
import ErrorTrackingList from '~/error_tracking/components/error_tracking_list.vue';
2019-07-07 11:18:12 +05:30
import { GlButton, GlEmptyState, GlLoadingIcon, GlTable, GlLink } from '@gitlab/ui';
2019-02-15 15:39:39 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
describe('ErrorTrackingList', () => {
let store;
let wrapper;
2019-07-07 11:18:12 +05:30
let actions;
2019-02-15 15:39:39 +05:30
function mountComponent({ errorTrackingEnabled = true } = {}) {
wrapper = shallowMount(ErrorTrackingList, {
localVue,
store,
propsData: {
indexPath: '/path',
enableErrorTrackingLink: '/link',
errorTrackingEnabled,
illustrationPath: 'illustration/path',
},
2019-07-07 11:18:12 +05:30
stubs: {
'gl-link': GlLink,
},
2019-02-15 15:39:39 +05:30
});
}
beforeEach(() => {
2019-07-07 11:18:12 +05:30
actions = {
2019-02-15 15:39:39 +05:30
getErrorList: () => {},
2019-07-07 11:18:12 +05:30
startPolling: () => {},
restartPolling: jasmine.createSpy('restartPolling'),
2019-02-15 15:39:39 +05:30
};
const state = {
errors: [],
loading: true,
};
store = new Vuex.Store({
actions,
state,
});
});
afterEach(() => {
if (wrapper) {
wrapper.destroy();
}
});
describe('loading', () => {
beforeEach(() => {
mountComponent();
});
it('shows spinner', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBeTruthy();
expect(wrapper.find(GlTable).exists()).toBeFalsy();
expect(wrapper.find(GlButton).exists()).toBeFalsy();
});
});
describe('results', () => {
beforeEach(() => {
store.state.loading = false;
mountComponent();
});
it('shows table', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBeFalsy();
expect(wrapper.find(GlTable).exists()).toBeTruthy();
expect(wrapper.find(GlButton).exists()).toBeTruthy();
});
});
describe('no results', () => {
beforeEach(() => {
store.state.loading = false;
mountComponent();
});
it('shows empty table', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBeFalsy();
expect(wrapper.find(GlTable).exists()).toBeTruthy();
expect(wrapper.find(GlButton).exists()).toBeTruthy();
});
2019-07-07 11:18:12 +05:30
it('shows a message prompting to refresh', () => {
const refreshLink = wrapper.vm.$refs.empty.querySelector('a');
expect(refreshLink.textContent.trim()).toContain('Check again');
});
it('restarts polling', () => {
wrapper.find('.js-try-again').trigger('click');
expect(actions.restartPolling).toHaveBeenCalled();
});
2019-02-15 15:39:39 +05:30
});
describe('error tracking feature disabled', () => {
beforeEach(() => {
mountComponent({ errorTrackingEnabled: false });
});
it('shows empty state', () => {
expect(wrapper.find(GlEmptyState).exists()).toBeTruthy();
expect(wrapper.find(GlLoadingIcon).exists()).toBeFalsy();
expect(wrapper.find(GlTable).exists()).toBeFalsy();
expect(wrapper.find(GlButton).exists()).toBeFalsy();
});
});
});