2020-02-06 07:10:29 -05:00
|
|
|
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-09 02:09:30 -04:00
|
|
|
blobs: ['test'],
|
2021-05-04 20:10:41 -04:00
|
|
|
definitionPathPrefix: 'https://test.com/blob/main',
|
2022-04-08 14:08:29 -04:00
|
|
|
wrapTextNodes: true,
|
2020-02-06 07:10:29 -05:00
|
|
|
});
|
|
|
|
|
2020-04-09 02:09:30 -04:00
|
|
|
expect(state.blobs).toEqual(['test']);
|
2021-05-04 20:10:41 -04:00
|
|
|
expect(state.definitionPathPrefix).toBe('https://test.com/blob/main');
|
2022-04-08 14:08:29 -04:00
|
|
|
expect(state.wrapTextNodes).toBe(true);
|
2020-02-06 07:10:29 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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-09 02:09:30 -04:00
|
|
|
mutations.REQUEST_DATA_SUCCESS(state, { path: 'index.js', normalizedData: ['test'] });
|
2020-02-06 07:10:29 -05:00
|
|
|
|
2020-04-09 02:09:30 -04:00
|
|
|
expect(state.data).toEqual({ 'index.js': ['test'] });
|
2020-02-06 07:10:29 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|