2020-02-11 07:08:52 -05:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-09-20 14:13:03 -04:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2019-12-10 04:07:51 -05:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2022-01-25 10:12:32 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2021-02-14 13:09:20 -05:00
|
|
|
import ContributorsCharts from '~/contributors/components/contributors.vue';
|
2019-10-28 14:06:15 -04:00
|
|
|
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';
|
2021-05-04 20:10:41 -04:00
|
|
|
const branch = 'main';
|
2019-10-28 14:06:15 -04:00
|
|
|
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-02-11 07:08:52 -05:00
|
|
|
wrapper = mount(Component, {
|
2019-10-28 14:06:15 -04:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
it('should display loader whiled loading data', async () => {
|
2019-10-28 14:06:15 -04:00
|
|
|
wrapper.vm.$store.state.loading = true;
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2022-09-20 14:13:03 -04:00
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
|
2019-10-28 14:06:15 -04:00
|
|
|
});
|
|
|
|
|
2022-01-25 10:12:32 -05:00
|
|
|
it('should render charts when loading completed and there is chart data', async () => {
|
2019-10-28 14:06:15 -04:00
|
|
|
wrapper.vm.$store.state.loading = false;
|
|
|
|
wrapper.vm.$store.state.chartData = chartData;
|
2022-01-25 10:12:32 -05:00
|
|
|
await nextTick();
|
2022-09-20 14:13:03 -04:00
|
|
|
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
|
2022-01-25 10:12:32 -05:00
|
|
|
expect(wrapper.find('.contributors-charts').exists()).toBe(true);
|
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
2019-10-28 14:06:15 -04:00
|
|
|
});
|
|
|
|
});
|