Commit 98e31bf4 authored by Phil Hughes's avatar Phil Hughes

added mutation spec

parent 87be05bf
...@@ -93,16 +93,18 @@ export default { ...@@ -93,16 +93,18 @@ export default {
// To support legacy notes, should be very rare case. // To support legacy notes, should be very rare case.
if (note.individual_note && note.notes.length > 1) { if (note.individual_note && note.notes.length > 1) {
note.notes.forEach((n) => { note.notes.forEach((n) => {
const nn = Object.assign({}, note); notes.push({
nn.notes = [n]; // override notes array to only have one item to mimick individual_note ...note,
notes.push(nn); notes: [n], // override notes array to only have one item to mimick individual_note
});
}); });
} else { } else {
const nn = Object.assign({}, note);
const oldNote = utils.findNoteObjectById(state.notes, note.id); 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),
});
} }
}); });
......
...@@ -101,10 +101,21 @@ describe('Notes Store mutations', () => { ...@@ -101,10 +101,21 @@ describe('Notes Store mutations', () => {
const state = { const state = {
notes: [], 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[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);
}); });
}); });
......
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