Commit ae5600b8 authored by Paul Slaughter's avatar Paul Slaughter Committed by Phil Hughes

Create specs for diffs/components/app and update modules to export factory functions

parent 32b96bfd
...@@ -11,8 +11,10 @@ export default () => ({ ...@@ -11,8 +11,10 @@ export default () => ({
endpoint: '', endpoint: '',
basePath: '', basePath: '',
commit: null, commit: null,
startVersion: null,
diffFiles: [], diffFiles: [],
mergeRequestDiffs: [], mergeRequestDiffs: [],
mergeRequestDiff: null,
diffLineCommentForms: {}, diffLineCommentForms: {},
diffViewType: viewTypeFromQueryString || viewTypeFromCookie || defaultViewType, diffViewType: viewTypeFromQueryString || viewTypeFromCookie || defaultViewType,
}); });
...@@ -3,10 +3,10 @@ import * as getters from '../getters'; ...@@ -3,10 +3,10 @@ import * as getters from '../getters';
import mutations from '../mutations'; import mutations from '../mutations';
import createState from './diff_state'; import createState from './diff_state';
export default { export default () => ({
namespaced: true, namespaced: true,
state: createState(), state: createState(),
getters, getters,
actions, actions,
mutations, mutations,
}; });
...@@ -9,7 +9,7 @@ Vue.use(Vuex); ...@@ -9,7 +9,7 @@ Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
modules: { modules: {
page: mrPageModule, page: mrPageModule,
notes: notesModule, notes: notesModule(),
diffs: diffsModule, diffs: diffsModule(),
}, },
}); });
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import * as actions from './actions'; import notesModule from './modules';
import * as getters from './getters';
import mutations from './mutations';
import module from './modules';
Vue.use(Vuex); Vue.use(Vuex);
export default () => export default () =>
new Vuex.Store({ new Vuex.Store(notesModule());
state: module.state,
actions,
getters,
mutations,
});
...@@ -2,7 +2,7 @@ import * as actions from '../actions'; ...@@ -2,7 +2,7 @@ import * as actions from '../actions';
import * as getters from '../getters'; import * as getters from '../getters';
import mutations from '../mutations'; import mutations from '../mutations';
export default { export default () => ({
state: { state: {
discussions: [], discussions: [],
targetNoteHash: null, targetNoteHash: null,
...@@ -24,4 +24,4 @@ export default { ...@@ -24,4 +24,4 @@ export default {
actions, actions,
getters, getters,
mutations, mutations,
}; });
// 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);
});
});
...@@ -8,7 +8,7 @@ describe('ChangedFiles', () => { ...@@ -8,7 +8,7 @@ describe('ChangedFiles', () => {
const Component = Vue.extend(changedFiles); const Component = Vue.extend(changedFiles);
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: { modules: {
diffs: diffsModule, diffs: diffsModule(),
}, },
}); });
......
...@@ -16,8 +16,8 @@ describe('diff_file_header', () => { ...@@ -16,8 +16,8 @@ describe('diff_file_header', () => {
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: { modules: {
diffs: diffsModule, diffs: diffsModule(),
notes: notesModule, notes: notesModule(),
}, },
}); });
...@@ -450,13 +450,14 @@ describe('diff_file_header', () => { ...@@ -450,13 +450,14 @@ describe('diff_file_header', () => {
propsCopy.diffFile.deletedFile = true; propsCopy.diffFile.deletedFile = true;
const discussionGetter = () => [diffDiscussionMock]; const discussionGetter = () => [diffDiscussionMock];
notesModule.getters.discussions = discussionGetter; const notesModuleMock = notesModule();
notesModuleMock.getters.discussions = discussionGetter;
vm = mountComponentWithStore(Component, { vm = mountComponentWithStore(Component, {
props: propsCopy, props: propsCopy,
store: new Vuex.Store({ store: new Vuex.Store({
modules: { modules: {
diffs: diffsModule, diffs: diffsModule(),
notes: notesModule, notes: notesModuleMock,
}, },
}), }),
}); });
......
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(),
},
});
}
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