debian-mirror-gitlab/spec/javascripts/releases/list/store/mutations_spec.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import state from '~/releases/list/store/state';
import mutations from '~/releases/list/store/mutations';
import * as types from '~/releases/list/store/mutation_types';
2020-01-01 13:55:28 +05:30
import { parseIntPagination } from '~/lib/utils/common_utils';
import { pageInfoHeadersWithoutPagination, releases } from '../../mock_data';
2019-02-15 15:39:39 +05:30
describe('Releases Store Mutations', () => {
let stateCopy;
2020-01-01 13:55:28 +05:30
let pageInfo;
2019-02-15 15:39:39 +05:30
beforeEach(() => {
stateCopy = state();
2020-01-01 13:55:28 +05:30
pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination);
2019-02-15 15:39:39 +05:30
});
describe('REQUEST_RELEASES', () => {
it('sets isLoading to true', () => {
mutations[types.REQUEST_RELEASES](stateCopy);
expect(stateCopy.isLoading).toEqual(true);
});
});
describe('RECEIVE_RELEASES_SUCCESS', () => {
beforeEach(() => {
2020-01-01 13:55:28 +05:30
mutations[types.RECEIVE_RELEASES_SUCCESS](stateCopy, { pageInfo, data: releases });
2019-02-15 15:39:39 +05:30
});
it('sets is loading to false', () => {
expect(stateCopy.isLoading).toEqual(false);
});
it('sets hasError to false', () => {
expect(stateCopy.hasError).toEqual(false);
});
it('sets data', () => {
expect(stateCopy.releases).toEqual(releases);
});
2020-01-01 13:55:28 +05:30
it('sets pageInfo', () => {
expect(stateCopy.pageInfo).toEqual(pageInfo);
});
2019-02-15 15:39:39 +05:30
});
describe('RECEIVE_RELEASES_ERROR', () => {
it('resets data', () => {
mutations[types.RECEIVE_RELEASES_ERROR](stateCopy);
expect(stateCopy.isLoading).toEqual(false);
expect(stateCopy.releases).toEqual([]);
2020-01-01 13:55:28 +05:30
expect(stateCopy.pageInfo).toEqual({});
2019-02-15 15:39:39 +05:30
});
});
});