From 8a1127834986e05fbd278b39349b9492fd6419fe Mon Sep 17 00:00:00 2001 From: Matheus Martins Date: Wed, 13 Jul 2016 23:53:55 -0300 Subject: [PATCH] Formulas with test --- test/annotationsTest.js | 8 +++--- test/fullTest.js | 6 ++--- test/mock/SpreadsheetApp/Cell.js | 18 ++++++++++--- test/mock/SpreadsheetApp/Formulas.js | 39 ++++++++++++++++++++++++++++ test/mock/SpreadsheetApp/Sheet.js | 36 ++++++++++++++++++------- 5 files changed, 88 insertions(+), 19 deletions(-) create mode 100644 test/mock/SpreadsheetApp/Formulas.js diff --git a/test/annotationsTest.js b/test/annotationsTest.js index 1e2a04c..65026e2 100644 --- a/test/annotationsTest.js +++ b/test/annotationsTest.js @@ -39,12 +39,12 @@ var jsonMock = { } }; -describe('QuickDrive functions', function () { - describe('get new sheet', function () { - it('it should return sheet with text replaced', function () { +describe('Annotations tests', function () { + describe('test specific annotations', function () { + it('all properties annotation', function () { var QuickDriveMock = new QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations)); var file = QuickDriveMock.processSheet(jsonMock); - var range = file.sheet.getRange(1,1,2,2).getCells(); + var range = file.sheet._processFormulas().getRange(1,1,2,2).getCells(); var firstCell = range[0][0]; var secondCell = range[0][1]; var thirdCell = range[1][0]; diff --git a/test/fullTest.js b/test/fullTest.js index 78904a3..a12659f 100644 --- a/test/fullTest.js +++ b/test/fullTest.js @@ -54,16 +54,16 @@ describe('QuickDrive functions', function () { var file = QuickDriveMock.processSheet(jsonMock); assert.equal(JSON.stringify([ ['My cool header', 'My random text', 'another random text', ''], - ['Matheus', 'Martins do Rego', 20, 'My user'], + ['Matheus', 'Martins do Rego', '20', 'My user'], ['12345-678', 'Campinas', 'São Paulo', 'Brasil'], - ['=SUM(10,30)', '','',''], + ['40', '','',''], ['Languages that he likes', '', '', ''], ['', 'Java', '', ''], ['', 'JavaScript', '', ''], ['', 'CSS', '', ''], ['', 'HTML', '', ''], ['', 'Python', '', 'text that will stay on last line'] - ]), JSON.stringify(file.sheet.getRange(1, 1, file.sheet.getMaxRows(), file.sheet.getMaxColumns()).getValues())); + ]), JSON.stringify(file.sheet._processFormulas().getRange(1, 1, file.sheet.getMaxRows(), file.sheet.getMaxColumns()).getValues())); }); }); }); diff --git a/test/mock/SpreadsheetApp/Cell.js b/test/mock/SpreadsheetApp/Cell.js index 8598256..d1ea12c 100644 --- a/test/mock/SpreadsheetApp/Cell.js +++ b/test/mock/SpreadsheetApp/Cell.js @@ -1,5 +1,6 @@ var Cell = function (firstValue) { var value = firstValue || '', + formula = '', backgroundColor = 'default', borderStyle = 'default', color = 'default', @@ -9,13 +10,24 @@ var Cell = function (firstValue) { var links = {}; this.getValue = function () { - return value; + return value + ''; + }; + this.getNumberValue = function() { + if (isNaN(value)) { + return 0; + } else { + return parseInt(value || 0); + } }; this.setValue = function (newValue) { value = newValue; }; - this.setFormula = function (newValue) { - value = newValue; + this.getFormula = function () { + return formula; + }; + this.setFormula = function (newFormula) { + value = ''; + formula = newFormula; }; this.getBackground = function () { return backgroundColor; diff --git a/test/mock/SpreadsheetApp/Formulas.js b/test/mock/SpreadsheetApp/Formulas.js new file mode 100644 index 0000000..9220b5b --- /dev/null +++ b/test/mock/SpreadsheetApp/Formulas.js @@ -0,0 +1,39 @@ +var Formulas = function (sheet) { + + return { + SUM: function (params) { + var sum = 0, + range = sheet.getRange(1,1,sheet.getMaxRows(),sheet.getMaxColumns()); + + if (params) { + var oldParams = params; + params = [] + for (var i =0;i