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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { mount } from '@vue/test-utils';
2022-11-25 23:54:43 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import MockAdapter from 'axios-mock-adapter';
2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2021-03-11 19:13:27 +05:30
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';
2021-06-08 01:23:25 +05:30
const branch = 'main';
2019-12-26 22:10:19 +05:30
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);
});
2022-04-04 11:22:00 +05:30
it('should display loader whiled loading data', async () => {
2019-12-26 22:10:19 +05:30
wrapper.vm.$store.state.loading = true;
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
2019-12-26 22:10:19 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render charts when loading completed and there is chart data', async () => {
2019-12-26 22:10:19 +05:30
wrapper.vm.$store.state.loading = false;
wrapper.vm.$store.state.chartData = chartData;
2022-04-04 11:22:00 +05:30
await nextTick();
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(false);
2022-04-04 11:22:00 +05:30
expect(wrapper.find('.contributors-charts').exists()).toBe(true);
expect(wrapper.element).toMatchSnapshot();
2019-12-26 22:10:19 +05:30
});
});