debian-mirror-gitlab/spec/frontend/code_navigation/store/mutations_spec.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import mutations from '~/code_navigation/store/mutations';
import createState from '~/code_navigation/store/state';
let state;
describe('Code navigation mutations', () => {
beforeEach(() => {
state = createState();
});
describe('SET_INITIAL_DATA', () => {
it('sets initial data', () => {
mutations.SET_INITIAL_DATA(state, {
2020-04-22 19:07:51 +05:30
blobs: ['test'],
definitionPathPrefix: 'https://test.com/blob/master',
2020-03-13 15:44:24 +05:30
});
2020-04-22 19:07:51 +05:30
expect(state.blobs).toEqual(['test']);
expect(state.definitionPathPrefix).toBe('https://test.com/blob/master');
2020-03-13 15:44:24 +05:30
});
});
describe('REQUEST_DATA', () => {
it('sets loading true', () => {
mutations.REQUEST_DATA(state);
expect(state.loading).toBe(true);
});
});
describe('REQUEST_DATA_SUCCESS', () => {
it('sets loading false', () => {
mutations.REQUEST_DATA_SUCCESS(state, ['test']);
expect(state.loading).toBe(false);
});
it('sets data', () => {
2020-04-22 19:07:51 +05:30
mutations.REQUEST_DATA_SUCCESS(state, { path: 'index.js', normalizedData: ['test'] });
2020-03-13 15:44:24 +05:30
2020-04-22 19:07:51 +05:30
expect(state.data).toEqual({ 'index.js': ['test'] });
2020-03-13 15:44:24 +05:30
});
});
describe('REQUEST_DATA_ERROR', () => {
it('sets loading false', () => {
mutations.REQUEST_DATA_ERROR(state);
expect(state.loading).toBe(false);
});
});
describe('SET_CURRENT_DEFINITION', () => {
it('sets current definition and position', () => {
mutations.SET_CURRENT_DEFINITION(state, { definition: 'test', position: { x: 0 } });
expect(state.currentDefinition).toBe('test');
expect(state.currentDefinitionPosition).toEqual({ x: 0 });
});
});
});