summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-03-10 18:17:01 +0000
committerPhil Hughes <me@iamphill.com>2018-03-10 18:17:01 +0000
commit98e31bf437c9934884bd8a7b5c311617757d0785 (patch)
tree2591fc876f0e76f8fd1289ee4821b76643dfa122
parent87be05bff037bf72e4496b2d3e266d0ba554d2c1 (diff)
downloadgitlab-ce-98e31bf437c9934884bd8a7b5c311617757d0785.tar.gz
added mutation spec
-rw-r--r--app/assets/javascripts/notes/stores/mutations.js14
-rw-r--r--spec/javascripts/notes/stores/mutation_spec.js15
2 files changed, 21 insertions, 8 deletions
diff --git a/app/assets/javascripts/notes/stores/mutations.js b/app/assets/javascripts/notes/stores/mutations.js
index aed0a44e808..949628a65c0 100644
--- a/app/assets/javascripts/notes/stores/mutations.js
+++ b/app/assets/javascripts/notes/stores/mutations.js
@@ -93,16 +93,18 @@ export default {
// To support legacy notes, should be very rare case.
if (note.individual_note && note.notes.length > 1) {
note.notes.forEach((n) => {
- const nn = Object.assign({}, note);
- nn.notes = [n]; // override notes array to only have one item to mimick individual_note
- notes.push(nn);
+ notes.push({
+ ...note,
+ notes: [n], // override notes array to only have one item to mimick individual_note
+ });
});
} else {
- const nn = Object.assign({}, note);
const oldNote = utils.findNoteObjectById(state.notes, note.id);
- nn.expanded = oldNote ? oldNote.expanded : note.expanded;
- notes.push(nn);
+ notes.push({
+ ...note,
+ expanded: (oldNote ? oldNote.expanded : note.expanded),
+ });
}
});
diff --git a/spec/javascripts/notes/stores/mutation_spec.js b/spec/javascripts/notes/stores/mutation_spec.js
index e4baefc5bfc..34884f8968f 100644
--- a/spec/javascripts/notes/stores/mutation_spec.js
+++ b/spec/javascripts/notes/stores/mutation_spec.js
@@ -101,10 +101,21 @@ describe('Notes Store mutations', () => {
const state = {
notes: [],
};
+ const legacyNote = {
+ id: 2,
+ individual_note: true,
+ notes: [{
+ note: '1',
+ }, {
+ note: '2',
+ }],
+ };
- mutations.SET_INITIAL_NOTES(state, [note]);
+ mutations.SET_INITIAL_NOTES(state, [note, legacyNote]);
expect(state.notes[0].id).toEqual(note.id);
- expect(state.notes.length).toEqual(1);
+ expect(state.notes[1].notes[0].note).toBe(legacyNote.notes[0].note);
+ expect(state.notes[2].notes[0].note).toBe(legacyNote.notes[1].note);
+ expect(state.notes.length).toEqual(3);
});
});