Commit 57c32c7d authored by Filipa Lacerda's avatar Filipa Lacerda

Adds specs for getters in merge request vuex diff module

parent 135ead1d
...@@ -95,7 +95,6 @@ export const expandAllFiles = ({ commit }) => { ...@@ -95,7 +95,6 @@ export const expandAllFiles = ({ commit }) => {
*/ */
export const toggleFileDiscussions = ({ getters, dispatch }, diff) => { export const toggleFileDiscussions = ({ getters, dispatch }, diff) => {
const discussions = getters.getDiffFileDiscussions(diff); const discussions = getters.getDiffFileDiscussions(diff);
const shouldCloseAll = getters.diffHasAllExpandedDiscussions(diff); const shouldCloseAll = getters.diffHasAllExpandedDiscussions(diff);
const shouldExpandAll = getters.diffHasAllCollpasedDiscussions(diff); const shouldExpandAll = getters.diffHasAllCollpasedDiscussions(diff);
......
...@@ -4,7 +4,7 @@ import diffsModule from '~/diffs/store/modules'; ...@@ -4,7 +4,7 @@ import diffsModule from '~/diffs/store/modules';
import notesModule from '~/notes/stores/modules'; import notesModule from '~/notes/stores/modules';
import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import mountComponent, { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
const discussionFixture = 'merge_requests/diff_discussion.json'; const discussionFixture = 'merge_requests/diff_discussion.json';
......
...@@ -5,9 +5,20 @@ import discussion from '../mock_data/diff_discussions'; ...@@ -5,9 +5,20 @@ import discussion from '../mock_data/diff_discussions';
describe('Diffs Module Getters', () => { describe('Diffs Module Getters', () => {
let localState; let localState;
let discussionMock;
let discussionMock1;
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
beforeEach(() => { beforeEach(() => {
localState = state(); localState = state();
discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash;
discussionMock1 = Object.assign({}, discussion);
discussionMock1.diff_file.file_hash = diffFileMock.fileHash;
}); });
describe('isParallelView', () => { describe('isParallelView', () => {
...@@ -67,13 +78,6 @@ describe('Diffs Module Getters', () => { ...@@ -67,13 +78,6 @@ describe('Diffs Module Getters', () => {
describe('diffHasAllExpandedDiscussions', () => { describe('diffHasAllExpandedDiscussions', () => {
it('returns true when all discussions are expanded', () => { it('returns true when all discussions are expanded', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash;
expect( expect(
getters.diffHasAllExpandedDiscussions(localState, { getters.diffHasAllExpandedDiscussions(localState, {
getDiffFileDiscussions: () => [discussionMock, discussionMock], getDiffFileDiscussions: () => [discussionMock, discussionMock],
...@@ -82,10 +86,6 @@ describe('Diffs Module Getters', () => { ...@@ -82,10 +86,6 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when there are no discussions', () => { it('returns false when there are no discussions', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
expect( expect(
getters.diffHasAllExpandedDiscussions(localState, { getters.diffHasAllExpandedDiscussions(localState, {
getDiffFileDiscussions: () => [], getDiffFileDiscussions: () => [],
...@@ -94,15 +94,6 @@ describe('Diffs Module Getters', () => { ...@@ -94,15 +94,6 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when one discussions is collapsed', () => { it('returns false when one discussions is collapsed', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash;
const discussionMock1 = Object.assign({}, discussion);
discussionMock1.diff_file.file_hash = diffFileMock.fileHash;
discussionMock1.expanded = false; discussionMock1.expanded = false;
expect( expect(
...@@ -115,11 +106,6 @@ describe('Diffs Module Getters', () => { ...@@ -115,11 +106,6 @@ describe('Diffs Module Getters', () => {
describe('diffHasAllCollpasedDiscussions', () => { describe('diffHasAllCollpasedDiscussions', () => {
it('returns true when all discussions are collapsed', () => { it('returns true when all discussions are collapsed', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash; discussionMock.diff_file.file_hash = diffFileMock.fileHash;
discussionMock.expanded = false; discussionMock.expanded = false;
...@@ -131,10 +117,6 @@ describe('Diffs Module Getters', () => { ...@@ -131,10 +117,6 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when there are no discussions', () => { it('returns false when there are no discussions', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
expect( expect(
getters.diffHasAllCollpasedDiscussions(localState, { getters.diffHasAllCollpasedDiscussions(localState, {
getDiffFileDiscussions: () => [], getDiffFileDiscussions: () => [],
...@@ -143,14 +125,6 @@ describe('Diffs Module Getters', () => { ...@@ -143,14 +125,6 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when one discussions is expanded', () => { it('returns false when one discussions is expanded', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash;
const discussionMock1 = Object.assign({}, discussion);
discussionMock1.diff_file.file_hash = diffFileMock.fileHash;
discussionMock1.expanded = false; discussionMock1.expanded = false;
expect( expect(
...@@ -163,14 +137,6 @@ describe('Diffs Module Getters', () => { ...@@ -163,14 +137,6 @@ describe('Diffs Module Getters', () => {
describe('diffHasExpandedDiscussions', () => { describe('diffHasExpandedDiscussions', () => {
it('returns true when one of the discussions is expanded', () => { it('returns true when one of the discussions is expanded', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussionMock.diff_file.file_hash = diffFileMock.fileHash;
const discussionMock1 = Object.assign({}, discussion);
discussionMock1.diff_file.file_hash = diffFileMock.fileHash;
discussionMock1.expanded = false; discussionMock1.expanded = false;
expect( expect(
...@@ -181,10 +147,6 @@ describe('Diffs Module Getters', () => { ...@@ -181,10 +147,6 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when there are no discussions', () => { it('returns false when there are no discussions', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
expect( expect(
getters.diffHasExpandedDiscussions(localState, { getDiffFileDiscussions: () => [] })( getters.diffHasExpandedDiscussions(localState, { getDiffFileDiscussions: () => [] })(
diffFileMock, diffFileMock,
...@@ -193,17 +155,7 @@ describe('Diffs Module Getters', () => { ...@@ -193,17 +155,7 @@ describe('Diffs Module Getters', () => {
}); });
it('returns false when no discussion is expanded', () => { it('returns false when no discussion is expanded', () => {
const diffFileMock = {
fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
};
const discussionMock = Object.assign({}, discussion);
discussion.diff_file.file_hash = diffFileMock.fileHash;
discussionMock.expanded = false; discussionMock.expanded = false;
const discussionMock1 = Object.assign({}, discussion);
discussionMock1.diff_file.file_hash = diffFileMock.fileHash;
discussionMock1.expanded = false; discussionMock1.expanded = false;
expect( expect(
...@@ -214,38 +166,22 @@ describe('Diffs Module Getters', () => { ...@@ -214,38 +166,22 @@ describe('Diffs Module Getters', () => {
}); });
}); });
// describe('getDiffFileDiscussions', () => { describe('getDiffFileDiscussions', () => {
// it('returns an array with discussions when fileHash matches and the discussion belongs to a diff', () => { it('returns an array with discussions when fileHash matches and the discussion belongs to a diff', () => {
// const diffFileMock = { discussionMock.diff_file.file_hash = diffFileMock.fileHash;
// fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
// }; expect(
getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [discussionMock] })(
// const discussionMock = Object.assign({}, discussion); diffFileMock,
// discussionMock.diff_file.file_hash = diffFileMock.fileHash; ).length,
).toEqual(1);
// expect( });
// getters.getDiffFileDiscussions(
// localState, it('returns an empty array when no discussions are found in the given diff', () => {
// {}, expect(
// {}, getters.getDiffFileDiscussions(localState, {}, {}, { discussions: [] })(diffFileMock)
// { discussions: [discussionMock] }, .length,
// )(diffFileMock).length, ).toEqual(0);
// ).toEqual(1); });
// }); });
// it('returns an empty array when no discussions are found in the given diff', () => {
// const diffFileMock = {
// fileHash: '9732849daca6ae818696d9575f5d1207d1a7f8bb',
// };
// expect(
// getters.getDiffFileDiscussions(
// localState,
// {},
// {},
// { discussions: () => ([]) },
// )(diffFileMock).length,
// ).toEqual(0);
// });
// });
}); });
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