debian-mirror-gitlab/spec/javascripts/registry/stores/actions_spec.js

125 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-01-03 12:48:30 +05:30
import Vue from 'vue';
import VueResource from 'vue-resource';
import _ from 'underscore';
2018-03-17 18:26:18 +05:30
import * as actions from '~/registry/stores/actions';
import * as types from '~/registry/stores/mutation_types';
import testAction from '../../helpers/vuex_action_helper';
import {
2019-01-03 12:48:30 +05:30
defaultState,
2018-03-17 18:26:18 +05:30
reposServerResponse,
registryServerResponse,
parsedReposServerResponse,
} from '../mock_data';
2019-01-03 12:48:30 +05:30
Vue.use(VueResource);
2018-03-17 18:26:18 +05:30
describe('Actions Registry Store', () => {
2019-01-03 12:48:30 +05:30
let interceptor;
2018-03-17 18:26:18 +05:30
let mockedState;
beforeEach(() => {
2019-01-03 12:48:30 +05:30
mockedState = defaultState;
2018-12-23 12:14:25 +05:30
});
2018-03-17 18:26:18 +05:30
2018-12-23 12:14:25 +05:30
describe('server requests', () => {
2019-01-03 12:48:30 +05:30
afterEach(() => {
Vue.http.interceptors = _.without(Vue.http.interceptors, interceptor);
});
2018-03-17 18:26:18 +05:30
describe('fetchRepos', () => {
beforeEach(() => {
2019-01-03 12:48:30 +05:30
interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify(reposServerResponse), {
status: 200,
}),
);
};
Vue.http.interceptors.push(interceptor);
2018-03-17 18:26:18 +05:30
});
2018-05-09 12:01:36 +05:30
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 },
],
[],
done,
);
2018-03-17 18:26:18 +05:30
});
});
describe('fetchList', () => {
beforeEach(() => {
2019-01-03 12:48:30 +05:30
interceptor = (request, next) => {
next(
request.respondWith(JSON.stringify(registryServerResponse), {
status: 200,
}),
);
};
2018-03-17 18:26:18 +05:30
2019-01-03 12:48:30 +05:30
Vue.http.interceptors.push(interceptor);
2018-03-17 18:26:18 +05:30
});
2018-05-09 12:01:36 +05:30
it('should set received list', done => {
2019-01-03 12:48:30 +05:30
mockedState.repos = parsedReposServerResponse;
const repo = mockedState.repos[1];
2018-05-09 12:01:36 +05:30
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(),
},
},
],
[],
done,
);
2018-03-17 18:26:18 +05:30
});
});
});
describe('setMainEndpoint', () => {
2018-05-09 12:01:36 +05:30
it('should commit set main endpoint', done => {
testAction(
actions.setMainEndpoint,
'endpoint',
mockedState,
[{ type: types.SET_MAIN_ENDPOINT, payload: 'endpoint' }],
[],
done,
);
2018-03-17 18:26:18 +05:30
});
});
describe('toggleLoading', () => {
2018-05-09 12:01:36 +05:30
it('should commit toggle main loading', done => {
testAction(
actions.toggleLoading,
null,
mockedState,
[{ type: types.TOGGLE_MAIN_LOADING }],
[],
done,
);
2018-03-17 18:26:18 +05:30
});
});
});