CE - FE fix diffs specs leaking store

- Export mr_notes module as function
- Update specs refs of mr_notes/stores to factory

EE MR: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/15097
This commit is contained in:
Paul Slaughter 2019-08-11 18:57:30 -05:00
parent 7daf1f41be
commit 8cffa55b2c
No known key found for this signature in database
GPG key ID: DF5690803C68282A
13 changed files with 29 additions and 25 deletions

View file

@ -9,7 +9,7 @@ Vue.use(Vuex);
export const createStore = () => export const createStore = () =>
new Vuex.Store({ new Vuex.Store({
modules: { modules: {
page: mrPageModule, page: mrPageModule(),
notes: notesModule(), notes: notesModule(),
diffs: diffsModule(), diffs: diffsModule(),
}, },

View file

@ -2,11 +2,11 @@ import actions from '../actions';
import getters from '../getters'; import getters from '../getters';
import mutations from '../mutations'; import mutations from '../mutations';
export default { export default () => ({
state: { state: {
activeTab: null, activeTab: null,
}, },
actions, actions,
getters, getters,
mutations, mutations,
}; });

View file

@ -1,6 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import CompareVersionsComponent from '~/diffs/components/compare_versions.vue'; import CompareVersionsComponent from '~/diffs/components/compare_versions.vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffsMockData from '../mock_data/merge_request_diffs'; import diffsMockData from '../mock_data/merge_request_diffs';
import getDiffWithCommit from '../mock_data/diff_with_commit'; import getDiffWithCommit from '../mock_data/diff_with_commit';
@ -10,6 +10,8 @@ describe('CompareVersions', () => {
const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 }; const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 };
beforeEach(() => { beforeEach(() => {
const store = createStore();
store.state.diffs.addedLines = 10; store.state.diffs.addedLines = 10;
store.state.diffs.removedLines = 20; store.state.diffs.removedLines = 20;
store.state.diffs.diffFiles.push('test'); store.state.diffs.diffFiles.push('test');

View file

@ -1,5 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import DiffExpansionCell from '~/diffs/components/diff_expansion_cell.vue'; import DiffExpansionCell from '~/diffs/components/diff_expansion_cell.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -22,7 +22,7 @@ describe('DiffExpansionCell', () => {
}; };
const props = Object.assign({}, defaults, options); const props = Object.assign({}, defaults, options);
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, createStore(), props).$mount();
}; };
describe('top row', () => { describe('top row', () => {

View file

@ -1,7 +1,7 @@
import Vue from 'vue'; import Vue from 'vue';
import DiffFileComponent from '~/diffs/components/diff_file.vue'; import DiffFileComponent from '~/diffs/components/diff_file.vue';
import { diffViewerModes, diffViewerErrors } from '~/ide/constants'; import { diffViewerModes, diffViewerErrors } from '~/ide/constants';
import store from 'ee_else_ce/mr_notes/stores'; import { createStore } from 'ee_else_ce/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -9,7 +9,7 @@ describe('DiffFile', () => {
let vm; let vm;
beforeEach(() => { beforeEach(() => {
vm = createComponentWithStore(Vue.extend(DiffFileComponent), store, { vm = createComponentWithStore(Vue.extend(DiffFileComponent), createStore(), {
file: JSON.parse(JSON.stringify(diffFileMockData)), file: JSON.parse(JSON.stringify(diffFileMockData)),
canCurrentUserFork: false, canCurrentUserFork: false,
}).$mount(); }).$mount();
@ -36,7 +36,7 @@ describe('DiffFile', () => {
vm.$nextTick() vm.$nextTick()
.then(() => { .then(() => {
expect(el.querySelectorAll('.line_content').length).toBeGreaterThanOrEqual(5); expect(el.querySelectorAll('.line_content').length).toBe(5);
expect(el.querySelectorAll('.js-line-expansion-content').length).toBe(1); expect(el.querySelectorAll('.js-line-expansion-content').length).toBe(1);
}) })
.then(done) .then(done)

View file

@ -1,6 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import DiffLineGutterContent from '~/diffs/components/diff_line_gutter_content.vue'; import DiffLineGutterContent from '~/diffs/components/diff_line_gutter_content.vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import discussionsMockData from '../mock_data/diff_discussions'; import discussionsMockData from '../mock_data/diff_discussions';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -23,7 +23,7 @@ describe('DiffLineGutterContent', () => {
props.fileHash = getDiffFileMock().file_hash; props.fileHash = getDiffFileMock().file_hash;
props.contextLinesPath = '/context/lines/path'; props.contextLinesPath = '/context/lines/path';
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, createStore(), props).$mount();
}; };
describe('computed', () => { describe('computed', () => {
@ -61,7 +61,7 @@ describe('DiffLineGutterContent', () => {
contextLinesPath: '/context/lines/path', contextLinesPath: '/context/lines/path',
}; };
props.line.discussions = [Object.assign({}, discussionsMockData)]; props.line.discussions = [Object.assign({}, discussionsMockData)];
const component = createComponentWithStore(cmp, store, props).$mount(); const component = createComponentWithStore(cmp, createStore(), props).$mount();
expect(component.hasDiscussions).toEqual(true); expect(component.hasDiscussions).toEqual(true);
expect(component.shouldShowAvatarsOnGutter).toEqual(true); expect(component.shouldShowAvatarsOnGutter).toEqual(true);

View file

@ -1,6 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue'; import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
import { noteableDataMock } from '../../notes/mock_data'; import { noteableDataMock } from '../../notes/mock_data';
@ -15,7 +15,7 @@ describe('DiffLineNoteForm', () => {
diffFile = getDiffFileMock(); diffFile = getDiffFileMock();
diffLines = diffFile.highlighted_diff_lines; diffLines = diffFile.highlighted_diff_lines;
component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, { component = createComponentWithStore(Vue.extend(DiffLineNoteForm), createStore(), {
diffFileHash: diffFile.file_hash, diffFileHash: diffFile.file_hash,
diffLines, diffLines,
line: diffLines[0], line: diffLines[0],

View file

@ -1,12 +1,12 @@
import Vue from 'vue'; import Vue from 'vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import DiffTableCell from '~/diffs/components/diff_table_cell.vue'; import DiffTableCell from '~/diffs/components/diff_table_cell.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
describe('DiffTableCell', () => { describe('DiffTableCell', () => {
const createComponent = options => const createComponent = options =>
createComponentWithStore(Vue.extend(DiffTableCell), store, { createComponentWithStore(Vue.extend(DiffTableCell), createStore(), {
line: diffFileMockData.highlighted_diff_lines[0], line: diffFileMockData.highlighted_diff_lines[0],
fileHash: diffFileMockData.file_hash, fileHash: diffFileMockData.file_hash,
contextLinesPath: 'contextLinesPath', contextLinesPath: 'contextLinesPath',

View file

@ -1,5 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import InlineDiffExpansionRow from '~/diffs/components/inline_diff_expansion_row.vue'; import InlineDiffExpansionRow from '~/diffs/components/inline_diff_expansion_row.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -18,7 +18,7 @@ describe('InlineDiffExpansionRow', () => {
}; };
const props = Object.assign({}, defaults, options); const props = Object.assign({}, defaults, options);
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, createStore(), props).$mount();
}; };
describe('template', () => { describe('template', () => {

View file

@ -1,5 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import InlineDiffTableRow from '~/diffs/components/inline_diff_table_row.vue'; import InlineDiffTableRow from '~/diffs/components/inline_diff_table_row.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -9,7 +9,7 @@ describe('InlineDiffTableRow', () => {
const thisLine = diffFileMockData.highlighted_diff_lines[0]; const thisLine = diffFileMockData.highlighted_diff_lines[0];
beforeEach(() => { beforeEach(() => {
vm = createComponentWithStore(Vue.extend(InlineDiffTableRow), store, { vm = createComponentWithStore(Vue.extend(InlineDiffTableRow), createStore(), {
line: thisLine, line: thisLine,
fileHash: diffFileMockData.file_hash, fileHash: diffFileMockData.file_hash,
contextLinesPath: 'contextLinesPath', contextLinesPath: 'contextLinesPath',

View file

@ -1,7 +1,7 @@
import Vue from 'vue'; import Vue from 'vue';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import InlineDiffView from '~/diffs/components/inline_diff_view.vue'; import InlineDiffView from '~/diffs/components/inline_diff_view.vue';
import store from 'ee_else_ce/mr_notes/stores'; import { createStore } from 'ee_else_ce/mr_notes/stores';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
import discussionsMockData from '../mock_data/diff_discussions'; import discussionsMockData from '../mock_data/diff_discussions';
@ -15,6 +15,8 @@ describe('InlineDiffView', () => {
beforeEach(done => { beforeEach(done => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
const store = createStore();
store.dispatch('diffs/setInlineDiffViewType'); store.dispatch('diffs/setInlineDiffViewType');
component = createComponentWithStore(Vue.extend(InlineDiffView), store, { component = createComponentWithStore(Vue.extend(InlineDiffView), store, {
diffFile, diffFile,

View file

@ -1,5 +1,5 @@
import Vue from 'vue'; import Vue from 'vue';
import store from '~/mr_notes/stores'; import { createStore } from '~/mr_notes/stores';
import ParallelDiffExpansionRow from '~/diffs/components/parallel_diff_expansion_row.vue'; import ParallelDiffExpansionRow from '~/diffs/components/parallel_diff_expansion_row.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -18,7 +18,7 @@ describe('ParallelDiffExpansionRow', () => {
}; };
const props = Object.assign({}, defaults, options); const props = Object.assign({}, defaults, options);
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, createStore(), props).$mount();
}; };
describe('template', () => { describe('template', () => {

View file

@ -1,6 +1,6 @@
import Vue from 'vue'; import Vue from 'vue';
import ParallelDiffView from '~/diffs/components/parallel_diff_view.vue'; import ParallelDiffView from '~/diffs/components/parallel_diff_view.vue';
import store from 'ee_else_ce/mr_notes/stores'; import { createStore } from 'ee_else_ce/mr_notes/stores';
import * as constants from '~/diffs/constants'; import * as constants from '~/diffs/constants';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
@ -12,7 +12,7 @@ describe('ParallelDiffView', () => {
beforeEach(() => { beforeEach(() => {
const diffFile = getDiffFileMock(); const diffFile = getDiffFileMock();
component = createComponentWithStore(Vue.extend(ParallelDiffView), store, { component = createComponentWithStore(Vue.extend(ParallelDiffView), createStore(), {
diffFile, diffFile,
diffLines: diffFile.parallel_diff_lines, diffLines: diffFile.parallel_diff_lines,
}).$mount(); }).$mount();