From 978c190e4ea27b420f9ca6ac4c5cf02b058d71a8 Mon Sep 17 00:00:00 2001 From: John Spiliotopoulos Date: Fri, 10 Jan 2020 17:28:16 +0200 Subject: [PATCH] Implement SS2 N/Record's removeline() --- modules/SS2/Record.js | 13 +++++++++++-- test/RecordTest.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/modules/SS2/Record.js b/modules/SS2/Record.js index 770053d..be61b37 100644 --- a/modules/SS2/Record.js +++ b/modules/SS2/Record.js @@ -235,7 +235,17 @@ module.exports = class Record { return this.sublists[sublistId][line][fieldId]; } - + + removeLine(options){ + const sublistId = options.sublistId; + const line = options.line; + + this.sublists[sublistId].splice(line, 1); + + return this; + } + + cancelLine(options) {} commitLine(options) {} findMatrixSublistLineWithValue(options){} @@ -260,7 +270,6 @@ module.exports = class Record { hasCurrentSublistSubrecord(options){} hasSubrecord(options){} removeCurrentSublistSubrecord(options){} - removeLine(options){} removeSublistSubrecord(options){} removeSubrecord(options){} setCurrentMatrixSublistValue(options){} diff --git a/test/RecordTest.js b/test/RecordTest.js index 96c9863..cfa9ed8 100644 --- a/test/RecordTest.js +++ b/test/RecordTest.js @@ -168,4 +168,49 @@ describe('Record', function() { }) + describe('removeLine()', function() { + const record = new Record({ + id: '1', + sublists: { + 'item': [ + {id: '1_0'}, + {id: '1_1'}, + {id: '1_2'}, + ], + }, + }); + + it("does not error if line doesn't exist", () => { + const options = { + sublistId: 'item', + line: 999, + }; + should.not.throw(() => record.removeLine(options)); + }); + + it("errors if sublistId is not on record", () => { + const options = { + sublistId: 'invalid', + line: 0, + }; + should.throw(() => record.removeLine(options)); + }); + + it("removes an existing line and returns the record", () => { + const options = { + sublistId: 'item', + line: 1, + }; + record.removeLine(options).sublists['item'].should.eql([{id: '1_0'}, {id: '1_2'}]); + }); + + it("returns the record regardless of operation success", () => { + const options = { + sublistId: 'item', + line: 999, + }; + + record.removeLine(options).should.be.a('Object'); + }); + }) })