From 8cffa55b2cec3f2c95913af014a5c828cf547788 Mon Sep 17 00:00:00 2001 From: Paul Slaughter Date: Sun, 11 Aug 2019 18:57:30 -0500 Subject: [PATCH] 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 --- app/assets/javascripts/mr_notes/stores/index.js | 2 +- app/assets/javascripts/mr_notes/stores/modules/index.js | 4 ++-- spec/javascripts/diffs/components/compare_versions_spec.js | 4 +++- .../diffs/components/diff_expansion_cell_spec.js | 4 ++-- spec/javascripts/diffs/components/diff_file_spec.js | 6 +++--- .../diffs/components/diff_line_gutter_content_spec.js | 6 +++--- .../diffs/components/diff_line_note_form_spec.js | 4 ++-- spec/javascripts/diffs/components/diff_table_cell_spec.js | 4 ++-- .../diffs/components/inline_diff_expansion_row_spec.js | 4 ++-- .../diffs/components/inline_diff_table_row_spec.js | 4 ++-- spec/javascripts/diffs/components/inline_diff_view_spec.js | 4 +++- .../diffs/components/parallel_diff_expansion_row_spec.js | 4 ++-- .../javascripts/diffs/components/parallel_diff_view_spec.js | 4 ++-- 13 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/mr_notes/stores/index.js b/app/assets/javascripts/mr_notes/stores/index.js index c4225c8ec08..8fbd0291a7d 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 const createStore = () => new Vuex.Store({ modules: { - page: mrPageModule, + page: mrPageModule(), notes: notesModule(), diffs: diffsModule(), }, diff --git a/app/assets/javascripts/mr_notes/stores/modules/index.js b/app/assets/javascripts/mr_notes/stores/modules/index.js index 660081f76c8..c28e666943b 100644 --- a/app/assets/javascripts/mr_notes/stores/modules/index.js +++ b/app/assets/javascripts/mr_notes/stores/modules/index.js @@ -2,11 +2,11 @@ import actions from '../actions'; import getters from '../getters'; import mutations from '../mutations'; -export default { +export default () => ({ state: { activeTab: null, }, actions, getters, mutations, -}; +}); diff --git a/spec/javascripts/diffs/components/compare_versions_spec.js b/spec/javascripts/diffs/components/compare_versions_spec.js index 77f8352047c..ef4bb470734 100644 --- a/spec/javascripts/diffs/components/compare_versions_spec.js +++ b/spec/javascripts/diffs/components/compare_versions_spec.js @@ -1,6 +1,6 @@ import Vue from '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 diffsMockData from '../mock_data/merge_request_diffs'; import getDiffWithCommit from '../mock_data/diff_with_commit'; @@ -10,6 +10,8 @@ describe('CompareVersions', () => { const targetBranch = { branchName: 'tmp-wine-dev', versionIndex: -1 }; beforeEach(() => { + const store = createStore(); + store.state.diffs.addedLines = 10; store.state.diffs.removedLines = 20; store.state.diffs.diffFiles.push('test'); diff --git a/spec/javascripts/diffs/components/diff_expansion_cell_spec.js b/spec/javascripts/diffs/components/diff_expansion_cell_spec.js index cb1966b2122..63c50c09fce 100644 --- a/spec/javascripts/diffs/components/diff_expansion_cell_spec.js +++ b/spec/javascripts/diffs/components/diff_expansion_cell_spec.js @@ -1,5 +1,5 @@ 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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; @@ -22,7 +22,7 @@ describe('DiffExpansionCell', () => { }; const props = Object.assign({}, defaults, options); - return createComponentWithStore(cmp, store, props).$mount(); + return createComponentWithStore(cmp, createStore(), props).$mount(); }; describe('top row', () => { diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index 18da0a473d6..3ca2d1dc934 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import DiffFileComponent from '~/diffs/components/diff_file.vue'; 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 diffFileMockData from '../mock_data/diff_file'; @@ -9,7 +9,7 @@ describe('DiffFile', () => { let vm; beforeEach(() => { - vm = createComponentWithStore(Vue.extend(DiffFileComponent), store, { + vm = createComponentWithStore(Vue.extend(DiffFileComponent), createStore(), { file: JSON.parse(JSON.stringify(diffFileMockData)), canCurrentUserFork: false, }).$mount(); @@ -36,7 +36,7 @@ describe('DiffFile', () => { vm.$nextTick() .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); }) .then(done) diff --git a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js index 99b5496c24b..6bb704658fb 100644 --- a/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js +++ b/spec/javascripts/diffs/components/diff_line_gutter_content_spec.js @@ -1,6 +1,6 @@ import Vue from '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 discussionsMockData from '../mock_data/diff_discussions'; import diffFileMockData from '../mock_data/diff_file'; @@ -23,7 +23,7 @@ describe('DiffLineGutterContent', () => { props.fileHash = getDiffFileMock().file_hash; props.contextLinesPath = '/context/lines/path'; - return createComponentWithStore(cmp, store, props).$mount(); + return createComponentWithStore(cmp, createStore(), props).$mount(); }; describe('computed', () => { @@ -61,7 +61,7 @@ describe('DiffLineGutterContent', () => { contextLinesPath: '/context/lines/path', }; 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.shouldShowAvatarsOnGutter).toEqual(true); diff --git a/spec/javascripts/diffs/components/diff_line_note_form_spec.js b/spec/javascripts/diffs/components/diff_line_note_form_spec.js index b983dc35a57..237cfccfa29 100644 --- a/spec/javascripts/diffs/components/diff_line_note_form_spec.js +++ b/spec/javascripts/diffs/components/diff_line_note_form_spec.js @@ -1,6 +1,6 @@ import Vue from '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 diffFileMockData from '../mock_data/diff_file'; import { noteableDataMock } from '../../notes/mock_data'; @@ -15,7 +15,7 @@ describe('DiffLineNoteForm', () => { diffFile = getDiffFileMock(); diffLines = diffFile.highlighted_diff_lines; - component = createComponentWithStore(Vue.extend(DiffLineNoteForm), store, { + component = createComponentWithStore(Vue.extend(DiffLineNoteForm), createStore(), { diffFileHash: diffFile.file_hash, diffLines, line: diffLines[0], diff --git a/spec/javascripts/diffs/components/diff_table_cell_spec.js b/spec/javascripts/diffs/components/diff_table_cell_spec.js index 170e661beea..a5a042c577c 100644 --- a/spec/javascripts/diffs/components/diff_table_cell_spec.js +++ b/spec/javascripts/diffs/components/diff_table_cell_spec.js @@ -1,12 +1,12 @@ 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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; describe('DiffTableCell', () => { const createComponent = options => - createComponentWithStore(Vue.extend(DiffTableCell), store, { + createComponentWithStore(Vue.extend(DiffTableCell), createStore(), { line: diffFileMockData.highlighted_diff_lines[0], fileHash: diffFileMockData.file_hash, contextLinesPath: 'contextLinesPath', diff --git a/spec/javascripts/diffs/components/inline_diff_expansion_row_spec.js b/spec/javascripts/diffs/components/inline_diff_expansion_row_spec.js index bf50070a4f5..290b3d7c803 100644 --- a/spec/javascripts/diffs/components/inline_diff_expansion_row_spec.js +++ b/spec/javascripts/diffs/components/inline_diff_expansion_row_spec.js @@ -1,5 +1,5 @@ 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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; @@ -18,7 +18,7 @@ describe('InlineDiffExpansionRow', () => { }; const props = Object.assign({}, defaults, options); - return createComponentWithStore(cmp, store, props).$mount(); + return createComponentWithStore(cmp, createStore(), props).$mount(); }; describe('template', () => { diff --git a/spec/javascripts/diffs/components/inline_diff_table_row_spec.js b/spec/javascripts/diffs/components/inline_diff_table_row_spec.js index 97926f6625e..0ddffe926d9 100644 --- a/spec/javascripts/diffs/components/inline_diff_table_row_spec.js +++ b/spec/javascripts/diffs/components/inline_diff_table_row_spec.js @@ -1,5 +1,5 @@ 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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; @@ -9,7 +9,7 @@ describe('InlineDiffTableRow', () => { const thisLine = diffFileMockData.highlighted_diff_lines[0]; beforeEach(() => { - vm = createComponentWithStore(Vue.extend(InlineDiffTableRow), store, { + vm = createComponentWithStore(Vue.extend(InlineDiffTableRow), createStore(), { line: thisLine, fileHash: diffFileMockData.file_hash, contextLinesPath: 'contextLinesPath', diff --git a/spec/javascripts/diffs/components/inline_diff_view_spec.js b/spec/javascripts/diffs/components/inline_diff_view_spec.js index 3963e37fae2..486d9629e26 100644 --- a/spec/javascripts/diffs/components/inline_diff_view_spec.js +++ b/spec/javascripts/diffs/components/inline_diff_view_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import '~/behaviors/markdown/render_gfm'; 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 diffFileMockData from '../mock_data/diff_file'; import discussionsMockData from '../mock_data/diff_discussions'; @@ -15,6 +15,8 @@ describe('InlineDiffView', () => { beforeEach(done => { const diffFile = getDiffFileMock(); + const store = createStore(); + store.dispatch('diffs/setInlineDiffViewType'); component = createComponentWithStore(Vue.extend(InlineDiffView), store, { diffFile, diff --git a/spec/javascripts/diffs/components/parallel_diff_expansion_row_spec.js b/spec/javascripts/diffs/components/parallel_diff_expansion_row_spec.js index 134738932b3..a766ebb5efb 100644 --- a/spec/javascripts/diffs/components/parallel_diff_expansion_row_spec.js +++ b/spec/javascripts/diffs/components/parallel_diff_expansion_row_spec.js @@ -1,5 +1,5 @@ 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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; @@ -18,7 +18,7 @@ describe('ParallelDiffExpansionRow', () => { }; const props = Object.assign({}, defaults, options); - return createComponentWithStore(cmp, store, props).$mount(); + return createComponentWithStore(cmp, createStore(), props).$mount(); }; describe('template', () => { diff --git a/spec/javascripts/diffs/components/parallel_diff_view_spec.js b/spec/javascripts/diffs/components/parallel_diff_view_spec.js index 236bda96145..191313bf487 100644 --- a/spec/javascripts/diffs/components/parallel_diff_view_spec.js +++ b/spec/javascripts/diffs/components/parallel_diff_view_spec.js @@ -1,6 +1,6 @@ import Vue from '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 { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffFileMockData from '../mock_data/diff_file'; @@ -12,7 +12,7 @@ describe('ParallelDiffView', () => { beforeEach(() => { const diffFile = getDiffFileMock(); - component = createComponentWithStore(Vue.extend(ParallelDiffView), store, { + component = createComponentWithStore(Vue.extend(ParallelDiffView), createStore(), { diffFile, diffLines: diffFile.parallel_diff_lines, }).$mount();