Commit 4ed3010b authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'xanf-vtu-v1-artifacts-list' into 'master'

Upgrading VTU to v1: Remove deprecated `methods` option from artifacts_list_app_spec

See merge request gitlab-org/gitlab!50494
parents bea95666 fc71982d
...@@ -7,10 +7,11 @@ import state from './state'; ...@@ -7,10 +7,11 @@ import state from './state';
Vue.use(Vuex); Vue.use(Vuex);
export default () => export const getStoreConfig = () => ({
new Vuex.Store({ actions,
actions, mutations,
mutations, getters,
getters, state: state(),
state: state(), });
});
export default () => new Vuex.Store(getStoreConfig());
import { mount, createLocalVue } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Vue, { nextTick } from 'vue';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST as FAKE_ENDPOINT } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import ArtifactsListApp from '~/vue_merge_request_widget/components/artifacts_list_app.vue'; import ArtifactsListApp from '~/vue_merge_request_widget/components/artifacts_list_app.vue';
import createStore from '~/vue_merge_request_widget/stores/artifacts_list'; import { getStoreConfig } from '~/vue_merge_request_widget/stores/artifacts_list';
import { artifactsList } from './mock_data'; import { artifactsList } from './mock_data';
Vue.use(Vuex);
describe('Merge Requests Artifacts list app', () => { describe('Merge Requests Artifacts list app', () => {
let wrapper; let wrapper;
let store;
let mock; let mock;
const store = createStore();
const localVue = createLocalVue();
localVue.use(Vuex);
const actionSpies = { const actionSpies = {
fetchArtifacts: jest.fn(), fetchArtifacts: jest.fn(),
...@@ -29,15 +30,20 @@ describe('Merge Requests Artifacts list app', () => { ...@@ -29,15 +30,20 @@ describe('Merge Requests Artifacts list app', () => {
}); });
const createComponent = () => { const createComponent = () => {
const storeConfig = getStoreConfig();
store = new Vuex.Store({
...storeConfig,
actions: {
...storeConfig.actions,
...actionSpies,
},
});
wrapper = mount(ArtifactsListApp, { wrapper = mount(ArtifactsListApp, {
propsData: { propsData: {
endpoint: TEST_HOST, endpoint: FAKE_ENDPOINT,
}, },
store, store,
methods: {
...actionSpies,
},
localVue,
}); });
}; };
...@@ -50,7 +56,7 @@ describe('Merge Requests Artifacts list app', () => { ...@@ -50,7 +56,7 @@ describe('Merge Requests Artifacts list app', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
store.dispatch('requestArtifacts'); store.dispatch('requestArtifacts');
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('renders a loading icon', () => { it('renders a loading icon', () => {
...@@ -72,12 +78,12 @@ describe('Merge Requests Artifacts list app', () => { ...@@ -72,12 +78,12 @@ describe('Merge Requests Artifacts list app', () => {
describe('with results', () => { describe('with results', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
mock.onGet(wrapper.vm.$store.state.endpoint).reply(200, artifactsList, {}); mock.onGet(FAKE_ENDPOINT).reply(200, artifactsList, {});
store.dispatch('receiveArtifactsSuccess', { store.dispatch('receiveArtifactsSuccess', {
data: artifactsList, data: artifactsList,
status: 200, status: 200,
}); });
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('renders a title with the number of artifacts', () => { it('renders a title with the number of artifacts', () => {
...@@ -91,11 +97,11 @@ describe('Merge Requests Artifacts list app', () => { ...@@ -91,11 +97,11 @@ describe('Merge Requests Artifacts list app', () => {
}); });
describe('on click', () => { describe('on click', () => {
it('renders the list of artifacts', () => { it('renders the list of artifacts', async () => {
findTitle().trigger('click'); findTitle().trigger('click');
wrapper.vm.$nextTick(() => { await nextTick();
expect(findTableRows().length).toEqual(2);
}); expect(findTableRows().length).toEqual(2);
}); });
}); });
}); });
...@@ -103,9 +109,9 @@ describe('Merge Requests Artifacts list app', () => { ...@@ -103,9 +109,9 @@ describe('Merge Requests Artifacts list app', () => {
describe('with error', () => { describe('with error', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
mock.onGet(wrapper.vm.$store.state.endpoint).reply(500, {}, {}); mock.onGet(FAKE_ENDPOINT).reply(500, {}, {});
store.dispatch('receiveArtifactsError'); store.dispatch('receiveArtifactsError');
return wrapper.vm.$nextTick(); return nextTick();
}); });
it('renders the error state', () => { it('renders the error state', () => {
......
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