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

109 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-12-23 12:14:25 +05:30
import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
2018-03-17 18:26:18 +05:30
import * as actions from '~/registry/stores/actions';
import * as types from '~/registry/stores/mutation_types';
2018-12-23 12:14:25 +05:30
import state from '~/registry/stores/state';
import { TEST_HOST } from 'spec/test_constants';
2018-03-17 18:26:18 +05:30
import testAction from '../../helpers/vuex_action_helper';
import {
reposServerResponse,
registryServerResponse,
parsedReposServerResponse,
} from '../mock_data';
describe('Actions Registry Store', () => {
let mockedState;
2018-12-23 12:14:25 +05:30
let mock;
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2018-12-23 12:14:25 +05:30
mockedState = state();
mockedState.endpoint = `${TEST_HOST}/endpoint.json`;
mock = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
});
2018-12-23 12:14:25 +05:30
afterEach(() => {
mock.restore();
});
2018-03-17 18:26:18 +05:30
2018-12-23 12:14:25 +05:30
describe('server requests', () => {
2018-03-17 18:26:18 +05:30
describe('fetchRepos', () => {
beforeEach(() => {
2018-12-23 12:14:25 +05:30
mock.onGet(`${TEST_HOST}/endpoint.json`).replyOnce(200, reposServerResponse, {});
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', () => {
2018-12-23 12:14:25 +05:30
let repo;
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2018-12-23 12:14:25 +05:30
mockedState.repos = parsedReposServerResponse;
[, repo] = mockedState.repos;
2018-03-17 18:26:18 +05:30
2018-12-23 12:14:25 +05:30
mock.onGet(repo.tagsPath).replyOnce(200, registryServerResponse, {});
2018-03-17 18:26:18 +05:30
});
2018-05-09 12:01:36 +05:30
it('should set received list', done => {
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
});
});
});