diff --git a/src/SheetsTemplater.js b/src/SheetsTemplater.js index a7bbfcd..abd6c0d 100644 --- a/src/SheetsTemplater.js +++ b/src/SheetsTemplater.js @@ -16,7 +16,6 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) { '#': annotationFunctions.INSERT_FORMULA, '*': annotationFunctions.COMPLETE_CELL, '+': annotationFunctions.SET_MATRIX - }; var _config = { folderId: '0B8cJhvYlR-sCcGR4d3VYWGZaYWM', diff --git a/test/annotationsTest.js b/test/spreadsheetTemplater/annotations/annotationsTest.js similarity index 86% rename from test/annotationsTest.js rename to test/spreadsheetTemplater/annotations/annotationsTest.js index 79a09f4..7781409 100644 --- a/test/annotationsTest.js +++ b/test/spreadsheetTemplater/annotations/annotationsTest.js @@ -1,8 +1,8 @@ -var DriveApp = require('./mock/DriveApp.js').DriveApp; -var Cell = require('./mock/SpreadsheetApp/Cell.js').Cell; -var Range = require('./mock/SpreadsheetApp/Range.js').Range; -var SpreadsheetApp = require('./mock/SpreadsheetApp.js').SpreadsheetApp; -var QuickDriveConstructor = require('../src/SheetsTemplater.gs').QuickDrive; +var DriveApp = require('./../../mock/DriveApp.js').DriveApp; +var Cell = require('./../../mock/SpreadsheetApp/Cell.js').Cell; +var Range = require('./../../mock/SpreadsheetApp/Range.js').Range; +var SpreadsheetApp = require('./../../mock/SpreadsheetApp.js').SpreadsheetApp; +var QuickDriveConstructor = require('../../../src/SheetsTemplater.js').QuickDrive; var QuickDrive = QuickDriveConstructor(DriveApp(), SpreadsheetApp(), new Range()); var chai = require('chai'); var assert = chai.assert; diff --git a/test/fullTest.js b/test/spreadsheetTemplater/macro/fullTest.js similarity index 88% rename from test/fullTest.js rename to test/spreadsheetTemplater/macro/fullTest.js index a12659f..cc7e3ba 100644 --- a/test/fullTest.js +++ b/test/spreadsheetTemplater/macro/fullTest.js @@ -1,7 +1,7 @@ -var DriveApp = require('./mock/DriveApp.js').DriveApp; -var Cell = require('./mock/SpreadsheetApp/Cell.js').Cell; -var SpreadsheetApp = require('./mock/SpreadsheetApp.js').SpreadsheetApp; -var QuickDriveConstructor = require('../src/SheetsTemplater.gs').QuickDrive; +var DriveApp = require('./../../mock/DriveApp.js').DriveApp; +var Cell = require('./../../mock/SpreadsheetApp/Cell.js').Cell; +var SpreadsheetApp = require('./../../mock/SpreadsheetApp.js').SpreadsheetApp; +var QuickDriveConstructor = require('../../../src/SheetsTemplater.js').QuickDrive; var QuickDrive = QuickDriveConstructor(DriveApp(), SpreadsheetApp()); var chai = require('chai'); var assert = chai.assert; diff --git a/test/sheetMockTest.js b/test/spreadsheetTemplater/sheetMockTest.js similarity index 85% rename from test/sheetMockTest.js rename to test/spreadsheetTemplater/sheetMockTest.js index 59b16f8..93331e0 100644 --- a/test/sheetMockTest.js +++ b/test/spreadsheetTemplater/sheetMockTest.js @@ -1,5 +1,5 @@ -var SpreadsheetApp = require('./mock/SpreadsheetApp.js').SpreadsheetApp(); -var DriveApp = require('./mock/DriveApp.js').DriveApp(); +var SpreadsheetApp = require('./../mock/SpreadsheetApp.js').SpreadsheetApp(); +var DriveApp = require('./../mock/DriveApp.js').DriveApp(); var assert = require('chai').assert; describe('DriveApp sheet mock test', function () { diff --git a/test/spreadsheetTemplater/test.js b/test/spreadsheetTemplater/test.js new file mode 100644 index 0000000..1ad8f75 --- /dev/null +++ b/test/spreadsheetTemplater/test.js @@ -0,0 +1,86 @@ +var DriveApp = require('./../mock/DriveApp.js').DriveApp; +var Cell = require('./../mock/SpreadsheetApp/Cell.js').Cell; +var SpreadsheetApp = require('./../mock/SpreadsheetApp.js').SpreadsheetApp; +var QuickDriveConstructor = require('./../../src/SheetsTemplater.js').QuickDrive; +var QuickDrive = new QuickDriveConstructor(DriveApp(), SpreadsheetApp()); +var chai = require('chai'); +var assert = chai.assert; +var expect = chai.expect; + +describe('QuickDrive functions', function () { + describe('getAnnotationType', function () { + it('it should return none annotation, just simple text', function () { + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('==simple text with no annotation==')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{another simple')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('another one}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{with no action}')); + }); + it('it should return none annotation (invalid annotation present)', function () { + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=@foo.bar}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=@bar}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foo..bar}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=.foo.bar}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=.foobar}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foobar.}')); + assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foo@bar}')); + }); + it('it should return simple replace text', function () { + assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo.bar}')); + assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo}')); + assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo.bar.text.with.many.properties}')); + }); + it('it should return for each annotation', function () { + assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~mylist}')); + assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~foo.myList}')); + assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~foo.bar.with.many.properties.myList}')); + }); + it('it should insert formula annotation', function () { + assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#myFormula}')); + assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#my.formula}')); + assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#foo.bar.with.many.properties.myList}')); + }); + it('it should set matrix annotation', function () { + assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+myMatrix}')); + assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+my.matrix}')); + assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+foo.bar.with.many.properties.myMatrix}')); + }); + }); + describe('validateConfig', function () { + var createQuickDriveWithConfig = function (propertie, value) { + var obj = {}; + obj[propertie] = value; + return function () { + QuickDriveConstructor(DriveApp(), SpreadsheetApp(), obj); + }; + }; + it('it should have default config with no error', function () { + QuickDriveConstructor(DriveApp(), QuickDrive._config); + }); + it('it should validate fileId', function () { + assert.throws(createQuickDriveWithConfig('templateId', 'myshortid'), Error, 'invalid-file-id'); + assert.throws(createQuickDriveWithConfig('templateId', 2313123), Error, 'invalid-file-id'); + assert.throws(createQuickDriveWithConfig('templateId', true), Error, 'invalid-file-id'); + createQuickDriveWithConfig('fileId', '123456789012345678901234567890123456789012345')(); + }); + it('it should validate folderId', function () { + assert.throws(createQuickDriveWithConfig('folderId', 'myshortid'), Error, 'invalid-folder-id'); + assert.throws(createQuickDriveWithConfig('folderId', 2313123), Error, 'invalid-folder-id'); + assert.throws(createQuickDriveWithConfig('folderId', true), Error, 'invalid-folder-id'); + createQuickDriveWithConfig('folderId', '123456789012345678')(); + }); + it('it should validate file name', function () { + assert.throws(createQuickDriveWithConfig('newDocumentName', 2313123), Error, 'invalid-file-name'); + assert.throws(createQuickDriveWithConfig('newDocumentName', true), Error, 'invalid-file-name'); + createQuickDriveWithConfig('newDocumentName', 'my new name')(); + }); + it('it should validate stripe color', function () { + assert.throws(createQuickDriveWithConfig('stripeColor', 2313123), Error, 'invalid-stripe-color'); + assert.throws(createQuickDriveWithConfig('stripeColor', true), Error, 'invalid-stripe-color'); + assert.throws(createQuickDriveWithConfig('stripeColor', '#3333'), Error, 'invalid-stripe-color'); + assert.throws(createQuickDriveWithConfig('stripeColor', '3333'), Error, 'invalid-stripe-color'); + createQuickDriveWithConfig('stripeColor', '#333333')(); + createQuickDriveWithConfig('stripeColor', '#333')(); + createQuickDriveWithConfig('stripeColor', 'rgb(123,123,123)')(); + }); + }); +}); diff --git a/test/test.js b/test/test.js index 9fe5c97..8ad354a 100644 --- a/test/test.js +++ b/test/test.js @@ -1,86 +1,4 @@ -var DriveApp = require('./mock/DriveApp.js').DriveApp; -var Cell = require('./mock/SpreadsheetApp/Cell.js').Cell; -var SpreadsheetApp = require('./mock/SpreadsheetApp.js').SpreadsheetApp; -var QuickDriveConstructor = require('../src/SheetsTemplater.gs').QuickDrive; -var QuickDrive = new QuickDriveConstructor(DriveApp(), SpreadsheetApp()); -var chai = require('chai'); -var assert = chai.assert; -var expect = chai.expect; - -describe('QuickDrive functions', function () { - describe('getAnnotationType', function () { - it('it should return none annotation, just simple text', function () { - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('==simple text with no annotation==')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{another simple')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('another one}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{with no action}')); - }); - it('it should return none annotation (invalid annotation present)', function () { - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=@foo.bar}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=@bar}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foo..bar}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=.foo.bar}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=.foobar}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foobar.}')); - assert.equal(QuickDrive.annotationFunctions.NONE, QuickDrive.getAnnotationType('{=foo@bar}')); - }); - it('it should return simple replace text', function () { - assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo.bar}')); - assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo}')); - assert.equal(QuickDrive.annotationFunctions.REPLACE_TEXT, QuickDrive.getAnnotationType('{=foo.bar.text.with.many.properties}')); - }); - it('it should return for each annotation', function () { - assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~mylist}')); - assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~foo.myList}')); - assert.equal(QuickDrive.annotationFunctions.FOR_EACH, QuickDrive.getAnnotationType('{~foo.bar.with.many.properties.myList}')); - }); - it('it should insert formula annotation', function () { - assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#myFormula}')); - assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#my.formula}')); - assert.equal(QuickDrive.annotationFunctions.INSERT_FORMULA, QuickDrive.getAnnotationType('{#foo.bar.with.many.properties.myList}')); - }); - it('it should set matrix annotation', function () { - assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+myMatrix}')); - assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+my.matrix}')); - assert.equal(QuickDrive.annotationFunctions.SET_MATRIX, QuickDrive.getAnnotationType('{+foo.bar.with.many.properties.myMatrix}')); - }); - }); - describe('validateConfig', function () { - var createQuickDriveWithConfig = function (propertie, value) { - var obj = {}; - obj[propertie] = value; - return function () { - QuickDriveConstructor(DriveApp(), SpreadsheetApp(), obj); - }; - }; - it('it should have default config with no error', function () { - QuickDriveConstructor(DriveApp(), QuickDrive._config); - }); - it('it should validate fileId', function () { - assert.throws(createQuickDriveWithConfig('templateId', 'myshortid'), Error, 'invalid-file-id'); - assert.throws(createQuickDriveWithConfig('templateId', 2313123), Error, 'invalid-file-id'); - assert.throws(createQuickDriveWithConfig('templateId', true), Error, 'invalid-file-id'); - createQuickDriveWithConfig('fileId', '123456789012345678901234567890123456789012345')(); - }); - it('it should validate folderId', function () { - assert.throws(createQuickDriveWithConfig('folderId', 'myshortid'), Error, 'invalid-folder-id'); - assert.throws(createQuickDriveWithConfig('folderId', 2313123), Error, 'invalid-folder-id'); - assert.throws(createQuickDriveWithConfig('folderId', true), Error, 'invalid-folder-id'); - createQuickDriveWithConfig('folderId', '123456789012345678')(); - }); - it('it should validate file name', function () { - assert.throws(createQuickDriveWithConfig('newDocumentName', 2313123), Error, 'invalid-file-name'); - assert.throws(createQuickDriveWithConfig('newDocumentName', true), Error, 'invalid-file-name'); - createQuickDriveWithConfig('newDocumentName', 'my new name')(); - }); - it('it should validate stripe color', function () { - assert.throws(createQuickDriveWithConfig('stripeColor', 2313123), Error, 'invalid-stripe-color'); - assert.throws(createQuickDriveWithConfig('stripeColor', true), Error, 'invalid-stripe-color'); - assert.throws(createQuickDriveWithConfig('stripeColor', '#3333'), Error, 'invalid-stripe-color'); - assert.throws(createQuickDriveWithConfig('stripeColor', '3333'), Error, 'invalid-stripe-color'); - createQuickDriveWithConfig('stripeColor', '#333333')(); - createQuickDriveWithConfig('stripeColor', '#333')(); - createQuickDriveWithConfig('stripeColor', 'rgb(123,123,123)')(); - }); - }); -}); +require('./spreadsheetTemplater/test.js'); +require('./spreadsheetTemplater/sheetMockTest.js'); +require('./spreadsheetTemplater/macro/fullTest.js'); +require('./spreadsheetTemplater/annotations/annotationsTest.js'); \ No newline at end of file