debian-mirror-gitlab/spec/frontend/pipelines/components/pipeline_tabs_spec.js

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

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-06-21 17:19:12 +05:30
import { shallowMount } from '@vue/test-utils';
2022-07-23 23:45:48 +05:30
import { GlTab } from '@gitlab/ui';
2022-06-21 17:19:12 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import PipelineTabs from '~/pipelines/components/pipeline_tabs.vue';
describe('The Pipeline Tabs', () => {
let wrapper;
const findDagTab = () => wrapper.findByTestId('dag-tab');
const findFailedJobsTab = () => wrapper.findByTestId('failed-jobs-tab');
const findJobsTab = () => wrapper.findByTestId('jobs-tab');
const findPipelineTab = () => wrapper.findByTestId('pipeline-tab');
const findTestsTab = () => wrapper.findByTestId('tests-tab');
2022-07-23 23:45:48 +05:30
const findFailedJobsBadge = () => wrapper.findByTestId('failed-builds-counter');
const findJobsBadge = () => wrapper.findByTestId('builds-counter');
2022-08-27 11:52:29 +05:30
const findTestsBadge = () => wrapper.findByTestId('tests-counter');
2022-07-23 23:45:48 +05:30
2022-07-16 23:28:13 +05:30
const defaultProvide = {
defaultTabValue: '',
2022-07-23 23:45:48 +05:30
failedJobsCount: 1,
totalJobCount: 10,
2022-08-27 11:52:29 +05:30
testsCount: 123,
2022-07-16 23:28:13 +05:30
};
2022-07-23 23:45:48 +05:30
const createComponent = (provide = {}) => {
2022-06-21 17:19:12 +05:30
wrapper = extendedWrapper(
shallowMount(PipelineTabs, {
2022-07-16 23:28:13 +05:30
provide: {
...defaultProvide,
2022-07-23 23:45:48 +05:30
...provide,
2022-07-16 23:28:13 +05:30
},
2022-06-21 17:19:12 +05:30
stubs: {
2022-07-23 23:45:48 +05:30
GlTab,
2023-01-13 00:05:48 +05:30
RouterView: true,
2022-06-21 17:19:12 +05:30
},
}),
);
};
describe('Tabs', () => {
it.each`
2023-01-13 00:05:48 +05:30
tabName | tabComponent
${'Pipeline'} | ${findPipelineTab}
${'Dag'} | ${findDagTab}
${'Jobs'} | ${findJobsTab}
${'Failed Jobs'} | ${findFailedJobsTab}
${'Tests'} | ${findTestsTab}
`('shows $tabName tab', ({ tabComponent }) => {
2022-07-23 23:45:48 +05:30
createComponent();
2022-06-21 17:19:12 +05:30
expect(tabComponent().exists()).toBe(true);
});
2022-07-23 23:45:48 +05:30
describe('with no failed jobs', () => {
beforeEach(() => {
createComponent({ failedJobsCount: 0 });
});
it('hides the failed jobs tab', () => {
expect(findFailedJobsTab().exists()).toBe(false);
});
});
});
describe('Tabs badges', () => {
it.each`
tabName | badgeComponent | badgeText
${'Jobs'} | ${findJobsBadge} | ${String(defaultProvide.totalJobCount)}
${'Failed Jobs'} | ${findFailedJobsBadge} | ${String(defaultProvide.failedJobsCount)}
2022-08-27 11:52:29 +05:30
${'Tests'} | ${findTestsBadge} | ${String(defaultProvide.testsCount)}
2022-07-23 23:45:48 +05:30
`('shows badge for $tabName with the correct text', ({ badgeComponent, badgeText }) => {
createComponent();
expect(badgeComponent().exists()).toBe(true);
expect(badgeComponent().text()).toBe(badgeText);
});
2022-06-21 17:19:12 +05:30
});
});