Commit a424e814 authored by Tim Zallmann's avatar Tim Zallmann

Fixes for Karma Tests

parent b8b2cb36
...@@ -65,11 +65,6 @@ export default { ...@@ -65,11 +65,6 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
discussions: {
type: Array,
required: false,
default: () => [],
},
}, },
computed: { computed: {
...mapState({ ...mapState({
......
...@@ -6,13 +6,12 @@ import discussionsMockData from '../mock_data/diff_discussions'; ...@@ -6,13 +6,12 @@ import discussionsMockData from '../mock_data/diff_discussions';
import diffFileMockData from '../mock_data/diff_file'; import diffFileMockData from '../mock_data/diff_file';
describe('DiffLineGutterContent', () => { describe('DiffLineGutterContent', () => {
const getDiscussionsMockData = () => [Object.assign({}, discussionsMockData)];
const getDiffFileMock = () => Object.assign({}, diffFileMockData); const getDiffFileMock = () => Object.assign({}, diffFileMockData);
const createComponent = (options = {}) => { const createComponent = (options = {}) => {
const cmp = Vue.extend(DiffLineGutterContent); const cmp = Vue.extend(DiffLineGutterContent);
const props = Object.assign({}, options); const props = Object.assign({}, options);
props.line = { props.line = {
lineCode: 'LC_42', code: 'LC_42',
type: 'new', type: 'new',
oldLine: null, oldLine: null,
newLine: 1, newLine: 1,
...@@ -26,51 +25,42 @@ describe('DiffLineGutterContent', () => { ...@@ -26,51 +25,42 @@ describe('DiffLineGutterContent', () => {
return createComponentWithStore(cmp, store, props).$mount(); return createComponentWithStore(cmp, store, props).$mount();
}; };
const setDiscussions = component => {
component.$store.dispatch('setInitialNotes', getDiscussionsMockData());
};
const resetDiscussions = component => {
component.$store.dispatch('setInitialNotes', []);
};
describe('computed', () => { describe('computed', () => {
describe('lineHref', () => { describe('lineHref', () => {
it('should prepend # to lineCode', () => { it('should prepend # to lineCode', () => {
const lineCode = 'LC_42'; const lineCode = 'LC_42';
const component = createComponent({ lineCode }); const component = createComponent();
expect(component.lineHref).toEqual(`#${lineCode}`); expect(component.lineHref).toEqual(`#${lineCode}`);
}); });
it('should return # if there is no lineCode', () => { it('should return # if there is no lineCode', () => {
const component = createComponent({ lineCode: null }); const component = createComponent();
component.line.code = '';
expect(component.lineHref).toEqual('#'); expect(component.lineHref).toEqual('#');
}); });
}); });
describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => { describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => {
it('should return empty array when there is no discussion', () => { it('should return empty array when there is no discussion', () => {
const component = createComponent({ lineCode: 'LC_42' }); const component = createComponent();
expect(component.discussions).toEqual([]);
expect(component.hasDiscussions).toEqual(false); expect(component.hasDiscussions).toEqual(false);
expect(component.shouldShowAvatarsOnGutter).toEqual(false); expect(component.shouldShowAvatarsOnGutter).toEqual(false);
}); });
it('should return discussions for the given lineCode', () => { it('should return discussions for the given lineCode', () => {
const { lineCode } = getDiffFileMock().highlightedDiffLines[1]; const cmp = Vue.extend(DiffLineGutterContent);
const component = createComponent({ const props = {
lineCode, line: getDiffFileMock().highlightedDiffLines[1],
fileHash: getDiffFileMock().fileHash,
showCommentButton: true, showCommentButton: true,
discussions: getDiscussionsMockData(), contextLinesPath: '/context/lines/path',
}); };
props.line.discussions = [Object.assign({}, discussionsMockData)];
const component = createComponentWithStore(cmp, store, props).$mount();
setDiscussions(component);
expect(component.discussions).toEqual(getDiscussionsMockData());
expect(component.hasDiscussions).toEqual(true); expect(component.hasDiscussions).toEqual(true);
expect(component.shouldShowAvatarsOnGutter).toEqual(true); expect(component.shouldShowAvatarsOnGutter).toEqual(true);
resetDiscussions(component);
}); });
}); });
}); });
...@@ -114,9 +104,7 @@ describe('DiffLineGutterContent', () => { ...@@ -114,9 +104,7 @@ describe('DiffLineGutterContent', () => {
lineCode: getDiffFileMock().highlightedDiffLines[1].lineCode, lineCode: getDiffFileMock().highlightedDiffLines[1].lineCode,
}); });
setDiscussions(component);
expect(component.$el.querySelector('.diff-comment-avatar-holders')).toBeDefined(); expect(component.$el.querySelector('.diff-comment-avatar-holders')).toBeDefined();
resetDiscussions(component);
}); });
}); });
}); });
...@@ -99,6 +99,7 @@ export default { ...@@ -99,6 +99,7 @@ export default {
type: 'match', type: 'match',
oldLine: null, oldLine: null,
newLine: null, newLine: null,
discussions: [],
text: '', text: '',
richText: '', richText: '',
metaData: { metaData: {
......
...@@ -179,32 +179,45 @@ describe('DiffsStoreUtils', () => { ...@@ -179,32 +179,45 @@ describe('DiffsStoreUtils', () => {
describe('trimFirstCharOfLineContent', () => { describe('trimFirstCharOfLineContent', () => {
it('trims the line when it starts with a space', () => { it('trims the line when it starts with a space', () => {
expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({ richText: 'diff' }); expect(utils.trimFirstCharOfLineContent({ richText: ' diff' })).toEqual({
discussions: [],
richText: 'diff',
});
}); });
it('trims the line when it starts with a +', () => { it('trims the line when it starts with a +', () => {
expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({ richText: 'diff' }); expect(utils.trimFirstCharOfLineContent({ richText: '+diff' })).toEqual({
discussions: [],
richText: 'diff',
});
}); });
it('trims the line when it starts with a -', () => { it('trims the line when it starts with a -', () => {
expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({ richText: 'diff' }); expect(utils.trimFirstCharOfLineContent({ richText: '-diff' })).toEqual({
discussions: [],
richText: 'diff',
});
}); });
it('does not trims the line when it starts with a letter', () => { it('does not trims the line when it starts with a letter', () => {
expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({ richText: 'diff' }); expect(utils.trimFirstCharOfLineContent({ richText: 'diff' })).toEqual({
discussions: [],
richText: 'diff',
});
}); });
it('does not modify the provided object', () => { it('does not modify the provided object', () => {
const lineObj = { const lineObj = {
discussions: [],
richText: ' diff', richText: ' diff',
}; };
utils.trimFirstCharOfLineContent(lineObj); utils.trimFirstCharOfLineContent(lineObj);
expect(lineObj).toEqual({ richText: ' diff' }); expect(lineObj).toEqual({ discussions: [], richText: ' diff' });
}); });
it('handles a undefined or null parameter', () => { it('handles a undefined or null parameter', () => {
expect(utils.trimFirstCharOfLineContent()).toEqual({}); expect(utils.trimFirstCharOfLineContent()).toEqual({ discussions: [] });
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment