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.

93 lines
3.2 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';
import PipelineGraphWrapper from '~/pipelines/components/graph/graph_component_wrapper.vue';
import Dag from '~/pipelines/components/dag/dag.vue';
import JobsApp from '~/pipelines/components/jobs/jobs_app.vue';
import TestReports from '~/pipelines/components/test_reports/test_reports.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');
const findDagApp = () => wrapper.findComponent(Dag);
const findFailedJobsApp = () => wrapper.findComponent(JobsApp);
const findJobsApp = () => wrapper.findComponent(JobsApp);
const findPipelineApp = () => wrapper.findComponent(PipelineGraphWrapper);
const findTestsApp = () => wrapper.findComponent(TestReports);
2022-07-23 23:45:48 +05:30
const findFailedJobsBadge = () => wrapper.findByTestId('failed-builds-counter');
const findJobsBadge = () => wrapper.findByTestId('builds-counter');
2022-07-16 23:28:13 +05:30
const defaultProvide = {
defaultTabValue: '',
2022-07-23 23:45:48 +05:30
failedJobsCount: 1,
failedJobsSummary: [],
totalJobCount: 10,
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,
2022-06-21 17:19:12 +05:30
TestReports: { template: '<div id="tests" />' },
},
}),
);
};
afterEach(() => {
wrapper.destroy();
});
describe('Tabs', () => {
it.each`
tabName | tabComponent | appComponent
${'Pipeline'} | ${findPipelineTab} | ${findPipelineApp}
${'Dag'} | ${findDagTab} | ${findDagApp}
${'Jobs'} | ${findJobsTab} | ${findJobsApp}
${'Failed Jobs'} | ${findFailedJobsTab} | ${findFailedJobsApp}
${'Tests'} | ${findTestsTab} | ${findTestsApp}
2022-07-23 23:45:48 +05:30
`('shows $tabName tab with its associated component', ({ appComponent, tabComponent }) => {
createComponent();
2022-06-21 17:19:12 +05:30
expect(tabComponent().exists()).toBe(true);
expect(appComponent().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)}
`('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
});
});