Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/notes/components')
-rw-r--r--spec/frontend/notes/components/multiline_comment_utils_spec.js64
-rw-r--r--spec/frontend/notes/components/note_actions_spec.js64
-rw-r--r--spec/frontend/notes/components/note_form_spec.js18
-rw-r--r--spec/frontend/notes/components/noteable_note_spec.js71
4 files changed, 174 insertions, 43 deletions
diff --git a/spec/frontend/notes/components/multiline_comment_utils_spec.js b/spec/frontend/notes/components/multiline_comment_utils_spec.js
index 261bfb106e7..af4394cc648 100644
--- a/spec/frontend/notes/components/multiline_comment_utils_spec.js
+++ b/spec/frontend/notes/components/multiline_comment_utils_spec.js
@@ -2,35 +2,23 @@ import {
getSymbol,
getStartLineNumber,
getEndLineNumber,
+ getCommentedLines,
} from '~/notes/components/multiline_comment_utils';
describe('Multiline comment utilities', () => {
- describe('getStartLineNumber', () => {
+ describe('get start & end line numbers', () => {
+ const lineRanges = ['old', 'new', null].map(type => ({
+ start: { new_line: 1, old_line: 1, type },
+ end: { new_line: 2, old_line: 2, type },
+ }));
it.each`
- lineCode | type | result
- ${'abcdef_1_1'} | ${'old'} | ${'-1'}
- ${'abcdef_1_1'} | ${'new'} | ${'+1'}
- ${'abcdef_1_1'} | ${null} | ${'1'}
- ${'abcdef'} | ${'new'} | ${''}
- ${'abcdef'} | ${'old'} | ${''}
- ${'abcdef'} | ${null} | ${''}
- `('returns line number', ({ lineCode, type, result }) => {
- expect(getStartLineNumber({ start_line_code: lineCode, start_line_type: type })).toEqual(
- result,
- );
- });
- });
- describe('getEndLineNumber', () => {
- it.each`
- lineCode | type | result
- ${'abcdef_1_1'} | ${'old'} | ${'-1'}
- ${'abcdef_1_1'} | ${'new'} | ${'+1'}
- ${'abcdef_1_1'} | ${null} | ${'1'}
- ${'abcdef'} | ${'new'} | ${''}
- ${'abcdef'} | ${'old'} | ${''}
- ${'abcdef'} | ${null} | ${''}
- `('returns line number', ({ lineCode, type, result }) => {
- expect(getEndLineNumber({ end_line_code: lineCode, end_line_type: type })).toEqual(result);
+ lineRange | start | end
+ ${lineRanges[0]} | ${'-1'} | ${'-2'}
+ ${lineRanges[1]} | ${'+1'} | ${'+2'}
+ ${lineRanges[2]} | ${'1'} | ${'2'}
+ `('returns line numbers `$start` & `$end`', ({ lineRange, start, end }) => {
+ expect(getStartLineNumber(lineRange)).toEqual(start);
+ expect(getEndLineNumber(lineRange)).toEqual(end);
});
});
describe('getSymbol', () => {
@@ -46,4 +34,30 @@ describe('Multiline comment utilities', () => {
expect(getSymbol(type)).toEqual(result);
});
});
+ describe('getCommentedLines', () => {
+ const diffLines = [{ line_code: '1' }, { line_code: '2' }, { line_code: '3' }];
+ it('returns a default object when `selectedCommentPosition` is not provided', () => {
+ expect(getCommentedLines(undefined, diffLines)).toEqual({ startLine: 4, endLine: 4 });
+ });
+ it('returns an object with startLine and endLine equal to 0', () => {
+ const selectedCommentPosition = {
+ start: { line_code: '1' },
+ end: { line_code: '1' },
+ };
+ expect(getCommentedLines(selectedCommentPosition, diffLines)).toEqual({
+ startLine: 0,
+ endLine: 0,
+ });
+ });
+ it('returns an object with startLine and endLine equal to 0 and 1', () => {
+ const selectedCommentPosition = {
+ start: { line_code: '1' },
+ end: { line_code: '2' },
+ };
+ expect(getCommentedLines(selectedCommentPosition, diffLines)).toEqual({
+ startLine: 0,
+ endLine: 1,
+ });
+ });
+ });
});
diff --git a/spec/frontend/notes/components/note_actions_spec.js b/spec/frontend/notes/components/note_actions_spec.js
index 220ac22d8eb..5cc56cdefae 100644
--- a/spec/frontend/notes/components/note_actions_spec.js
+++ b/spec/frontend/notes/components/note_actions_spec.js
@@ -127,25 +127,63 @@ describe('noteActions', () => {
.catch(done.fail);
});
- it('should be possible to assign or unassign the comment author', () => {
- wrapper = shallowMountNoteActions(props, {
- targetType: () => 'issue',
- });
-
+ it('should not be possible to assign or unassign the comment author in a merge request', () => {
const assignUserButton = wrapper.find('[data-testid="assign-user"]');
- expect(assignUserButton.exists()).toBe(true);
+ expect(assignUserButton.exists()).toBe(false);
+ });
+ });
+ });
- assignUserButton.trigger('click');
- axiosMock.onPut(`${TEST_HOST}/api/v4/projects/group/project/issues/1`).reply(() => {
- expect(actions.updateAssignees).toHaveBeenCalled();
- });
+ describe('when a user has access to edit an issue', () => {
+ const testButtonClickTriggersAction = () => {
+ axiosMock.onPut(`${TEST_HOST}/api/v4/projects/group/project/issues/1`).reply(() => {
+ expect(actions.updateAssignees).toHaveBeenCalled();
});
- it('should not be possible to assign or unassign the comment author in a merge request', () => {
- const assignUserButton = wrapper.find('[data-testid="assign-user"]');
- expect(assignUserButton.exists()).toBe(false);
+ const assignUserButton = wrapper.find('[data-testid="assign-user"]');
+ expect(assignUserButton.exists()).toBe(true);
+ assignUserButton.trigger('click');
+ };
+
+ beforeEach(() => {
+ wrapper = shallowMountNoteActions(props, {
+ targetType: () => 'issue',
});
+ store.state.noteableData = {
+ current_user: {
+ can_update: true,
+ },
+ };
+ store.state.userData = userDataMock;
});
+
+ afterEach(() => {
+ wrapper.destroy();
+ axiosMock.restore();
+ });
+
+ it('should be possible to assign the comment author', testButtonClickTriggersAction);
+ it('should be possible to unassign the comment author', testButtonClickTriggersAction);
+ });
+
+ describe('when a user does not have access to edit an issue', () => {
+ const testButtonDoesNotRender = () => {
+ const assignUserButton = wrapper.find('[data-testid="assign-user"]');
+ expect(assignUserButton.exists()).toBe(false);
+ };
+
+ beforeEach(() => {
+ wrapper = shallowMountNoteActions(props, {
+ targetType: () => 'issue',
+ });
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ it('should not be possible to assign the comment author', testButtonDoesNotRender);
+ it('should not be possible to unassign the comment author', testButtonDoesNotRender);
});
describe('user is not logged in', () => {
diff --git a/spec/frontend/notes/components/note_form_spec.js b/spec/frontend/notes/components/note_form_spec.js
index 15802841c57..a5b5204509e 100644
--- a/spec/frontend/notes/components/note_form_spec.js
+++ b/spec/frontend/notes/components/note_form_spec.js
@@ -245,6 +245,24 @@ describe('issue_note_form component', () => {
expect(updateDraft).toHaveBeenCalledWith(dummyAutosaveKey, dummyContent);
});
+
+ it('does not save draft when ctrl+enter is pressed', () => {
+ const options = {
+ noteBody: '',
+ autosaveKey: dummyAutosaveKey,
+ };
+
+ props = { ...props, ...options };
+ wrapper = createComponentWrapper();
+
+ wrapper.setData({ isSubmittingWithKeydown: true });
+
+ const textarea = wrapper.find('textarea');
+ textarea.setValue('some content');
+ textarea.trigger('keydown.enter', { metaKey: true });
+
+ expect(updateDraft).not.toHaveBeenCalled();
+ });
});
describe('with batch comments', () => {
diff --git a/spec/frontend/notes/components/noteable_note_spec.js b/spec/frontend/notes/components/noteable_note_spec.js
index aa3eaa97e20..fc238feb974 100644
--- a/spec/frontend/notes/components/noteable_note_spec.js
+++ b/spec/frontend/notes/components/noteable_note_spec.js
@@ -34,7 +34,13 @@ describe('issue_note', () => {
note,
},
localVue,
- stubs: ['note-header', 'user-avatar-link', 'note-actions', 'note-body'],
+ stubs: [
+ 'note-header',
+ 'user-avatar-link',
+ 'note-actions',
+ 'note-body',
+ 'multiline-comment-form',
+ ],
});
});
@@ -46,12 +52,30 @@ describe('issue_note', () => {
it('should render if has multiline comment', () => {
const position = {
line_range: {
- start_line_code: 'abc_1_1',
- end_line_code: 'abc_2_2',
+ start: {
+ line_code: 'abc_1_1',
+ type: null,
+ old_line: '1',
+ new_line: '1',
+ },
+ end: {
+ line_code: 'abc_2_2',
+ type: null,
+ old_line: '2',
+ new_line: '2',
+ },
},
};
+ const line = {
+ line_code: 'abc_1_1',
+ type: null,
+ old_line: '1',
+ new_line: '1',
+ };
wrapper.setProps({
note: { ...note, position },
+ discussionRoot: true,
+ line,
});
return wrapper.vm.$nextTick().then(() => {
@@ -59,15 +83,51 @@ describe('issue_note', () => {
});
});
+ it('should render multiline comment if editing discussion root', () => {
+ wrapper.setProps({ discussionRoot: true });
+ wrapper.vm.isEditing = true;
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(findMultilineComment().exists()).toBe(true);
+ });
+ });
+
+ it('should not render multiline comment form unless it is the discussion root', () => {
+ wrapper.setProps({ discussionRoot: false });
+ wrapper.vm.isEditing = true;
+
+ return wrapper.vm.$nextTick().then(() => {
+ expect(findMultilineComment().exists()).toBe(false);
+ });
+ });
+
it('should not render if has single line comment', () => {
const position = {
line_range: {
- start_line_code: 'abc_1_1',
- end_line_code: 'abc_1_1',
+ start: {
+ line_code: 'abc_1_1',
+ type: null,
+ old_line: '1',
+ new_line: '1',
+ },
+ end: {
+ line_code: 'abc_1_1',
+ type: null,
+ old_line: '1',
+ new_line: '1',
+ },
},
};
+ const line = {
+ line_code: 'abc_1_1',
+ type: null,
+ old_line: '1',
+ new_line: '1',
+ };
wrapper.setProps({
note: { ...note, position },
+ discussionRoot: true,
+ line,
});
return wrapper.vm.$nextTick().then(() => {
@@ -139,6 +199,7 @@ describe('issue_note', () => {
store.hotUpdate({
actions: {
updateNote() {},
+ setSelectedCommentPositionHover() {},
},
});
const noteBodyComponent = wrapper.find(NoteBody);