Commit d64ec5df authored by Winnie Hellmann's avatar Winnie Hellmann

Use factory method for import_projects store

Make sure we always create a new instance of the import_projects store.
parent dc5fc283
...@@ -3,7 +3,7 @@ import { mapActions } from 'vuex'; ...@@ -3,7 +3,7 @@ import { mapActions } from 'vuex';
import Translate from '../vue_shared/translate'; import Translate from '../vue_shared/translate';
import ImportProjectsTable from './components/import_projects_table.vue'; import ImportProjectsTable from './components/import_projects_table.vue';
import { parseBoolean } from '../lib/utils/common_utils'; import { parseBoolean } from '../lib/utils/common_utils';
import store from './store'; import createStore from './store';
Vue.use(Translate); Vue.use(Translate);
...@@ -20,6 +20,7 @@ export default function mountImportProjectsTable(mountElement) { ...@@ -20,6 +20,7 @@ export default function mountImportProjectsTable(mountElement) {
ciCdOnly, ciCdOnly,
} = mountElement.dataset; } = mountElement.dataset;
const store = createStore();
return new Vue({ return new Vue({
el: mountElement, el: mountElement,
store, store,
......
...@@ -7,9 +7,10 @@ import mutations from './mutations'; ...@@ -7,9 +7,10 @@ import mutations from './mutations';
Vue.use(Vuex); Vue.use(Vuex);
export default new Vuex.Store({ export default () =>
state: state(), new Vuex.Store({
actions, state: state(),
mutations, actions,
getters, mutations,
}); getters,
});
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; 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 importProjectsTable from '~/import_projects/components/import_projects_table.vue';
import STATUS_MAP from '~/import_projects/constants'; import STATUS_MAP from '~/import_projects/constants';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper'; import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
...@@ -9,6 +9,7 @@ import setTimeoutPromise from '../../helpers/set_timeout_promise_helper'; ...@@ -9,6 +9,7 @@ import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
describe('ImportProjectsTable', () => { describe('ImportProjectsTable', () => {
let vm; let vm;
let mock; let mock;
let store;
const reposPath = '/repos-path'; const reposPath = '/repos-path';
const jobsPath = '/jobs-path'; const jobsPath = '/jobs-path';
const providerTitle = 'THE PROVIDER'; const providerTitle = 'THE PROVIDER';
...@@ -31,12 +32,13 @@ describe('ImportProjectsTable', () => { ...@@ -31,12 +32,13 @@ describe('ImportProjectsTable', () => {
}, },
}).$mount(); }).$mount();
component.$store.dispatch('stopJobsPolling'); store.dispatch('stopJobsPolling');
return component; return component;
} }
beforeEach(() => { beforeEach(() => {
store = createStore();
store.dispatch('setInitialData', { reposPath }); store.dispatch('setInitialData', { reposPath });
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -167,7 +169,7 @@ describe('ImportProjectsTable', () => { ...@@ -167,7 +169,7 @@ describe('ImportProjectsTable', () => {
expect(vm.$el.querySelector(`.ic-status_${statusObject.icon}`)).not.toBeNull(); expect(vm.$el.querySelector(`.ic-status_${statusObject.icon}`)).not.toBeNull();
mock.onGet(jobsPath).replyOnce(200, updatedProjects); mock.onGet(jobsPath).replyOnce(200, updatedProjects);
return vm.$store.dispatch('restartJobsPolling'); return store.dispatch('restartJobsPolling');
}) })
.then(() => setTimeoutPromise()) .then(() => setTimeoutPromise())
.then(() => { .then(() => {
......
import Vue from 'vue'; 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 importedProjectTableRow from '~/import_projects/components/imported_project_table_row.vue';
import STATUS_MAP from '~/import_projects/constants'; import STATUS_MAP from '~/import_projects/constants';
...@@ -16,6 +16,7 @@ describe('ImportedProjectTableRow', () => { ...@@ -16,6 +16,7 @@ describe('ImportedProjectTableRow', () => {
function createComponent() { function createComponent() {
const ImportedProjectTableRow = Vue.extend(importedProjectTableRow); const ImportedProjectTableRow = Vue.extend(importedProjectTableRow);
const store = createStore();
return new ImportedProjectTableRow({ return new ImportedProjectTableRow({
store, store,
propsData: { propsData: {
......
import Vue from 'vue'; import Vue from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; 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 providerRepoTableRow from '~/import_projects/components/provider_repo_table_row.vue';
import STATUS_MAP, { STATUSES } from '~/import_projects/constants'; import STATUS_MAP, { STATUSES } from '~/import_projects/constants';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper'; import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
describe('ProviderRepoTableRow', () => { describe('ProviderRepoTableRow', () => {
let store;
let vm; let vm;
const repo = { const repo = {
id: 10, id: 10,
...@@ -28,6 +29,10 @@ describe('ProviderRepoTableRow', () => { ...@@ -28,6 +29,10 @@ describe('ProviderRepoTableRow', () => {
}).$mount(); }).$mount();
} }
beforeEach(() => {
store = createStore();
});
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
}); });
......
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