Use factory method for import_projects store

Make sure we always create a new instance of the import_projects store.
This commit is contained in:
Winnie Hellmann 2019-02-28 15:35:06 +01:00
parent dc5fc28382
commit d64ec5df34
5 changed files with 22 additions and 12 deletions

View file

@ -3,7 +3,7 @@ import { mapActions } from 'vuex';
import Translate from '../vue_shared/translate';
import ImportProjectsTable from './components/import_projects_table.vue';
import { parseBoolean } from '../lib/utils/common_utils';
import store from './store';
import createStore from './store';
Vue.use(Translate);
@ -20,6 +20,7 @@ export default function mountImportProjectsTable(mountElement) {
ciCdOnly,
} = mountElement.dataset;
const store = createStore();
return new Vue({
el: mountElement,
store,

View file

@ -7,9 +7,10 @@ import mutations from './mutations';
Vue.use(Vuex);
export default new Vuex.Store({
export default () =>
new Vuex.Store({
state: state(),
actions,
mutations,
getters,
});
});

View file

@ -1,7 +1,7 @@
import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import store from '~/import_projects/store';
import createStore from '~/import_projects/store';
import importProjectsTable from '~/import_projects/components/import_projects_table.vue';
import STATUS_MAP from '~/import_projects/constants';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
@ -9,6 +9,7 @@ import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
describe('ImportProjectsTable', () => {
let vm;
let mock;
let store;
const reposPath = '/repos-path';
const jobsPath = '/jobs-path';
const providerTitle = 'THE PROVIDER';
@ -31,12 +32,13 @@ describe('ImportProjectsTable', () => {
},
}).$mount();
component.$store.dispatch('stopJobsPolling');
store.dispatch('stopJobsPolling');
return component;
}
beforeEach(() => {
store = createStore();
store.dispatch('setInitialData', { reposPath });
mock = new MockAdapter(axios);
});
@ -167,7 +169,7 @@ describe('ImportProjectsTable', () => {
expect(vm.$el.querySelector(`.ic-status_${statusObject.icon}`)).not.toBeNull();
mock.onGet(jobsPath).replyOnce(200, updatedProjects);
return vm.$store.dispatch('restartJobsPolling');
return store.dispatch('restartJobsPolling');
})
.then(() => setTimeoutPromise())
.then(() => {

View file

@ -1,5 +1,5 @@
import Vue from 'vue';
import store from '~/import_projects/store';
import createStore from '~/import_projects/store';
import importedProjectTableRow from '~/import_projects/components/imported_project_table_row.vue';
import STATUS_MAP from '~/import_projects/constants';
@ -16,6 +16,7 @@ describe('ImportedProjectTableRow', () => {
function createComponent() {
const ImportedProjectTableRow = Vue.extend(importedProjectTableRow);
const store = createStore();
return new ImportedProjectTableRow({
store,
propsData: {

View file

@ -1,12 +1,13 @@
import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import store from '~/import_projects/store';
import createStore from '~/import_projects/store';
import providerRepoTableRow from '~/import_projects/components/provider_repo_table_row.vue';
import STATUS_MAP, { STATUSES } from '~/import_projects/constants';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
describe('ProviderRepoTableRow', () => {
let store;
let vm;
const repo = {
id: 10,
@ -28,6 +29,10 @@ describe('ProviderRepoTableRow', () => {
}).$mount();
}
beforeEach(() => {
store = createStore();
});
afterEach(() => {
vm.$destroy();
});