2023-05-27 22:25:52 +05:30
|
|
|
import { GlAlert, GlCollapsibleListbox, GlListboxItem } from '@gitlab/ui';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { GlAreaChart } from '@gitlab/ui/dist/charts';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
import { nextTick } from 'vue';
|
2020-10-24 23:57:45 +05:30
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2020-06-23 00:09:42 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2023-03-17 16:20:25 +05:30
|
|
|
import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2020-06-23 00:09:42 +05:30
|
|
|
import CodeCoverage from '~/pages/projects/graphs/components/code_coverage.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { codeCoverageMockData, sortedDataByDates } from './mock_data';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
describe('Code Coverage', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mockAxios;
|
|
|
|
|
|
|
|
const graphEndpoint = '/graph';
|
2022-08-27 11:52:29 +05:30
|
|
|
const graphStartDate = '13 February';
|
|
|
|
const graphEndDate = '12 May';
|
|
|
|
const graphRef = 'master';
|
|
|
|
const graphCsvPath = 'url/';
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
const findAlert = () => wrapper.findComponent(GlAlert);
|
|
|
|
const findAreaChart = () => wrapper.findComponent(GlAreaChart);
|
2023-05-27 22:25:52 +05:30
|
|
|
const findListBox = () => wrapper.findComponent(GlCollapsibleListbox);
|
2023-03-04 22:38:38 +05:30
|
|
|
const findListBoxItems = () => wrapper.findAllComponents(GlListboxItem);
|
|
|
|
const findFirstListBoxItem = () => findListBoxItems().at(0);
|
|
|
|
const findSecondListBoxItem = () => findListBoxItems().at(1);
|
2022-08-27 11:52:29 +05:30
|
|
|
const findDownloadButton = () => wrapper.find('[data-testid="download-button"]');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
wrapper = shallowMount(CodeCoverage, {
|
|
|
|
propsData: {
|
|
|
|
graphEndpoint,
|
2022-08-27 11:52:29 +05:30
|
|
|
graphStartDate,
|
|
|
|
graphEndDate,
|
|
|
|
graphRef,
|
|
|
|
graphCsvPath,
|
2020-06-23 00:09:42 +05:30
|
|
|
},
|
2023-05-27 22:25:52 +05:30
|
|
|
stubs: { GlCollapsibleListbox },
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('when fetching data is successful', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
2023-03-17 16:20:25 +05:30
|
|
|
mockAxios.onGet().replyOnce(HTTP_STATUS_OK, codeCoverageMockData);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockAxios.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the area chart', () => {
|
|
|
|
expect(findAreaChart().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
it('sorts the dates in ascending order', () => {
|
|
|
|
expect(wrapper.vm.sortedData).toEqual(sortedDataByDates);
|
|
|
|
});
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
it('shows no error messages', () => {
|
|
|
|
expect(findAlert().exists()).toBe(false);
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
it('does not render download button', () => {
|
|
|
|
expect(findDownloadButton().exists()).toBe(true);
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('when fetching data fails', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
2023-03-17 16:20:25 +05:30
|
|
|
mockAxios.onGet().replyOnce(HTTP_STATUS_BAD_REQUEST);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockAxios.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an error message', () => {
|
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
expect(findAlert().attributes().variant).toBe('danger');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('still renders an empty graph', () => {
|
|
|
|
expect(findAreaChart().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when fetching data succeed but returns an empty state', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
2023-03-17 16:20:25 +05:30
|
|
|
mockAxios.onGet().replyOnce(HTTP_STATUS_OK, []);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mockAxios.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders an information message', () => {
|
|
|
|
expect(findAlert().exists()).toBe(true);
|
|
|
|
expect(findAlert().attributes().variant).toBe('info');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('still renders an empty graph', () => {
|
|
|
|
expect(findAreaChart().exists()).toBe(true);
|
|
|
|
});
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
it('does not render download button', () => {
|
|
|
|
expect(findDownloadButton().exists()).toBe(false);
|
|
|
|
});
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('dropdown options', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
2023-03-17 16:20:25 +05:30
|
|
|
mockAxios.onGet().replyOnce(HTTP_STATUS_OK, codeCoverageMockData);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the dropdown with all custom names as options', () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(findListBox().exists()).toBe(true);
|
|
|
|
expect(findListBoxItems()).toHaveLength(codeCoverageMockData.length);
|
|
|
|
expect(findFirstListBoxItem().text()).toBe(codeCoverageMockData[0].group_name);
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('interactions', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mockAxios = new MockAdapter(axios);
|
2023-03-17 16:20:25 +05:30
|
|
|
mockAxios.onGet().replyOnce(HTTP_STATUS_OK, codeCoverageMockData);
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
return waitForPromises();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the selected dropdown option with an icon', async () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
findListBox().vm.$emit('select', '1');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
expect(findFirstListBoxItem().attributes('isselected')).toBeUndefined();
|
|
|
|
expect(findSecondListBoxItem().attributes('isselected')).toBe('true');
|
2020-06-23 00:09:42 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('updates the graph data when selecting a different option in dropdown', async () => {
|
|
|
|
const originalSelectedData = wrapper.vm.selectedDailyCoverage;
|
|
|
|
const expectedData = codeCoverageMockData[1];
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
findListBox().vm.$emit('select', '1');
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
await nextTick();
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
expect(wrapper.vm.selectedDailyCoverage).not.toBe(originalSelectedData);
|
|
|
|
expect(wrapper.vm.selectedDailyCoverage).toBe(expectedData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|