2019-12-26 22:10:19 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
|
|
|
import Summary from '~/pipelines/components/test_reports/test_summary.vue';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
describe('Test reports summary', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
const {
|
|
|
|
test_suites: [testSuite],
|
|
|
|
} = getJSONFixture('pipelines/test_report.json');
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const backButton = () => wrapper.find('.js-back-button');
|
|
|
|
const totalTests = () => wrapper.find('.js-total-tests');
|
|
|
|
const failedTests = () => wrapper.find('.js-failed-tests');
|
|
|
|
const erroredTests = () => wrapper.find('.js-errored-tests');
|
|
|
|
const successRate = () => wrapper.find('.js-success-rate');
|
|
|
|
const duration = () => wrapper.find('.js-duration');
|
|
|
|
|
|
|
|
const defaultProps = {
|
2020-01-01 13:55:28 +05:30
|
|
|
report: testSuite,
|
2019-12-26 22:10:19 +05:30
|
|
|
showBack: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = props => {
|
|
|
|
wrapper = mount(Summary, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('should not render', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('a back button by default', () => {
|
|
|
|
expect(backButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('should render', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('a back button and emit on-back-click event', () => {
|
|
|
|
createComponent({
|
|
|
|
showBack: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(backButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when a report is supplied', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct total', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(totalTests().text()).toBe('4 tests');
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct failure count', () => {
|
|
|
|
expect(failedTests().text()).toBe('2 failures');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correct error count', () => {
|
|
|
|
expect(erroredTests().text()).toBe('0 errors');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calculates and displays percentages correctly', () => {
|
|
|
|
expect(successRate().text()).toBe('50% success rate');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays the correctly formatted duration', () => {
|
2020-01-01 13:55:28 +05:30
|
|
|
expect(duration().text()).toBe('00:00:00');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('success percentage calculation', () => {
|
|
|
|
it.each`
|
2020-05-24 23:13:21 +05:30
|
|
|
name | successCount | totalCount | skippedCount | result
|
|
|
|
${'displays 0 when there are no tests'} | ${0} | ${0} | ${0} | ${'0'}
|
|
|
|
${'displays whole number when possible'} | ${10} | ${50} | ${0} | ${'20'}
|
|
|
|
${'excludes skipped tests from total'} | ${10} | ${50} | ${5} | ${'22.22'}
|
|
|
|
${'rounds to 0.01'} | ${1} | ${16604} | ${0} | ${'0.01'}
|
|
|
|
${'correctly rounds to 50'} | ${8302} | ${16604} | ${0} | ${'50'}
|
|
|
|
${'rounds down for large close numbers'} | ${16603} | ${16604} | ${0} | ${'99.99'}
|
|
|
|
${'correctly displays 100'} | ${16604} | ${16604} | ${0} | ${'100'}
|
|
|
|
`('$name', ({ successCount, totalCount, skippedCount, result }) => {
|
2020-01-01 13:55:28 +05:30
|
|
|
createComponent({
|
|
|
|
report: {
|
|
|
|
success_count: successCount,
|
2020-05-24 23:13:21 +05:30
|
|
|
skipped_count: skippedCount,
|
2020-01-01 13:55:28 +05:30
|
|
|
total_count: totalCount,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(successRate().text()).toBe(`${result}% success rate`);
|
2019-12-26 22:10:19 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|