debian-mirror-gitlab/spec/frontend/releases/stores/modules/list/mutations_spec.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import createState from '~/releases/stores/modules/list/state';
2020-03-13 15:44:24 +05:30
import mutations from '~/releases/stores/modules/list/mutations';
import * as types from '~/releases/stores/modules/list/mutation_types';
2020-01-01 13:55:28 +05:30
import { parseIntPagination } from '~/lib/utils/common_utils';
2020-03-13 15:44:24 +05:30
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(() => {
2020-11-24 15:15:51 +05:30
stateCopy = createState({});
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
});
});
});