diff options
author | Phil Hughes <me@iamphill.com> | 2018-09-14 08:25:13 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-09-14 08:25:13 +0000 |
commit | bb708a06e0fb02997b12ef31089485f9b7e54909 (patch) | |
tree | 81f4f3a119ed6e293bb052188d41ea0ebf09c234 | |
parent | 32b96bfd81ff254142dbd9c73e1a494308213cb3 (diff) | |
parent | ae5600b868308fd4094a8ddf1d6278fa6f5a5a7c (diff) | |
download | gitlab-ce-bb708a06e0fb02997b12ef31089485f9b7e54909.tar.gz |
Merge branch '49329-mr-show-commit-details-update-specs' into 'master'
Create specs for diffs/components/app and update modules to export factory functions
Closes #49329
See merge request gitlab-org/gitlab-ce!21685
9 files changed, 103 insertions, 23 deletions
diff --git a/app/assets/javascripts/diffs/store/modules/diff_state.js b/app/assets/javascripts/diffs/store/modules/diff_state.js index 39d90a64aab..eb596b251c1 100644 --- a/app/assets/javascripts/diffs/store/modules/diff_state.js +++ b/app/assets/javascripts/diffs/store/modules/diff_state.js @@ -11,8 +11,10 @@ export default () => ({ endpoint: '', basePath: '', commit: null, + startVersion: null, diffFiles: [], mergeRequestDiffs: [], + mergeRequestDiff: null, diffLineCommentForms: {}, diffViewType: viewTypeFromQueryString || viewTypeFromCookie || defaultViewType, }); diff --git a/app/assets/javascripts/diffs/store/modules/index.js b/app/assets/javascripts/diffs/store/modules/index.js index 20d1ebbe049..6860e24db6b 100644 --- a/app/assets/javascripts/diffs/store/modules/index.js +++ b/app/assets/javascripts/diffs/store/modules/index.js @@ -3,10 +3,10 @@ import * as getters from '../getters'; import mutations from '../mutations'; import createState from './diff_state'; -export default { +export default () => ({ namespaced: true, state: createState(), getters, actions, mutations, -}; +}); diff --git a/app/assets/javascripts/mr_notes/stores/index.js b/app/assets/javascripts/mr_notes/stores/index.js index dd2019001db..446eb477efc 100644 --- a/app/assets/javascripts/mr_notes/stores/index.js +++ b/app/assets/javascripts/mr_notes/stores/index.js @@ -9,7 +9,7 @@ Vue.use(Vuex); export default new Vuex.Store({ modules: { page: mrPageModule, - notes: notesModule, - diffs: diffsModule, + notes: notesModule(), + diffs: diffsModule(), }, }); diff --git a/app/assets/javascripts/notes/stores/index.js b/app/assets/javascripts/notes/stores/index.js index 0f48b8880f4..f105b7d0d11 100644 --- a/app/assets/javascripts/notes/stores/index.js +++ b/app/assets/javascripts/notes/stores/index.js @@ -1,16 +1,8 @@ import Vue from 'vue'; import Vuex from 'vuex'; -import * as actions from './actions'; -import * as getters from './getters'; -import mutations from './mutations'; -import module from './modules'; +import notesModule from './modules'; Vue.use(Vuex); export default () => - new Vuex.Store({ - state: module.state, - actions, - getters, - mutations, - }); + new Vuex.Store(notesModule()); diff --git a/app/assets/javascripts/notes/stores/modules/index.js b/app/assets/javascripts/notes/stores/modules/index.js index b4cb9267e0f..61dbb075586 100644 --- a/app/assets/javascripts/notes/stores/modules/index.js +++ b/app/assets/javascripts/notes/stores/modules/index.js @@ -2,7 +2,7 @@ import * as actions from '../actions'; import * as getters from '../getters'; import mutations from '../mutations'; -export default { +export default () => ({ state: { discussions: [], targetNoteHash: null, @@ -24,4 +24,4 @@ export default { actions, getters, mutations, -}; +}); diff --git a/spec/javascripts/diffs/components/app_spec.js b/spec/javascripts/diffs/components/app_spec.js index 7237274eb43..7be44a26ded 100644 --- a/spec/javascripts/diffs/components/app_spec.js +++ b/spec/javascripts/diffs/components/app_spec.js @@ -1 +1,71 @@ -// TODO: https://gitlab.com/gitlab-org/gitlab-ce/issues/48034 +import Vue from 'vue'; +import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; +import { TEST_HOST } from 'spec/test_constants'; +import App from '~/diffs/components/app.vue'; +import createDiffsStore from '../create_diffs_store'; + +describe('diffs/components/app', () => { + const oldMrTabs = window.mrTabs; + const Component = Vue.extend(App); + + let vm; + + beforeEach(() => { + // setup globals (needed for component to mount :/) + window.mrTabs = jasmine.createSpyObj('mrTabs', ['resetViewContainer']); + + // setup component + const store = createDiffsStore(); + store.state.diffs.isLoading = false; + + vm = mountComponentWithStore(Component, { + store, + props: { + endpoint: `${TEST_HOST}/diff/endpoint`, + projectPath: 'namespace/project', + currentUser: {}, + }, + }); + }); + + afterEach(() => { + // reset globals + window.mrTabs = oldMrTabs; + + // reset component + vm.$destroy(); + }); + + it('shows comments message, with commit', done => { + vm.$store.state.diffs.commit = {}; + + vm.$nextTick() + .then(() => { + expect(vm.$el).toContainText('Only comments from the following commit are shown below'); + }) + .then(done) + .catch(done.fail); + }); + + it('shows comments message, with old mergeRequestDiff', done => { + vm.$store.state.diffs.mergeRequestDiff = { latest: false }; + + vm.$nextTick() + .then(() => { + expect(vm.$el).toContainText("Not all comments are displayed because you're viewing an old version of the diff."); + }) + .then(done) + .catch(done.fail); + }); + + it('shows comments message, with startVersion', done => { + vm.$store.state.diffs.startVersion = 'test'; + + vm.$nextTick() + .then(() => { + expect(vm.$el).toContainText("Not all comments are displayed because you're comparing two versions of the diff."); + }) + .then(done) + .catch(done.fail); + }); +}); diff --git a/spec/javascripts/diffs/components/changed_files_spec.js b/spec/javascripts/diffs/components/changed_files_spec.js index f737e8fa38e..7f21273a991 100644 --- a/spec/javascripts/diffs/components/changed_files_spec.js +++ b/spec/javascripts/diffs/components/changed_files_spec.js @@ -8,7 +8,7 @@ describe('ChangedFiles', () => { const Component = Vue.extend(changedFiles); const store = new Vuex.Store({ modules: { - diffs: diffsModule, + diffs: diffsModule(), }, }); diff --git a/spec/javascripts/diffs/components/diff_file_header_spec.js b/spec/javascripts/diffs/components/diff_file_header_spec.js index 92b2004c4d7..c986ea604b2 100644 --- a/spec/javascripts/diffs/components/diff_file_header_spec.js +++ b/spec/javascripts/diffs/components/diff_file_header_spec.js @@ -16,8 +16,8 @@ describe('diff_file_header', () => { const store = new Vuex.Store({ modules: { - diffs: diffsModule, - notes: notesModule, + diffs: diffsModule(), + notes: notesModule(), }, }); @@ -450,13 +450,14 @@ describe('diff_file_header', () => { propsCopy.diffFile.deletedFile = true; const discussionGetter = () => [diffDiscussionMock]; - notesModule.getters.discussions = discussionGetter; + const notesModuleMock = notesModule(); + notesModuleMock.getters.discussions = discussionGetter; vm = mountComponentWithStore(Component, { props: propsCopy, store: new Vuex.Store({ modules: { - diffs: diffsModule, - notes: notesModule, + diffs: diffsModule(), + notes: notesModuleMock, }, }), }); diff --git a/spec/javascripts/diffs/create_diffs_store.js b/spec/javascripts/diffs/create_diffs_store.js new file mode 100644 index 00000000000..aacde99964c --- /dev/null +++ b/spec/javascripts/diffs/create_diffs_store.js @@ -0,0 +1,15 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import diffsModule from '~/diffs/store/modules'; +import notesModule from '~/notes/stores/modules'; + +Vue.use(Vuex); + +export default function createDiffsStore() { + return new Vuex.Store({ + modules: { + diffs: diffsModule(), + notes: notesModule(), + }, + }); +} |