1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
import { GlTable } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import JobsTable from '~/ci/jobs_page/components/jobs_table.vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { DEFAULT_FIELDS_ADMIN } from '~/ci/admin/jobs_table/constants';
import ProjectCell from '~/ci/admin/jobs_table/components/cells/project_cell.vue';
import RunnerCell from '~/ci/admin/jobs_table/components/cells/runner_cell.vue';
import { mockJobsNodes, mockAllJobsNodes } from 'jest/ci/jobs_mock_data';
describe('Jobs Table', () => {
let wrapper;
const findTable = () => wrapper.findComponent(GlTable);
const findCiIcon = () => wrapper.findComponent(CiIcon);
const findTableRows = () => wrapper.findAllByTestId('jobs-table-row');
const findJobStage = () => wrapper.findByTestId('job-stage-name');
const findJobName = () => wrapper.findByTestId('job-name');
const findJobProject = () => wrapper.findComponent(ProjectCell);
const findJobRunner = () => wrapper.findComponent(RunnerCell);
const findAllCoverageJobs = () => wrapper.findAllByTestId('job-coverage');
const createComponent = (props = {}) => {
wrapper = extendedWrapper(
mount(JobsTable, {
propsData: {
...props,
},
}),
);
};
describe('jobs table', () => {
beforeEach(() => {
createComponent({ jobs: mockJobsNodes });
});
it('displays the jobs table', () => {
expect(findTable().exists()).toBe(true);
});
it('displays correct number of job rows', () => {
expect(findTableRows()).toHaveLength(mockJobsNodes.length);
});
it('displays job status', () => {
expect(findCiIcon().exists()).toBe(true);
});
it('displays the job stage, id and name', () => {
const [firstJob] = mockJobsNodes;
expect(findJobStage().text()).toBe(`Stage: ${firstJob.stage.name}`);
expect(findJobName().text()).toBe(`#${getIdFromGraphQLId(firstJob.id)}: ${firstJob.name}`);
});
it('displays the coverage for only jobs that have coverage', () => {
const jobsThatHaveCoverage = mockJobsNodes.filter((job) => job.coverage !== null);
jobsThatHaveCoverage.forEach((job, index) => {
expect(findAllCoverageJobs().at(index).text()).toBe(`${job.coverage}%`);
});
expect(findAllCoverageJobs()).toHaveLength(jobsThatHaveCoverage.length);
});
describe('when stage of a job is missing', () => {
it('shows no stage', () => {
const stagelessJob = { ...mockJobsNodes[0], stage: null };
createComponent({ jobs: [stagelessJob] });
expect(findJobStage().exists()).toBe(false);
});
});
});
describe('regular user', () => {
beforeEach(() => {
createComponent({ jobs: mockJobsNodes });
});
it('hides the job runner', () => {
expect(findJobRunner().exists()).toBe(false);
});
it('hides the job project link', () => {
expect(findJobProject().exists()).toBe(false);
});
});
describe('admin mode', () => {
beforeEach(() => {
createComponent({ jobs: mockAllJobsNodes, tableFields: DEFAULT_FIELDS_ADMIN, admin: true });
});
it('displays the runner cell', () => {
expect(findJobRunner().exists()).toBe(true);
});
it('displays the project cell', () => {
expect(findJobProject().exists()).toBe(true);
});
it('displays correct number of job rows', () => {
expect(findTableRows()).toHaveLength(mockAllJobsNodes.length);
});
});
});
|