2019-12-26 22:10:19 +05:30
|
|
|
import Vuex from 'vuex';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2019-12-26 22:10:19 +05:30
|
|
|
import SuiteTable from '~/pipelines/components/test_reports/test_suite_table.vue';
|
|
|
|
import * as getters from '~/pipelines/stores/test_reports/getters';
|
|
|
|
import { TestStatus } from '~/pipelines/constants';
|
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;
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const noCasesMessage = () => wrapper.find('.js-no-test-cases');
|
|
|
|
const allCaseRows = () => wrapper.findAll('.js-case-row');
|
|
|
|
const findCaseRowAtIndex = index => wrapper.findAll('.js-case-row').at(index);
|
|
|
|
const findIconForRow = (row, status) => row.find(`.ci-status-icon-${status}`);
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
const createComponent = (suite = testSuite) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
2020-07-28 23:09:34 +05:30
|
|
|
testReports: {
|
|
|
|
test_suites: [suite],
|
|
|
|
},
|
|
|
|
selectedSuiteIndex: 0,
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
getters,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMount(SuiteTable, {
|
|
|
|
store,
|
2020-07-28 23:09:34 +05:30
|
|
|
localVue,
|
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', () => {
|
|
|
|
expect(allCaseRows().length).toBe(testCases.length);
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it.each([
|
|
|
|
TestStatus.ERROR,
|
|
|
|
TestStatus.FAILED,
|
|
|
|
TestStatus.SKIPPED,
|
|
|
|
TestStatus.SUCCESS,
|
|
|
|
'unknown',
|
|
|
|
])('renders the correct icon for test case with %s status', status => {
|
|
|
|
const test = testCases.findIndex(x => x.status === status);
|
|
|
|
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];
|
|
|
|
const row = findCaseRowAtIndex(0);
|
|
|
|
const button = row.find(GlButton);
|
2019-12-26 22:10:19 +05:30
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|