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';
2021-06-08 01:23:25 +05:30
import CiBadge from '~/vue_shared/components/ci_badge_link.vue';
2021-04-29 21:17:54 +05:30
import { mockJobsInTable } from '../../mock_data';
describe('Jobs Table', () => {
let wrapper;
const findTable = () => wrapper.findComponent(GlTable);
2021-06-08 01:23:25 +05:30
const findStatusBadge = () => wrapper.findComponent(CiBadge);
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: {
jobs: mockJobsInTable,
...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', () => {
expect(findTableRows()).toHaveLength(mockJobsInTable.length);
});
it('displays job status', () => {
expect(findStatusBadge().exists()).toBe(true);
});
it('displays the job stage and name', () => {
const firstJob = mockJobsInTable[0];
expect(findJobStage().text()).toBe(firstJob.stage.name);
expect(findJobName().text()).toBe(firstJob.name);
});
it('displays the coverage for only jobs that have coverage', () => {
const jobsThatHaveCoverage = mockJobsInTable.filter((job) => job.coverage !== null);
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
});