Skip to content
Snippets Groups Projects
Unverified Commit adb7f45a authored by Filipa Lacerda's avatar Filipa Lacerda
Browse files

Exports getters individually.

Exports state to allow tests
Adds specs for the getters that didn't have any.
parent 9a62e72d
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -20,16 +20,13 @@ export default {
},
},
computed: {
...mapGetters(['commit']),
...mapGetters(['commitId']),
normalizedDiffLines() {
return this.diffLines.map(line => (line.richText ? trimFirstCharOfLineContent(line) : line));
},
diffLinesLength() {
return this.normalizedDiffLines.length;
},
commitId() {
return this.commit && this.commit.id;
},
userColorScheme() {
return window.gon.user_color_scheme;
},
Loading
Loading
Loading
Loading
@@ -21,7 +21,7 @@ export default {
},
},
computed: {
...mapGetters(['commit']),
...mapGetters(['commitId']),
parallelDiffLines() {
return this.diffLines.map(line => {
const parallelLine = Object.assign({}, line);
Loading
Loading
@@ -44,9 +44,6 @@ export default {
diffLinesLength() {
return this.parallelDiffLines.length;
},
commitId() {
return this.commit && this.commit.id;
},
userColorScheme() {
return window.gon.user_color_scheme;
},
Loading
Loading
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants';
 
export default {
isParallelView(state) {
return state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
},
isInlineView(state) {
return state.diffViewType === INLINE_DIFF_VIEW_TYPE;
},
areAllFilesCollapsed(state) {
return state.diffFiles.every(file => file.collapsed);
},
commit(state) {
return state.commit;
},
};
export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
export const isInlineView = state => state.diffViewType === INLINE_DIFF_VIEW_TYPE;
export const areAllFilesCollapsed = state => state.diffFiles.every(file => file.collapsed);
export const commitId = state => (state.commit && state.commit.id ? state.commit.id : null);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
import Cookies from 'js-cookie';
import { getParameterValues } from '~/lib/utils/url_utility';
import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants';
const viewTypeFromQueryString = getParameterValues('view')[0];
const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME);
const defaultViewType = INLINE_DIFF_VIEW_TYPE;
export default () => ({
isLoading: true,
endpoint: '',
basePath: '',
commit: null,
diffFiles: [],
mergeRequestDiffs: [],
diffLineCommentForms: {},
diffViewType: viewTypeFromQueryString || viewTypeFromCookie || defaultViewType,
});
import Cookies from 'js-cookie';
import { getParameterValues } from '~/lib/utils/url_utility';
import actions from '../actions';
import getters from '../getters';
import * as getters from '../getters';
import mutations from '../mutations';
import { INLINE_DIFF_VIEW_TYPE, DIFF_VIEW_COOKIE_NAME } from '../../constants';
const viewTypeFromQueryString = getParameterValues('view')[0];
const viewTypeFromCookie = Cookies.get(DIFF_VIEW_COOKIE_NAME);
const defaultViewType = INLINE_DIFF_VIEW_TYPE;
import createState from './diff_state';
 
export default {
state: {
isLoading: true,
endpoint: '',
basePath: '',
commit: null,
diffFiles: [],
mergeRequestDiffs: [],
diffLineCommentForms: {},
diffViewType: viewTypeFromQueryString || viewTypeFromCookie || defaultViewType,
},
state: createState(),
getters,
actions,
mutations,
Loading
Loading
Loading
Loading
@@ -66,15 +66,10 @@ export default {
},
 
[types.EXPAND_ALL_FILES](state) {
const diffFiles = [];
state.diffFiles.forEach(file => {
diffFiles.push({
...file,
collapsed: false,
});
});
Object.assign(state, { diffFiles });
// eslint-disable-next-line no-param-reassign
state.diffFiles = state.diffFiles.map(file => ({
...file,
collapsed: false,
}));
},
};
---
title: Structure getters for diff Store properly and adds specs
merge_request:
author:
type: fixed
import getters from '~/diffs/store/getters';
import * as getters from '~/diffs/store/getters';
import state from '~/diffs/store/modules/diff_state';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants';
 
describe('DiffsStoreGetters', () => {
let localState;
beforeEach(() => {
localState = state();
});
describe('isParallelView', () => {
it('should return true if view set to parallel view', () => {
expect(getters.isParallelView({ diffViewType: PARALLEL_DIFF_VIEW_TYPE })).toBeTruthy();
localState.diffViewType = PARALLEL_DIFF_VIEW_TYPE;
expect(getters.isParallelView(localState)).toEqual(true);
});
 
it('should return false if view not to parallel view', () => {
expect(getters.isParallelView({ diffViewType: 'foo' })).toBeFalsy();
localState.diffViewType = INLINE_DIFF_VIEW_TYPE;
expect(getters.isParallelView(localState)).toEqual(false);
});
});
 
describe('isInlineView', () => {
it('should return true if view set to inline view', () => {
expect(getters.isInlineView({ diffViewType: INLINE_DIFF_VIEW_TYPE })).toBeTruthy();
localState.diffViewType = INLINE_DIFF_VIEW_TYPE;
expect(getters.isInlineView(localState)).toEqual(true);
});
 
it('should return false if view not to inline view', () => {
expect(getters.isInlineView({ diffViewType: PARALLEL_DIFF_VIEW_TYPE })).toBeFalsy();
localState.diffViewType = PARALLEL_DIFF_VIEW_TYPE;
expect(getters.isInlineView(localState)).toEqual(false);
});
});
describe('areAllFilesCollapsed', () => {
it('returns true when all files are collapsed', () => {
localState.diffFiles = [{ collapsed: true }, { collapsed: true }];
expect(getters.areAllFilesCollapsed(localState)).toEqual(true);
});
it('returns false when at least one file is not collapsed', () => {
localState.diffFiles = [{ collapsed: false }, { collapsed: true }];
expect(getters.areAllFilesCollapsed(localState)).toEqual(false);
});
});
describe('commitId', () => {
it('returns commit id when is set', () => {
const commitID = '800f7a91';
localState.commit = {
id: commitID,
};
expect(getters.commitId(localState)).toEqual(commitID);
});
it('returns null when no commit is set', () => {
expect(getters.commitId(localState)).toEqual(null);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment