debian-mirror-gitlab/spec/frontend/contributors/component/contributors_spec.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { mount } from '@vue/test-utils';
2020-01-01 13:55:28 +05:30
import MockAdapter from 'axios-mock-adapter';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
import ContributorsCharts from '~/contributors/components/contributors.vue';
2019-12-26 22:10:19 +05:30
import { createStore } from '~/contributors/stores';
import axios from '~/lib/utils/axios_utils';
let wrapper;
let mock;
let store;
const Component = Vue.extend(ContributorsCharts);
const endpoint = 'contributors';
const branch = 'master';
const chartData = [
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-05-05' },
{ author_name: 'John', author_email: 'jawnnypoo@gmail.com', date: '2019-03-03' },
];
function factory() {
mock = new MockAdapter(axios);
jest.spyOn(axios, 'get');
mock.onGet().reply(200, chartData);
store = createStore();
2020-03-13 15:44:24 +05:30
wrapper = mount(Component, {
2019-12-26 22:10:19 +05:30
propsData: {
endpoint,
branch,
},
stubs: {
GlLoadingIcon: true,
GlAreaChart: true,
},
store,
});
}
describe('Contributors charts', () => {
beforeEach(() => {
factory();
});
afterEach(() => {
mock.restore();
wrapper.destroy();
});
it('should fetch chart data when mounted', () => {
expect(axios.get).toHaveBeenCalledWith(endpoint);
});
it('should display loader whiled loading data', () => {
wrapper.vm.$store.state.loading = true;
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.contributors-loader').exists()).toBe(true);
});
});
it('should render charts when loading completed and there is chart data', () => {
wrapper.vm.$store.state.loading = false;
wrapper.vm.$store.state.chartData = chartData;
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
2019-12-26 22:10:19 +05:30
expect(wrapper.find('.contributors-loader').exists()).toBe(false);
expect(wrapper.find('.contributors-charts').exists()).toBe(true);
expect(wrapper.element).toMatchSnapshot();
});
});
});