debian-mirror-gitlab/spec/frontend/jobs/components/table/jobs_table_spec.js

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

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-29 21:17:54 +05:30
import { GlTable } from '@gitlab/ui';
2021-06-08 01:23:25 +05:30
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2021-04-29 21:17:54 +05:30
import JobsTable from '~/jobs/components/table/jobs_table.vue';
2023-03-17 16:20:25 +05:30
import CiBadgeLink from '~/vue_shared/components/ci_badge_link.vue';
2022-08-13 15:12:31 +05:30
import { mockJobsNodes } from '../../mock_data';
2021-04-29 21:17:54 +05:30
describe('Jobs Table', () => {
let wrapper;
const findTable = () => wrapper.findComponent(GlTable);
2023-03-17 16:20:25 +05:30
const findCiBadgeLink = () => wrapper.findComponent(CiBadgeLink);
2021-06-08 01:23:25 +05:30
const findTableRows = () => wrapper.findAllByTestId('jobs-table-row');
const findJobStage = () => wrapper.findByTestId('job-stage-name');
const findJobName = () => wrapper.findByTestId('job-name');
const findAllCoverageJobs = () => wrapper.findAllByTestId('job-coverage');
2021-04-29 21:17:54 +05:30
const createComponent = (props = {}) => {
2021-06-08 01:23:25 +05:30
wrapper = extendedWrapper(
mount(JobsTable, {
propsData: {
2022-08-13 15:12:31 +05:30
jobs: mockJobsNodes,
2021-06-08 01:23:25 +05:30
...props,
},
}),
);
2021-04-29 21:17:54 +05:30
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
2021-06-08 01:23:25 +05:30
it('displays the jobs table', () => {
2021-04-29 21:17:54 +05:30
expect(findTable().exists()).toBe(true);
});
2021-06-08 01:23:25 +05:30
it('displays correct number of job rows', () => {
2022-08-13 15:12:31 +05:30
expect(findTableRows()).toHaveLength(mockJobsNodes.length);
2021-06-08 01:23:25 +05:30
});
it('displays job status', () => {
2023-03-17 16:20:25 +05:30
expect(findCiBadgeLink().exists()).toBe(true);
2021-06-08 01:23:25 +05:30
});
it('displays the job stage and name', () => {
2022-08-13 15:12:31 +05:30
const firstJob = mockJobsNodes[0];
2021-06-08 01:23:25 +05:30
expect(findJobStage().text()).toBe(firstJob.stage.name);
expect(findJobName().text()).toBe(firstJob.name);
});
it('displays the coverage for only jobs that have coverage', () => {
2022-08-13 15:12:31 +05:30
const jobsThatHaveCoverage = mockJobsNodes.filter((job) => job.coverage !== null);
2021-06-08 01:23:25 +05:30
jobsThatHaveCoverage.forEach((job, index) => {
expect(findAllCoverageJobs().at(index).text()).toBe(`${job.coverage}%`);
});
expect(findAllCoverageJobs()).toHaveLength(jobsThatHaveCoverage.length);
});
2021-04-29 21:17:54 +05:30
});