Commit da1a2bd6 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'winh-refactor-job-groups' into 'master'

Replace job with group in frontend components to be consistent with backend

See merge request gitlab-org/gitlab-ce!22387
parents b2da681f b01dacff
...@@ -70,7 +70,7 @@ export default { ...@@ -70,7 +70,7 @@ export default {
v-for="(stage, index) in graph" v-for="(stage, index) in graph"
:key="stage.name" :key="stage.name"
:title="capitalizeStageName(stage.name)" :title="capitalizeStageName(stage.name)"
:jobs="stage.groups" :groups="stage.groups"
:stage-connector-class="stageConnectorClass(index, stage)" :stage-connector-class="stageConnectorClass(index, stage)"
:is-first-column="isFirstColumn(index)" :is-first-column="isFirstColumn(index)"
@refreshPipelineGraph="refreshPipelineGraph" @refreshPipelineGraph="refreshPipelineGraph"
......
<script> <script>
import $ from 'jquery'; import $ from 'jquery';
import JobNameComponent from './job_name_component.vue'; import CiIcon from '~/vue_shared/components/ci_icon.vue';
import JobComponent from './job_component.vue'; import JobItem from './job_item.vue';
import tooltip from '../../../vue_shared/directives/tooltip'; import tooltip from '../../../vue_shared/directives/tooltip';
/** /**
* Renders the dropdown for the pipeline graph. * Renders the dropdown for the pipeline graph.
* *
* The following object should be provided as `job`: * The object provided as `group` corresponds to app/serializers/job_group_entity.rb.
* *
* {
* "id": 4256,
* "name": "test",
* "status": {
* "icon": "status_success",
* "text": "passed",
* "label": "passed",
* "group": "success",
* "details_path": "/root/ci-mock/builds/4256",
* "action": {
* "icon": "retry",
* "title": "Retry",
* "path": "/root/ci-mock/builds/4256/retry",
* "method": "post"
* }
* }
* }
*/ */
export default { export default {
directives: { directives: {
...@@ -33,12 +16,12 @@ export default { ...@@ -33,12 +16,12 @@ export default {
}, },
components: { components: {
JobComponent, JobItem,
JobNameComponent, CiIcon,
}, },
props: { props: {
job: { group: {
type: Object, type: Object,
required: true, required: true,
}, },
...@@ -46,7 +29,8 @@ export default { ...@@ -46,7 +29,8 @@ export default {
computed: { computed: {
tooltipText() { tooltipText() {
return `${this.job.name} - ${this.job.status.label}`; const { name, status } = this.group;
return `${name} - ${status.label}`;
}, },
}, },
...@@ -56,7 +40,7 @@ export default { ...@@ -56,7 +40,7 @@ export default {
methods: { methods: {
/** /**
* When the user right clicks or cmd/ctrl + click in the job name or the action icon * When the user right clicks or cmd/ctrl + click in the group name or the action icon
* the dropdown should not be closed so we stop propagation * the dropdown should not be closed so we stop propagation
* of the click event inside the dropdown. * of the click event inside the dropdown.
* *
...@@ -90,14 +74,14 @@ export default { ...@@ -90,14 +74,14 @@ export default {
data-display="static" data-display="static"
class="dropdown-menu-toggle build-content" class="dropdown-menu-toggle build-content"
> >
<ci-icon :status="group.status" />
<job-name-component <span class="ci-status-text">
:name="job.name" {{ group.name }}
:status="job.status" </span>
/>
<span class="dropdown-counter-badge"> <span class="dropdown-counter-badge">
{{ job.size }} {{ group.size }}
</span> </span>
</button> </button>
...@@ -105,12 +89,12 @@ export default { ...@@ -105,12 +89,12 @@ export default {
<li class="scrollable-menu"> <li class="scrollable-menu">
<ul> <ul>
<li <li
v-for="(item, i) in job.jobs" v-for="job in group.jobs"
:key="i" :key="job.id"
> >
<job-component <job-item
:dropdown-length="job.size" :dropdown-length="group.size"
:job="item" :job="job"
css-class-job-name="mini-pipeline-graph-dropdown-item" css-class-job-name="mini-pipeline-graph-dropdown-item"
@pipelineActionRequestComplete="pipelineActionRequestComplete" @pipelineActionRequestComplete="pipelineActionRequestComplete"
/> />
......
<script> <script>
import _ from 'underscore'; import _ from 'underscore';
import JobComponent from './job_component.vue'; import JobItem from './job_item.vue';
import DropdownJobComponent from './dropdown_job_component.vue'; import JobGroupDropdown from './job_group_dropdown.vue';
export default { export default {
components: { components: {
JobComponent, JobItem,
DropdownJobComponent, JobGroupDropdown,
}, },
props: { props: {
title: { title: {
...@@ -14,7 +14,7 @@ export default { ...@@ -14,7 +14,7 @@ export default {
required: true, required: true,
}, },
jobs: { groups: {
type: Array, type: Array,
required: true, required: true,
}, },
...@@ -33,12 +33,8 @@ export default { ...@@ -33,12 +33,8 @@ export default {
}, },
methods: { methods: {
firstJob(list) { groupId(group) {
return list[0]; return `ci-badge-${_.escape(group.name)}`;
},
jobId(job) {
return `ci-badge-${_.escape(job.name)}`;
}, },
buildConnnectorClass(index) { buildConnnectorClass(index) {
...@@ -61,25 +57,25 @@ export default { ...@@ -61,25 +57,25 @@ export default {
<div class="builds-container"> <div class="builds-container">
<ul> <ul>
<li <li
v-for="(job, index) in jobs" v-for="(group, index) in groups"
:id="jobId(job)" :id="groupId(group)"
:key="job.id" :key="group.id"
:class="buildConnnectorClass(index)" :class="buildConnnectorClass(index)"
class="build" class="build"
> >
<div class="curve"></div> <div class="curve"></div>
<job-component <job-item
v-if="job.size === 1" v-if="group.size === 1"
:job="job" :job="group.jobs[0]"
css-class-job-name="build-content" css-class-job-name="build-content"
@pipelineActionRequestComplete="pipelineActionRequestComplete" @pipelineActionRequestComplete="pipelineActionRequestComplete"
/> />
<dropdown-job-component <job-group-dropdown
v-if="job.size > 1" v-if="group.size > 1"
:job="job" :group="group"
@pipelineActionRequestComplete="pipelineActionRequestComplete" @pipelineActionRequestComplete="pipelineActionRequestComplete"
/> />
......
...@@ -18,14 +18,14 @@ import Flash from '../../flash'; ...@@ -18,14 +18,14 @@ import Flash from '../../flash';
import axios from '../../lib/utils/axios_utils'; import axios from '../../lib/utils/axios_utils';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import Icon from '../../vue_shared/components/icon.vue'; import Icon from '../../vue_shared/components/icon.vue';
import JobComponent from './graph/job_component.vue'; import JobItem from './graph/job_item.vue';
import tooltip from '../../vue_shared/directives/tooltip'; import tooltip from '../../vue_shared/directives/tooltip';
import { PIPELINES_TABLE } from '../constants'; import { PIPELINES_TABLE } from '../constants';
export default { export default {
components: { components: {
Icon, Icon,
JobComponent, JobItem,
}, },
directives: { directives: {
...@@ -198,7 +198,7 @@ export default { ...@@ -198,7 +198,7 @@ export default {
v-for="job in dropdownContent" v-for="job in dropdownContent"
:key="job.id" :key="job.id"
> >
<job-component <job-item
:dropdown-length="dropdownContent.length" :dropdown-length="dropdownContent.length"
:job="job" :job="job"
css-class-job-name="mini-pipeline-graph-dropdown-item" css-class-job-name="mini-pipeline-graph-dropdown-item"
......
...@@ -9,7 +9,7 @@ module QA::Page ...@@ -9,7 +9,7 @@ module QA::Page
element :pipeline_graph, /class.*pipeline-graph.*/ # rubocop:disable QA/ElementWithPattern element :pipeline_graph, /class.*pipeline-graph.*/ # rubocop:disable QA/ElementWithPattern
end end
view 'app/assets/javascripts/pipelines/components/graph/job_component.vue' do view 'app/assets/javascripts/pipelines/components/graph/job_item.vue' do
element :job_component, /class.*ci-job-component.*/ # rubocop:disable QA/ElementWithPattern element :job_component, /class.*ci-job-component.*/ # rubocop:disable QA/ElementWithPattern
element :job_link, /class.*js-pipeline-graph-job-link.*/ # rubocop:disable QA/ElementWithPattern element :job_link, /class.*js-pipeline-graph-job-link.*/ # rubocop:disable QA/ElementWithPattern
end end
......
import Vue from 'vue'; import Vue from 'vue';
import component from '~/pipelines/components/graph/dropdown_job_component.vue'; import JobGroupDropdown from '~/pipelines/components/graph/job_group_dropdown.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('dropdown job component', () => { describe('job group dropdown component', () => {
const Component = Vue.extend(component); const Component = Vue.extend(JobGroupDropdown);
let vm; let vm;
const mock = { const group = {
jobs: [ jobs: [
{ {
id: 4256, id: 4256,
...@@ -71,15 +71,15 @@ describe('dropdown job component', () => { ...@@ -71,15 +71,15 @@ describe('dropdown job component', () => {
}); });
beforeEach(() => { beforeEach(() => {
vm = mountComponent(Component, { job: mock }); vm = mountComponent(Component, { group });
}); });
it('renders button with job name and size', () => { it('renders button with group name and size', () => {
expect(vm.$el.querySelector('button').textContent).toContain(mock.name); expect(vm.$el.querySelector('button').textContent).toContain(group.name);
expect(vm.$el.querySelector('button').textContent).toContain(mock.size); expect(vm.$el.querySelector('button').textContent).toContain(group.size);
}); });
it('renders dropdown with jobs', () => { it('renders dropdown with jobs', () => {
expect(vm.$el.querySelectorAll('.scrollable-menu>ul>li').length).toEqual(mock.jobs.length); expect(vm.$el.querySelectorAll('.scrollable-menu>ul>li').length).toEqual(group.jobs.length);
}); });
}); });
import Vue from 'vue'; import Vue from 'vue';
import jobComponent from '~/pipelines/components/graph/job_component.vue'; import JobItem from '~/pipelines/components/graph/job_item.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('pipeline graph job component', () => { describe('pipeline graph job item', () => {
const JobComponent = Vue.extend(jobComponent); const JobComponent = Vue.extend(JobItem);
let component; let component;
const mockJob = { const mockJob = {
......
...@@ -25,17 +25,16 @@ describe('stage column component', () => { ...@@ -25,17 +25,16 @@ describe('stage column component', () => {
}; };
beforeEach(() => { beforeEach(() => {
const mockGroups = [];
const mockJobs = [];
for (let i = 0; i < 3; i += 1) { for (let i = 0; i < 3; i += 1) {
const mockedJob = Object.assign({}, mockJob); const mockedJob = Object.assign({}, mockJob);
mockedJob.id += i; mockedJob.id += i;
mockJobs.push(mockedJob); mockGroups.push(mockedJob);
} }
component = mountComponent(StageColumnComponent, { component = mountComponent(StageColumnComponent, {
title: 'foo', title: 'foo',
jobs: mockJobs, groups: mockGroups,
}); });
}); });
...@@ -43,14 +42,14 @@ describe('stage column component', () => { ...@@ -43,14 +42,14 @@ describe('stage column component', () => {
expect(component.$el.querySelector('.stage-name').textContent.trim()).toEqual('foo'); expect(component.$el.querySelector('.stage-name').textContent.trim()).toEqual('foo');
}); });
it('should render the provided jobs', () => { it('should render the provided groups', () => {
expect(component.$el.querySelectorAll('.builds-container > ul > li').length).toEqual(3); expect(component.$el.querySelectorAll('.builds-container > ul > li').length).toEqual(3);
}); });
describe('jobId', () => { describe('jobId', () => {
it('escapes job name', () => { it('escapes job name', () => {
component = mountComponent(StageColumnComponent, { component = mountComponent(StageColumnComponent, {
jobs: [ groups: [
{ {
id: 4259, id: 4259,
name: '<img src=x onerror=alert(document.domain)>', name: '<img src=x onerror=alert(document.domain)>',
...@@ -64,9 +63,9 @@ describe('stage column component', () => { ...@@ -64,9 +63,9 @@ describe('stage column component', () => {
title: 'test', title: 'test',
}); });
expect( expect(component.$el.querySelector('.builds-container li').getAttribute('id')).toEqual(
component.$el.querySelector('.builds-container li').getAttribute('id'), 'ci-badge-&lt;img src=x onerror=alert(document.domain)&gt;',
).toEqual('ci-badge-&lt;img src=x onerror=alert(document.domain)&gt;'); );
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment