From bf6b70662bb9512e7d0e179358c174ad59c49156 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 19 Jun 2019 11:32:33 +0100 Subject: Render tree last commit widget with Vue Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/62766 --- .../repository/components/last_commit.vue | 145 +++++++++++++++++++++ app/assets/javascripts/repository/index.js | 19 +++ .../queries/pathLastCommit.query.graphql | 29 +++++ locale/gitlab.pot | 3 + .../__snapshots__/last_commit_spec.js.snap | 98 ++++++++++++++ .../repository/components/last_commit_spec.js | 103 +++++++++++++++ 6 files changed, 397 insertions(+) create mode 100644 app/assets/javascripts/repository/components/last_commit.vue create mode 100644 app/assets/javascripts/repository/queries/pathLastCommit.query.graphql create mode 100644 spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap create mode 100644 spec/frontend/repository/components/last_commit_spec.js diff --git a/app/assets/javascripts/repository/components/last_commit.vue b/app/assets/javascripts/repository/components/last_commit.vue new file mode 100644 index 00000000000..b1565699432 --- /dev/null +++ b/app/assets/javascripts/repository/components/last_commit.vue @@ -0,0 +1,145 @@ + + + diff --git a/app/assets/javascripts/repository/index.js b/app/assets/javascripts/repository/index.js index 52f53be045b..d9216e88676 100644 --- a/app/assets/javascripts/repository/index.js +++ b/app/assets/javascripts/repository/index.js @@ -2,6 +2,7 @@ import Vue from 'vue'; import createRouter from './router'; import App from './components/app.vue'; import Breadcrumbs from './components/breadcrumbs.vue'; +import LastCommit from './components/last_commit.vue'; import apolloProvider from './graphql'; import { setTitle } from './utils/title'; @@ -48,6 +49,24 @@ export default function setupVueRepositoryList() { }, }); + const commitEl = document.getElementById('js-last-commit'); + + if (commitEl) { + // eslint-disable-next-line no-new + new Vue({ + el: commitEl, + router, + apolloProvider, + render(h) { + return h(LastCommit, { + props: { + currentPath: this.$route.params.pathMatch, + }, + }); + }, + }); + } + return new Vue({ el, router, diff --git a/app/assets/javascripts/repository/queries/pathLastCommit.query.graphql b/app/assets/javascripts/repository/queries/pathLastCommit.query.graphql new file mode 100644 index 00000000000..90901f54d54 --- /dev/null +++ b/app/assets/javascripts/repository/queries/pathLastCommit.query.graphql @@ -0,0 +1,29 @@ +query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) { + project(fullPath: $projectPath) { + repository { + tree(path: $path, ref: $ref) { + commit { + id + title + message + webUrl + authoredDate + author { + name + avatarUrl + webUrl + } + pipeline { + detailedStatus { + detailsPath + icon + tooltip + text + group + } + } + } + } + } + } +} diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 0cabaeabb9a..e89b1e754f2 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -9140,6 +9140,9 @@ msgstr "" msgid "Show comments only" msgstr "" +msgid "Show commit description" +msgstr "" + msgid "Show complete raw log" msgstr "" diff --git a/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap new file mode 100644 index 00000000000..3ad6bfa9e5f --- /dev/null +++ b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Repository last commit component renders commit widget 1`] = ` +
+ + +
+
+ + + Commit title + + + + + +
+ + + Test + + + + authored + + +
+ + +
+ +
+ + + + +
+
+ + 12345678 + +
+ + +
+
+
+
+`; diff --git a/spec/frontend/repository/components/last_commit_spec.js b/spec/frontend/repository/components/last_commit_spec.js new file mode 100644 index 00000000000..972690a60f6 --- /dev/null +++ b/spec/frontend/repository/components/last_commit_spec.js @@ -0,0 +1,103 @@ +import { shallowMount } from '@vue/test-utils'; +import LastCommit from '~/repository/components/last_commit.vue'; +import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; + +let vm; + +function createCommitData(data = {}) { + return { + id: '123456789', + title: 'Commit title', + message: 'Commit message', + webUrl: 'https://test.com/commit/123', + authoredDate: '2019-01-01', + author: { + name: 'Test', + avatarUrl: 'https://test.com', + webUrl: 'https://test.com/test', + }, + pipeline: { + detailedStatus: { + detailsPath: 'https://test.com/pipeline', + icon: 'failed', + tooltip: 'failed', + text: 'failed', + group: {}, + }, + }, + ...data, + }; +} + +function factory(commit = createCommitData(), loading = false) { + vm = shallowMount(LastCommit, { + mocks: { + $apollo: { + queries: { + commit: { + loading: true, + }, + }, + }, + }, + }); + vm.setData({ commit }); + vm.vm.$apollo.queries.commit.loading = loading; +} + +describe('Repository last commit component', () => { + afterEach(() => { + vm.destroy(); + }); + + it.each` + loading | label + ${true} | ${'hides'} + ${false} | ${'shows'} + `('$label when $loading is true', ({ loading }) => { + factory(createCommitData(), loading); + + expect(vm.isEmpty()).toBe(loading); + }); + + it('renders commit widget', () => { + factory(); + + expect(vm.element).toMatchSnapshot(); + }); + + it('renders short commit ID', () => { + factory(); + + expect(vm.find('.label-monospace').text()).toEqual('12345678'); + }); + + it('hides pipeline components when pipeline does not exist', () => { + factory(createCommitData({ pipeline: null })); + + expect(vm.find('.js-commit-pipeline').exists()).toBe(false); + }); + + it('hides author component when author does not exist', () => { + factory(createCommitData({ author: null })); + + expect(vm.find('.js-user-link').exists()).toBe(false); + expect(vm.find(UserAvatarLink).exists()).toBe(false); + }); + + it('does not render description expander when description is null', () => { + factory(createCommitData({ description: null })); + + expect(vm.find('.text-expander').exists()).toBe(false); + expect(vm.find('.commit-row-description').exists()).toBe(false); + }); + + it('expands commit description when clicking expander', () => { + factory(createCommitData({ description: 'Test description' })); + + vm.find('.text-expander').vm.$emit('click'); + + expect(vm.find('.commit-row-description').isVisible()).toBe(true); + expect(vm.find('.text-expander').classes('open')).toBe(true); + }); +}); -- cgit v1.2.1