debian-mirror-gitlab/spec/frontend/pipelines/test_reports/test_suite_table_spec.js

146 lines
4.2 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import { GlButton, GlFriendlyWrap, GlLink, GlPagination } from '@gitlab/ui';
2020-07-28 23:09:34 +05:30
import { shallowMount, createLocalVue } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2020-01-01 13:55:28 +05:30
import { getJSONFixture } from 'helpers/fixtures';
2019-12-26 22:10:19 +05:30
import SuiteTable from '~/pipelines/components/test_reports/test_suite_table.vue';
import { TestStatus } from '~/pipelines/constants';
2021-03-11 19:13:27 +05:30
import * as getters from '~/pipelines/stores/test_reports/getters';
import { formatFilePath } from '~/pipelines/stores/test_reports/utils';
2020-01-01 13:55:28 +05:30
import skippedTestCases from './mock_data';
2019-12-26 22:10:19 +05:30
2020-07-28 23:09:34 +05:30
const localVue = createLocalVue();
localVue.use(Vuex);
2019-12-26 22:10:19 +05:30
describe('Test reports suite table', () => {
let wrapper;
let store;
2020-01-01 13:55:28 +05:30
const {
test_suites: [testSuite],
} = getJSONFixture('pipelines/test_report.json');
testSuite.test_cases = [...testSuite.test_cases, ...skippedTestCases];
const testCases = testSuite.test_cases;
2021-03-11 19:13:27 +05:30
const blobPath = '/test/blob/path';
2020-01-01 13:55:28 +05:30
2019-12-26 22:10:19 +05:30
const noCasesMessage = () => wrapper.find('.js-no-test-cases');
const allCaseRows = () => wrapper.findAll('.js-case-row');
2021-03-08 18:12:59 +05:30
const findCaseRowAtIndex = (index) => wrapper.findAll('.js-case-row').at(index);
2021-03-11 19:13:27 +05:30
const findLinkForRow = (row) => row.find(GlLink);
2019-12-26 22:10:19 +05:30
const findIconForRow = (row, status) => row.find(`.ci-status-icon-${status}`);
2021-02-22 17:27:13 +05:30
const createComponent = (suite = testSuite, perPage = 20) => {
2019-12-26 22:10:19 +05:30
store = new Vuex.Store({
state: {
2021-03-11 19:13:27 +05:30
blobPath,
2020-07-28 23:09:34 +05:30
testReports: {
test_suites: [suite],
},
selectedSuiteIndex: 0,
2021-02-22 17:27:13 +05:30
pageInfo: {
page: 1,
perPage,
},
2019-12-26 22:10:19 +05:30
},
getters,
});
wrapper = shallowMount(SuiteTable, {
store,
2020-07-28 23:09:34 +05:30
localVue,
2021-01-29 00:20:46 +05:30
stubs: { GlFriendlyWrap },
2019-12-26 22:10:19 +05:30
});
};
afterEach(() => {
wrapper.destroy();
});
describe('should not render', () => {
beforeEach(() => createComponent([]));
it('a table when there are no test cases', () => {
expect(noCasesMessage().exists()).toBe(true);
});
});
describe('when a test suite is supplied', () => {
beforeEach(() => createComponent());
it('renders the correct number of rows', () => {
2021-03-11 19:13:27 +05:30
expect(allCaseRows()).toHaveLength(testCases.length);
2019-12-26 22:10:19 +05:30
});
2021-01-03 14:25:43 +05:30
it.each([
TestStatus.ERROR,
TestStatus.FAILED,
TestStatus.SKIPPED,
TestStatus.SUCCESS,
'unknown',
2021-03-08 18:12:59 +05:30
])('renders the correct icon for test case with %s status', (status) => {
const test = testCases.findIndex((x) => x.status === status);
2021-01-03 14:25:43 +05:30
const row = findCaseRowAtIndex(test);
2019-12-26 22:10:19 +05:30
2021-01-03 14:25:43 +05:30
expect(findIconForRow(row, status).exists()).toBe(true);
});
it('renders the file name for the test with a copy button', () => {
const { file } = testCases[0];
2021-03-11 19:13:27 +05:30
const relativeFile = formatFilePath(file);
const filePath = `${blobPath}/${relativeFile}`;
2021-01-03 14:25:43 +05:30
const row = findCaseRowAtIndex(0);
2021-03-11 19:13:27 +05:30
const fileLink = findLinkForRow(row);
2021-01-03 14:25:43 +05:30
const button = row.find(GlButton);
2019-12-26 22:10:19 +05:30
2021-03-11 19:13:27 +05:30
expect(fileLink.attributes('href')).toBe(filePath);
2021-01-03 14:25:43 +05:30
expect(row.text()).toContain(file);
expect(button.exists()).toBe(true);
expect(button.attributes('data-clipboard-text')).toBe(file);
2019-12-26 22:10:19 +05:30
});
});
2021-02-22 17:27:13 +05:30
describe('when a test suite has more test cases than the pagination size', () => {
const perPage = 2;
beforeEach(() => {
createComponent(testSuite, perPage);
});
it('renders one page of test cases', () => {
expect(allCaseRows().length).toBe(perPage);
});
it('renders a pagination component', () => {
expect(wrapper.find(GlPagination).exists()).toBe(true);
});
});
2021-03-11 19:13:27 +05:30
describe('when a test case classname property is null', () => {
it('still renders all test cases', () => {
createComponent({
...testSuite,
test_cases: testSuite.test_cases.map((testCase) => ({
...testCase,
classname: null,
})),
});
expect(allCaseRows()).toHaveLength(testCases.length);
});
});
describe('when a test case name property is null', () => {
it('still renders all test cases', () => {
createComponent({
...testSuite,
test_cases: testSuite.test_cases.map((testCase) => ({
...testCase,
name: null,
})),
});
expect(allCaseRows()).toHaveLength(testCases.length);
});
});
2019-12-26 22:10:19 +05:30
});