2017-09-20 14:03:53 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueResource from 'vue-resource';
|
|
|
|
import _ from 'underscore';
|
|
|
|
import * as actions from '~/registry/stores/actions';
|
|
|
|
import * as types from '~/registry/stores/mutation_types';
|
|
|
|
import testAction from '../../helpers/vuex_action_helper';
|
|
|
|
import {
|
|
|
|
defaultState,
|
|
|
|
reposServerResponse,
|
|
|
|
registryServerResponse,
|
|
|
|
parsedReposServerResponse,
|
2017-09-26 07:02:03 -04:00
|
|
|
} from '../mock_data';
|
2017-09-20 14:03:53 -04:00
|
|
|
|
|
|
|
Vue.use(VueResource);
|
|
|
|
|
|
|
|
describe('Actions Registry Store', () => {
|
|
|
|
let interceptor;
|
|
|
|
let mockedState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockedState = defaultState;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('server requests', () => {
|
|
|
|
afterEach(() => {
|
|
|
|
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchRepos', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
interceptor = (request, next) => {
|
2018-03-29 05:43:32 -04:00
|
|
|
next(
|
|
|
|
request.respondWith(JSON.stringify(reposServerResponse), {
|
|
|
|
status: 200,
|
|
|
|
}),
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Vue.http.interceptors.push(interceptor);
|
|
|
|
});
|
|
|
|
|
2018-03-29 05:43:32 -04:00
|
|
|
it('should set receveived repos', done => {
|
|
|
|
testAction(
|
|
|
|
actions.fetchRepos,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{ type: types.TOGGLE_MAIN_LOADING },
|
|
|
|
{ type: types.TOGGLE_MAIN_LOADING },
|
|
|
|
{ type: types.SET_REPOS_LIST, payload: reposServerResponse },
|
|
|
|
],
|
2018-03-29 06:14:18 -04:00
|
|
|
[],
|
2018-03-29 05:43:32 -04:00
|
|
|
done,
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchList', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
interceptor = (request, next) => {
|
2018-03-29 05:43:32 -04:00
|
|
|
next(
|
|
|
|
request.respondWith(JSON.stringify(registryServerResponse), {
|
|
|
|
status: 200,
|
|
|
|
}),
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
Vue.http.interceptors.push(interceptor);
|
|
|
|
});
|
|
|
|
|
2018-03-29 05:43:32 -04:00
|
|
|
it('should set received list', done => {
|
2017-09-20 14:03:53 -04:00
|
|
|
mockedState.repos = parsedReposServerResponse;
|
|
|
|
|
2018-03-29 05:43:32 -04:00
|
|
|
const repo = mockedState.repos[1];
|
|
|
|
|
|
|
|
testAction(
|
|
|
|
actions.fetchList,
|
|
|
|
{ repo },
|
|
|
|
mockedState,
|
|
|
|
[
|
|
|
|
{ type: types.TOGGLE_REGISTRY_LIST_LOADING, payload: repo },
|
|
|
|
{ type: types.TOGGLE_REGISTRY_LIST_LOADING, payload: repo },
|
|
|
|
{
|
|
|
|
type: types.SET_REGISTRY_LIST,
|
|
|
|
payload: {
|
|
|
|
repo,
|
|
|
|
resp: registryServerResponse,
|
|
|
|
headers: jasmine.anything(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-03-29 06:14:18 -04:00
|
|
|
[],
|
2018-03-29 05:43:32 -04:00
|
|
|
done,
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setMainEndpoint', () => {
|
2018-03-29 05:43:32 -04:00
|
|
|
it('should commit set main endpoint', done => {
|
|
|
|
testAction(
|
|
|
|
actions.setMainEndpoint,
|
|
|
|
'endpoint',
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.SET_MAIN_ENDPOINT, payload: 'endpoint' }],
|
2018-03-29 06:14:18 -04:00
|
|
|
[],
|
2018-03-29 05:43:32 -04:00
|
|
|
done,
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('toggleLoading', () => {
|
2018-03-29 05:43:32 -04:00
|
|
|
it('should commit toggle main loading', done => {
|
|
|
|
testAction(
|
|
|
|
actions.toggleLoading,
|
|
|
|
null,
|
|
|
|
mockedState,
|
|
|
|
[{ type: types.TOGGLE_MAIN_LOADING }],
|
2018-03-29 06:14:18 -04:00
|
|
|
[],
|
2018-03-29 05:43:32 -04:00
|
|
|
done,
|
|
|
|
);
|
2017-09-20 14:03:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|