2017-09-20 14:03:53 -04:00
|
|
|
import mutations from '~/registry/stores/mutations';
|
|
|
|
import * as types from '~/registry/stores/mutation_types';
|
|
|
|
import {
|
|
|
|
defaultState,
|
|
|
|
reposServerResponse,
|
|
|
|
registryServerResponse,
|
|
|
|
parsedReposServerResponse,
|
|
|
|
parsedRegistryServerResponse,
|
2017-09-26 07:02:03 -04:00
|
|
|
} from '../mock_data';
|
2017-09-20 14:03:53 -04:00
|
|
|
|
|
|
|
describe('Mutations Registry Store', () => {
|
|
|
|
let mockState;
|
|
|
|
beforeEach(() => {
|
|
|
|
mockState = defaultState;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_MAIN_ENDPOINT', () => {
|
|
|
|
it('should set the main endpoint', () => {
|
|
|
|
const expectedState = Object.assign({}, mockState, { endpoint: 'foo' });
|
|
|
|
mutations[types.SET_MAIN_ENDPOINT](mockState, 'foo');
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-09-20 14:03:53 -04:00
|
|
|
expect(mockState).toEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_REPOS_LIST', () => {
|
|
|
|
it('should set a parsed repository list', () => {
|
|
|
|
mutations[types.SET_REPOS_LIST](mockState, reposServerResponse);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-09-20 14:03:53 -04:00
|
|
|
expect(mockState.repos).toEqual(parsedReposServerResponse);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_MAIN_LOADING', () => {
|
|
|
|
it('should set a parsed repository list', () => {
|
|
|
|
mutations[types.TOGGLE_MAIN_LOADING](mockState);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-09-20 14:03:53 -04:00
|
|
|
expect(mockState.isLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('SET_REGISTRY_LIST', () => {
|
|
|
|
it('should set a list of registries in a specific repository', () => {
|
|
|
|
mutations[types.SET_REPOS_LIST](mockState, reposServerResponse);
|
2017-09-22 06:46:55 -04:00
|
|
|
mutations[types.SET_REGISTRY_LIST](mockState, {
|
|
|
|
repo: mockState.repos[0],
|
|
|
|
resp: registryServerResponse,
|
|
|
|
headers: {
|
|
|
|
'x-per-page': 2,
|
|
|
|
'x-page': 1,
|
|
|
|
'x-total': 10,
|
|
|
|
},
|
|
|
|
});
|
2017-09-20 14:03:53 -04:00
|
|
|
|
|
|
|
expect(mockState.repos[0].list).toEqual(parsedRegistryServerResponse);
|
2017-09-22 06:46:55 -04:00
|
|
|
expect(mockState.repos[0].pagination).toEqual({
|
|
|
|
perPage: 2,
|
|
|
|
page: 1,
|
|
|
|
total: 10,
|
|
|
|
totalPages: NaN,
|
|
|
|
nextPage: NaN,
|
|
|
|
previousPage: NaN,
|
|
|
|
});
|
2017-09-20 14:03:53 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('TOGGLE_REGISTRY_LIST_LOADING', () => {
|
|
|
|
it('should toggle isLoading property for a specific repository', () => {
|
|
|
|
mutations[types.SET_REPOS_LIST](mockState, reposServerResponse);
|
2017-09-22 06:46:55 -04:00
|
|
|
mutations[types.SET_REGISTRY_LIST](mockState, {
|
|
|
|
repo: mockState.repos[0],
|
|
|
|
resp: registryServerResponse,
|
|
|
|
headers: {
|
|
|
|
'x-per-page': 2,
|
|
|
|
'x-page': 1,
|
|
|
|
'x-total': 10,
|
|
|
|
},
|
|
|
|
});
|
2017-09-20 14:03:53 -04:00
|
|
|
|
|
|
|
mutations[types.TOGGLE_REGISTRY_LIST_LOADING](mockState, mockState.repos[0]);
|
2018-10-09 14:03:09 -04:00
|
|
|
|
2017-09-20 14:03:53 -04:00
|
|
|
expect(mockState.repos[0].isLoading).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|