Commit b6a340c9 authored by Thomas Randolph's avatar Thomas Randolph

Fix 2+ discussions on one line not working

Always create a lines object, even if only one line is provided.

Some instances of creating the note form won't have a range of lines
at construction.

If only a single line is provided, create the range of lines using
that one line as both the start and end of the range.

Changelog: fixed
parent e2fa66f3
......@@ -149,7 +149,11 @@ export default {
},
},
created() {
this.lines = { ...this.range };
if (this.range) {
this.lines = { ...this.range };
} else if (this.line) {
this.lines = { start: this.line, end: this.line };
}
},
mounted() {
if (this.isLoggedIn) {
......
......@@ -24,11 +24,14 @@ describe('DiffLineNoteForm', () => {
return shallowMount(DiffLineNoteForm, {
store,
propsData: {
diffFileHash: diffFile.file_hash,
diffLines,
line: diffLines[1],
range: { start: diffLines[0], end: diffLines[1] },
noteTargetLine: diffLines[1],
...{
diffFileHash: diffFile.file_hash,
diffLines,
line: diffLines[1],
range: { start: diffLines[0], end: diffLines[1] },
noteTargetLine: diffLines[1],
},
...(args.props || {}),
},
});
};
......@@ -119,6 +122,22 @@ describe('DiffLineNoteForm', () => {
});
});
describe('created', () => {
it('should use the provided `range` of lines', () => {
wrapper = createComponent();
expect(wrapper.vm.lines.start).toBe(diffLines[0]);
expect(wrapper.vm.lines.end).toBe(diffLines[1]);
});
it("should fill the internal `lines` data with the provided `line` if there's no provided `range", () => {
wrapper = createComponent({ props: { range: null } });
expect(wrapper.vm.lines.start).toBe(diffLines[1]);
expect(wrapper.vm.lines.end).toBe(diffLines[1]);
});
});
describe('mounted', () => {
it('should init autosave', () => {
const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2';
......
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