debian-mirror-gitlab/spec/frontend/pipelines/unwrapping_utils_spec.js

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

128 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import {
unwrapGroups,
unwrapNodesWithName,
unwrapStagesWithNeeds,
} from '~/pipelines/components/unwrapping_utils';
const groupsArray = [
{
name: 'build_a',
size: 1,
status: {
label: 'passed',
group: 'success',
icon: 'status_success',
},
},
{
name: 'bob_the_build',
size: 1,
status: {
label: 'passed',
group: 'success',
icon: 'status_success',
},
},
];
const basicStageInfo = {
name: 'center_stage',
status: {
action: null,
},
};
const stagesAndGroups = [
{
...basicStageInfo,
groups: {
nodes: groupsArray,
},
},
];
const needArray = [
{
name: 'build_b',
},
];
const elephantArray = [
{
name: 'build_b',
elephant: 'gray',
},
];
const baseJobs = {
name: 'test_d',
status: {
icon: 'status_success',
tooltip: null,
hasDetails: true,
detailsPath: '/root/abcd-dag/-/pipelines/162',
group: 'success',
action: null,
},
};
const jobArrayWithNeeds = [
{
...baseJobs,
needs: {
nodes: needArray,
},
},
];
const jobArrayWithElephant = [
{
...baseJobs,
needs: {
nodes: elephantArray,
},
},
];
const completeMock = [
{
...basicStageInfo,
groups: {
2021-03-08 18:12:59 +05:30
nodes: groupsArray.map((group) => ({ ...group, jobs: { nodes: jobArrayWithNeeds } })),
2021-02-22 17:27:13 +05:30
},
},
];
describe('Shared pipeline unwrapping utils', () => {
describe('unwrapGroups', () => {
it('takes stages without nodes and returns the unwrapped groups', () => {
2021-04-29 21:17:54 +05:30
expect(unwrapGroups(stagesAndGroups)[0].node.groups).toEqual(groupsArray);
2021-02-22 17:27:13 +05:30
});
it('keeps other stage properties intact', () => {
2021-04-29 21:17:54 +05:30
expect(unwrapGroups(stagesAndGroups)[0].node).toMatchObject(basicStageInfo);
2021-02-22 17:27:13 +05:30
});
});
describe('unwrapNodesWithName', () => {
it('works with no field argument', () => {
expect(unwrapNodesWithName(jobArrayWithNeeds, 'needs')[0].needs).toEqual([needArray[0].name]);
});
it('works with custom field argument', () => {
expect(unwrapNodesWithName(jobArrayWithElephant, 'needs', 'elephant')[0].needs).toEqual([
elephantArray[0].elephant,
]);
});
});
describe('unwrapStagesWithNeeds', () => {
it('removes nodes from groups, jobs, and needs', () => {
const firstProcessedGroup = unwrapStagesWithNeeds(completeMock)[0].groups[0];
expect(firstProcessedGroup).toMatchObject(groupsArray[0]);
expect(firstProcessedGroup.jobs[0]).toMatchObject(baseJobs);
expect(firstProcessedGroup.jobs[0].needs[0]).toBe(needArray[0].name);
});
});
});