From 405d8b456f65c7165e8cca83ab0be4c9db6cadd2 Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Thu, 18 Jan 2018 16:22:20 -0600 Subject: [PATCH 1/5] Added pipeline status to the files view --- .../commit_pipeline_status_component.vue | 95 +++++++++++++++++++ .../tree/services/commit_pipeline_service.js | 11 +++ .../pages/projects/tree/show/index.js | 18 ++++ app/assets/stylesheets/pages/commits.scss | 9 ++ app/helpers/ci_status_helper.rb | 11 --- app/views/projects/commits/_commit.html.haml | 7 +- .../commit_pipeline_status_component_spec.js | 68 +++++++++++++ 7 files changed, 202 insertions(+), 17 deletions(-) create mode 100644 app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue create mode 100644 app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js create mode 100644 spec/javascripts/commit/commit_pipeline_status_component_spec.js diff --git a/app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue b/app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue new file mode 100644 index 00000000000..2bd1e8e3266 --- /dev/null +++ b/app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue @@ -0,0 +1,95 @@ + + diff --git a/app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js b/app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js new file mode 100644 index 00000000000..4b4189bc2de --- /dev/null +++ b/app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js @@ -0,0 +1,11 @@ +import axios from '~/lib/utils/axios_utils'; + +export default class CommitPipelineService { + constructor(endpoint) { + this.endpoint = endpoint; + } + + fetchData() { + return axios.get(this.endpoint); + } +} diff --git a/app/assets/javascripts/pages/projects/tree/show/index.js b/app/assets/javascripts/pages/projects/tree/show/index.js index 28a0160f47d..7181d4dfd47 100644 --- a/app/assets/javascripts/pages/projects/tree/show/index.js +++ b/app/assets/javascripts/pages/projects/tree/show/index.js @@ -1,8 +1,10 @@ +import Vue from 'vue'; import TreeView from '../../../../tree'; import ShortcutsNavigation from '../../../../shortcuts_navigation'; import BlobViewer from '../../../../blob/viewer'; import NewCommitForm from '../../../../new_commit_form'; import { ajaxGet } from '../../../../lib/utils/common_utils'; +import commitPipelineStatus from '../components/commit_pipeline_status_component.vue'; export default () => { new ShortcutsNavigation(); // eslint-disable-line no-new @@ -11,5 +13,21 @@ export default () => { new NewCommitForm($('.js-create-dir-form')); // eslint-disable-line no-new $('#tree-slider').waitForImages(() => ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath)); + + const commitPipelineStatusEl = document.getElementById('commit-pipeline-status'); + // eslint-disable-next-line no-new + new Vue({ + el: '#commit-pipeline-status', + components: { + commitPipelineStatus, + }, + render(createElement) { + return createElement('commit-pipeline-status', { + props: { + endpoint: commitPipelineStatusEl.dataset.endpoint, + }, + }); + }, + }); }; diff --git a/app/assets/stylesheets/pages/commits.scss b/app/assets/stylesheets/pages/commits.scss index aeaa33bd3bd..adfd72556b8 100644 --- a/app/assets/stylesheets/pages/commits.scss +++ b/app/assets/stylesheets/pages/commits.scss @@ -195,6 +195,10 @@ .commit-actions { @media (min-width: $screen-sm-min) { font-size: 0; + + span { + font-size: 6px; + } } .ci-status-link { @@ -219,6 +223,11 @@ font-size: 14px; font-weight: $gl-font-weight-bold; } + + .ci-status-icon { + position: relative; + top: 3px; + } } .commit, diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 636316da80a..e8365f1da1e 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -103,17 +103,6 @@ module CiStatusHelper tooltip_placement: tooltip_placement) end - def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left') - project = commit.project - path = pipelines_project_commit_path(project, commit) - - render_status_with_link( - 'commit', - commit.status(ref), - path, - tooltip_placement: tooltip_placement) - end - def render_pipeline_status(pipeline, tooltip_placement: 'auto left') project = pipeline.project path = project_pipeline_path(project, pipeline) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index d66066a6d0b..436e1739180 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -26,9 +26,6 @@ %span.commit-row-message.visible-xs-inline · = commit.short_id - - if commit.status(ref) - .visible-xs-inline - = render_commit_status(commit, ref: ref) - if commit.description? %button.text-expander.hidden-xs.js-toggle-button{ type: "button" } ... @@ -48,9 +45,7 @@ - else = render partial: 'projects/commit/ajax_signature', locals: { commit: commit } - - if commit.status(ref) - = render_commit_status(commit, ref: ref) - + #commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id) } } = link_to commit.short_id, link, class: "commit-sha btn btn-transparent btn-link" = clipboard_button(text: commit.id, title: _("Copy commit SHA to clipboard")) = link_to_browse_code(project, commit) diff --git a/spec/javascripts/commit/commit_pipeline_status_component_spec.js b/spec/javascripts/commit/commit_pipeline_status_component_spec.js new file mode 100644 index 00000000000..f6fca9e97e5 --- /dev/null +++ b/spec/javascripts/commit/commit_pipeline_status_component_spec.js @@ -0,0 +1,68 @@ +import Vue from 'vue'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; +import commitPipelineStatus from '~/pages/projects/tree/components/commit_pipeline_status_component.vue'; +import mountComponent from '../helpers/vue_mount_component_helper'; + +describe('Commit pipeline status component', () => { + let vm; + let component; + let mock; + const mockCiStatus = { + details_path: '/root/hello-world/pipelines/1', + favicon: 'canceled.ico', + group: 'canceled', + has_details: true, + icon: 'status_canceled', + label: 'canceled', + text: 'canceled', + }; + + beforeEach(() => { + mock = new MockAdapter(axios); + mock.onGet('/dummy/endpoint').reply(() => { + const res = Promise.resolve([200, { + pipelines: [ + { + details: { + status: mockCiStatus, + }, + }, + ], + }]); + return res; + }); + component = Vue.extend(commitPipelineStatus); + }); + + afterEach(() => { + mock.reset(); + }); + + describe('While polling pipeline data', () => { + beforeEach(() => { + vm = mountComponent(component, { + endpoint: '/dummy/endpoint', + }); + }); + + afterEach(() => { + vm.poll.stop(); + vm.$destroy(); + }); + + it('contains a ciStatus when the polling is succesful ', (done) => { + setTimeout(() => { + expect(vm.ciStatus).toEqual(mockCiStatus); + done(); + }, 1000); + }); + + it('contains a ci-status icon when polling is succesful', (done) => { + setTimeout(() => { + expect(vm.$el.querySelector('.ci-status-icon')).not.toBe(null); + done(); + }); + }); + }); +}); From 6042454600d79f1d6fb8e216c78b3e8b619a7a3e Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Fri, 19 Jan 2018 15:09:42 -0600 Subject: [PATCH 2/5] Added changelog --- ...5779-realtime-update-of-pipeline-status-in-files-view.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/35779-realtime-update-of-pipeline-status-in-files-view.yml diff --git a/changelogs/unreleased/35779-realtime-update-of-pipeline-status-in-files-view.yml b/changelogs/unreleased/35779-realtime-update-of-pipeline-status-in-files-view.yml new file mode 100644 index 00000000000..82df00fe631 --- /dev/null +++ b/changelogs/unreleased/35779-realtime-update-of-pipeline-status-in-files-view.yml @@ -0,0 +1,5 @@ +--- +title: Add realtime ci status for the repository -> files view +merge_request: 16523 +author: +type: added From bfc2b8a3d2c06c80126365348ce75b3985185e83 Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Mon, 22 Jan 2018 15:57:32 -0600 Subject: [PATCH 3/5] Added realtime prop and corrected specs --- .../javascripts/pages/projects/show/index.js | 19 +++++++++++++++++++ .../pages/projects/tree/show/index.js | 2 +- .../commit_pipeline_status_component.vue | 19 +++++++++++++++---- .../tree/services/commit_pipeline_service.js | 0 features/project/project.feature | 1 + features/steps/shared/project.rb | 1 + .../commit_pipeline_status_component_spec.js | 9 +++++++-- 7 files changed, 44 insertions(+), 7 deletions(-) rename app/assets/javascripts/{pages => }/projects/tree/components/commit_pipeline_status_component.vue (81%) rename app/assets/javascripts/{pages => }/projects/tree/services/commit_pipeline_service.js (100%) diff --git a/app/assets/javascripts/pages/projects/show/index.js b/app/assets/javascripts/pages/projects/show/index.js index 55154cdddcb..0213b46eb7c 100644 --- a/app/assets/javascripts/pages/projects/show/index.js +++ b/app/assets/javascripts/pages/projects/show/index.js @@ -1,3 +1,4 @@ +import Vue from 'vue'; import ShortcutsNavigation from '~/shortcuts_navigation'; import NotificationsForm from '~/notifications_form'; import UserCallout from '~/user_callout'; @@ -5,6 +6,7 @@ import TreeView from '~/tree'; import BlobViewer from '~/blob/viewer/index'; import Activities from '~/activities'; import { ajaxGet } from '~/lib/utils/common_utils'; +import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; import Star from '../../../star'; import notificationsDropdown from '../../../notifications_dropdown'; @@ -24,4 +26,21 @@ export default () => { $('#tree-slider').waitForImages(() => { ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath); }); + + const commitPipelineStatusEl = document.getElementById('commit-pipeline-status'); + // eslint-disable-next-line no-new + new Vue({ + el: '#commit-pipeline-status', + components: { + commitPipelineStatus, + }, + render(createElement) { + return createElement('commit-pipeline-status', { + props: { + endpoint: commitPipelineStatusEl.dataset.endpoint, + realtime: false, + }, + }); + }, + }); }; diff --git a/app/assets/javascripts/pages/projects/tree/show/index.js b/app/assets/javascripts/pages/projects/tree/show/index.js index 7181d4dfd47..c0b3f98e66d 100644 --- a/app/assets/javascripts/pages/projects/tree/show/index.js +++ b/app/assets/javascripts/pages/projects/tree/show/index.js @@ -1,10 +1,10 @@ import Vue from 'vue'; +import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; import TreeView from '../../../../tree'; import ShortcutsNavigation from '../../../../shortcuts_navigation'; import BlobViewer from '../../../../blob/viewer'; import NewCommitForm from '../../../../new_commit_form'; import { ajaxGet } from '../../../../lib/utils/common_utils'; -import commitPipelineStatus from '../components/commit_pipeline_status_component.vue'; export default () => { new ShortcutsNavigation(); // eslint-disable-line no-new diff --git a/app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue similarity index 81% rename from app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue rename to app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue index 2bd1e8e3266..e13acf8555a 100644 --- a/app/assets/javascripts/pages/projects/tree/components/commit_pipeline_status_component.vue +++ b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue @@ -18,22 +18,33 @@ type: String, required: true, }, + realtime: { + type: Boolean, + required: false, + default: true, + }, }, data() { return { ciStatus: {}, isLoading: true, service: {}, + stageTitle: '', }; }, mounted() { this.service = new CommitPipelineService(this.endpoint); - this.initPolling(); + if (this.realtime) { + this.initPolling(); + } else { + this.fetchPipelineCommitData(); + } }, methods: { successCallback(res) { if (res.data.pipelines.length > 0) { - this.ciStatus = res.data.pipelines[0].details.status; + this.ciStatus = res.data.pipelines[0].details.stages[0].status; + this.stageTitle = res.data.pipelines[0].details.stages[0].title; this.isLoading = false; } else { this.isLoading = true; @@ -86,8 +97,8 @@ > diff --git a/app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js b/app/assets/javascripts/projects/tree/services/commit_pipeline_service.js similarity index 100% rename from app/assets/javascripts/pages/projects/tree/services/commit_pipeline_service.js rename to app/assets/javascripts/projects/tree/services/commit_pipeline_service.js diff --git a/features/project/project.feature b/features/project/project.feature index 23817ef3ac9..bcd72c5c5a3 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -23,6 +23,7 @@ Feature: Project And I visit project "Shop" page Then I should see project "Shop" README + @javascript Scenario: I should see last commit with CI Given project "Shop" has CI enabled Given project "Shop" has CI build diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index affbccccdf9..923d54a6545 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -218,6 +218,7 @@ module SharedProject end step 'I should see last commit with CI status' do + sleep 2 page.within ".blob-commit-info" do expect(page).to have_content(project.commit.sha[0..6]) expect(page).to have_link("Commit: skipped") diff --git a/spec/javascripts/commit/commit_pipeline_status_component_spec.js b/spec/javascripts/commit/commit_pipeline_status_component_spec.js index f6fca9e97e5..2a52097e0d5 100644 --- a/spec/javascripts/commit/commit_pipeline_status_component_spec.js +++ b/spec/javascripts/commit/commit_pipeline_status_component_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import MockAdapter from 'axios-mock-adapter'; import axios from '~/lib/utils/axios_utils'; -import commitPipelineStatus from '~/pages/projects/tree/components/commit_pipeline_status_component.vue'; +import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; import mountComponent from '../helpers/vue_mount_component_helper'; describe('Commit pipeline status component', () => { @@ -25,7 +25,12 @@ describe('Commit pipeline status component', () => { pipelines: [ { details: { - status: mockCiStatus, + stages: [ + { + status: mockCiStatus, + title: 'Commit: canceled', + }, + ], }, }, ], From 449b0ebaf6f3ca65b48f372293117acc9a7e0abc Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Mon, 22 Jan 2018 18:34:21 -0600 Subject: [PATCH 4/5] Restored some code, add hidden class --- .../javascripts/pages/projects/show/index.js | 18 ------------------ .../pages/projects/tree/show/index.js | 5 +++++ app/helpers/ci_status_helper.rb | 11 +++++++++++ app/views/projects/commits/_commit.html.haml | 8 +++++++- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/pages/projects/show/index.js b/app/assets/javascripts/pages/projects/show/index.js index 0213b46eb7c..4c42fda16d7 100644 --- a/app/assets/javascripts/pages/projects/show/index.js +++ b/app/assets/javascripts/pages/projects/show/index.js @@ -1,4 +1,3 @@ -import Vue from 'vue'; import ShortcutsNavigation from '~/shortcuts_navigation'; import NotificationsForm from '~/notifications_form'; import UserCallout from '~/user_callout'; @@ -26,21 +25,4 @@ export default () => { $('#tree-slider').waitForImages(() => { ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath); }); - - const commitPipelineStatusEl = document.getElementById('commit-pipeline-status'); - // eslint-disable-next-line no-new - new Vue({ - el: '#commit-pipeline-status', - components: { - commitPipelineStatus, - }, - render(createElement) { - return createElement('commit-pipeline-status', { - props: { - endpoint: commitPipelineStatusEl.dataset.endpoint, - realtime: false, - }, - }); - }, - }); }; diff --git a/app/assets/javascripts/pages/projects/tree/show/index.js b/app/assets/javascripts/pages/projects/tree/show/index.js index c0b3f98e66d..f14c3f86687 100644 --- a/app/assets/javascripts/pages/projects/tree/show/index.js +++ b/app/assets/javascripts/pages/projects/tree/show/index.js @@ -15,6 +15,11 @@ export default () => { ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath)); const commitPipelineStatusEl = document.getElementById('commit-pipeline-status'); + const $statusLink = $('.ci-status-link'); + if ($statusLink.length > 0) { + $statusLink.remove(); + } + commitPipelineStatusEl.classList.remove('hidden'); // eslint-disable-next-line no-new new Vue({ el: '#commit-pipeline-status', diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index e8365f1da1e..636316da80a 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -103,6 +103,17 @@ module CiStatusHelper tooltip_placement: tooltip_placement) end + def render_commit_status(commit, ref: nil, tooltip_placement: 'auto left') + project = commit.project + path = pipelines_project_commit_path(project, commit) + + render_status_with_link( + 'commit', + commit.status(ref), + path, + tooltip_placement: tooltip_placement) + end + def render_pipeline_status(pipeline, tooltip_placement: 'auto left') project = pipeline.project path = project_pipeline_path(project, pipeline) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 436e1739180..c94e10947e6 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -26,6 +26,9 @@ %span.commit-row-message.visible-xs-inline · = commit.short_id + - if commit.status(ref) + .visible-xs-inline + = render_commit_status(commit, ref: ref) - if commit.description? %button.text-expander.hidden-xs.js-toggle-button{ type: "button" } ... @@ -45,7 +48,10 @@ - else = render partial: 'projects/commit/ajax_signature', locals: { commit: commit } - #commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id) } } + - if commit.status(ref) + = render_commit_status(commit, ref: ref) + + #commit-pipeline-status.hidden{ data: { endpoint: pipelines_project_commit_path(project, commit.id) } } = link_to commit.short_id, link, class: "commit-sha btn btn-transparent btn-link" = clipboard_button(text: commit.id, title: _("Copy commit SHA to clipboard")) = link_to_browse_code(project, commit) From 1123d9dc460353cbc3b46606cc2235f0433f35e1 Mon Sep 17 00:00:00 2001 From: Jose Ivan Vargas Date: Tue, 23 Jan 2018 12:50:58 -0600 Subject: [PATCH 5/5] Added more tests and corrected typos --- .../javascripts/pages/projects/show/index.js | 1 - .../pages/projects/tree/show/index.js | 35 ++++---- .../commit_pipeline_status_component.vue | 78 ++++++++++------- app/assets/stylesheets/pages/commits.scss | 10 ++- app/views/projects/commits/_commit.html.haml | 2 +- features/project/project.feature | 1 - features/steps/shared/project.rb | 1 - .../commit_pipeline_status_component_spec.js | 85 +++++++++++++------ 8 files changed, 131 insertions(+), 82 deletions(-) diff --git a/app/assets/javascripts/pages/projects/show/index.js b/app/assets/javascripts/pages/projects/show/index.js index 4c42fda16d7..55154cdddcb 100644 --- a/app/assets/javascripts/pages/projects/show/index.js +++ b/app/assets/javascripts/pages/projects/show/index.js @@ -5,7 +5,6 @@ import TreeView from '~/tree'; import BlobViewer from '~/blob/viewer/index'; import Activities from '~/activities'; import { ajaxGet } from '~/lib/utils/common_utils'; -import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; import Star from '../../../star'; import notificationsDropdown from '../../../notifications_dropdown'; diff --git a/app/assets/javascripts/pages/projects/tree/show/index.js b/app/assets/javascripts/pages/projects/tree/show/index.js index f14c3f86687..c4b3356e478 100644 --- a/app/assets/javascripts/pages/projects/tree/show/index.js +++ b/app/assets/javascripts/pages/projects/tree/show/index.js @@ -15,24 +15,23 @@ export default () => { ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath)); const commitPipelineStatusEl = document.getElementById('commit-pipeline-status'); - const $statusLink = $('.ci-status-link'); - if ($statusLink.length > 0) { - $statusLink.remove(); + const statusLink = document.querySelector('.commit-actions .ci-status-link'); + if (statusLink != null) { + statusLink.remove(); + // eslint-disable-next-line no-new + new Vue({ + el: commitPipelineStatusEl, + components: { + commitPipelineStatus, + }, + render(createElement) { + return createElement('commit-pipeline-status', { + props: { + endpoint: commitPipelineStatusEl.dataset.endpoint, + }, + }); + }, + }); } - commitPipelineStatusEl.classList.remove('hidden'); - // eslint-disable-next-line no-new - new Vue({ - el: '#commit-pipeline-status', - components: { - commitPipelineStatus, - }, - render(createElement) { - return createElement('commit-pipeline-status', { - props: { - endpoint: commitPipelineStatusEl.dataset.endpoint, - }, - }); - }, - }); }; diff --git a/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue index e13acf8555a..63f20a0041d 100644 --- a/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue +++ b/app/assets/javascripts/projects/tree/components/commit_pipeline_status_component.vue @@ -1,8 +1,10 @@ diff --git a/app/assets/stylesheets/pages/commits.scss b/app/assets/stylesheets/pages/commits.scss index adfd72556b8..17801ed5910 100644 --- a/app/assets/stylesheets/pages/commits.scss +++ b/app/assets/stylesheets/pages/commits.scss @@ -196,6 +196,14 @@ @media (min-width: $screen-sm-min) { font-size: 0; + div { + display: inline; + } + + .fa-spinner { + font-size: 12px; + } + span { font-size: 6px; } @@ -226,7 +234,7 @@ .ci-status-icon { position: relative; - top: 3px; + top: 1px; } } diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index c94e10947e6..90272ad9554 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -51,7 +51,7 @@ - if commit.status(ref) = render_commit_status(commit, ref: ref) - #commit-pipeline-status.hidden{ data: { endpoint: pipelines_project_commit_path(project, commit.id) } } + #commit-pipeline-status{ data: { endpoint: pipelines_project_commit_path(project, commit.id) } } = link_to commit.short_id, link, class: "commit-sha btn btn-transparent btn-link" = clipboard_button(text: commit.id, title: _("Copy commit SHA to clipboard")) = link_to_browse_code(project, commit) diff --git a/features/project/project.feature b/features/project/project.feature index bcd72c5c5a3..23817ef3ac9 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -23,7 +23,6 @@ Feature: Project And I visit project "Shop" page Then I should see project "Shop" README - @javascript Scenario: I should see last commit with CI Given project "Shop" has CI enabled Given project "Shop" has CI build diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb index 923d54a6545..affbccccdf9 100644 --- a/features/steps/shared/project.rb +++ b/features/steps/shared/project.rb @@ -218,7 +218,6 @@ module SharedProject end step 'I should see last commit with CI status' do - sleep 2 page.within ".blob-commit-info" do expect(page).to have_content(project.commit.sha[0..6]) expect(page).to have_link("Commit: skipped") diff --git a/spec/javascripts/commit/commit_pipeline_status_component_spec.js b/spec/javascripts/commit/commit_pipeline_status_component_spec.js index 2a52097e0d5..90f290e845e 100644 --- a/spec/javascripts/commit/commit_pipeline_status_component_spec.js +++ b/spec/javascripts/commit/commit_pipeline_status_component_spec.js @@ -6,7 +6,7 @@ import mountComponent from '../helpers/vue_mount_component_helper'; describe('Commit pipeline status component', () => { let vm; - let component; + let Component; let mock; const mockCiStatus = { details_path: '/root/hello-world/pipelines/1', @@ -19,34 +19,25 @@ describe('Commit pipeline status component', () => { }; beforeEach(() => { - mock = new MockAdapter(axios); - mock.onGet('/dummy/endpoint').reply(() => { - const res = Promise.resolve([200, { - pipelines: [ - { - details: { - stages: [ - { - status: mockCiStatus, - title: 'Commit: canceled', - }, - ], - }, - }, - ], - }]); - return res; - }); - component = Vue.extend(commitPipelineStatus); + Component = Vue.extend(commitPipelineStatus); }); - afterEach(() => { - mock.reset(); - }); - - describe('While polling pipeline data', () => { + describe('While polling pipeline data succesfully', () => { beforeEach(() => { - vm = mountComponent(component, { + mock = new MockAdapter(axios); + mock.onGet('/dummy/endpoint').reply(() => { + const res = Promise.resolve([200, { + pipelines: [ + { + details: { + status: mockCiStatus, + }, + }, + ], + }]); + return res; + }); + vm = mountComponent(Component, { endpoint: '/dummy/endpoint', }); }); @@ -54,18 +45,58 @@ describe('Commit pipeline status component', () => { afterEach(() => { vm.poll.stop(); vm.$destroy(); + mock.restore(); + }); + + it('shows the loading icon when polling is starting', (done) => { + expect(vm.$el.querySelector('.loading-container')).not.toBe(null); + setTimeout(() => { + expect(vm.$el.querySelector('.loading-container')).toBe(null); + done(); + }); }); it('contains a ciStatus when the polling is succesful ', (done) => { setTimeout(() => { expect(vm.ciStatus).toEqual(mockCiStatus); done(); - }, 1000); + }); }); it('contains a ci-status icon when polling is succesful', (done) => { setTimeout(() => { expect(vm.$el.querySelector('.ci-status-icon')).not.toBe(null); + expect(vm.$el.querySelector('.ci-status-icon').classList).toContain(`ci-status-icon-${mockCiStatus.group}`); + done(); + }); + }); + }); + + describe('When polling data was not succesful', () => { + beforeEach(() => { + mock = new MockAdapter(axios); + mock.onGet('/dummy/endpoint').reply(() => { + const res = Promise.reject([502, { }]); + return res; + }); + vm = new Component({ + props: { + endpoint: '/dummy/endpoint', + }, + }); + }); + + afterEach(() => { + vm.poll.stop(); + vm.$destroy(); + mock.restore(); + }); + + it('calls an errorCallback', (done) => { + spyOn(vm, 'errorCallback').and.callThrough(); + vm.$mount(); + setTimeout(() => { + expect(vm.errorCallback.calls.count()).toEqual(1); done(); }); });