Skip to content

Commit

Permalink
Changing dir
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Aug 15, 2016
1 parent 28fb82e commit b5fa06c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 98 deletions.
1 change: 0 additions & 1 deletion src/SheetsTemplater.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
'#': annotationFunctions.INSERT_FORMULA,
'*': annotationFunctions.COMPLETE_CELL,
'+': annotationFunctions.SET_MATRIX

};
var _config = {
folderId: '0B8cJhvYlR-sCcGR4d3VYWGZaYWM',
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down
86 changes: 86 additions & 0 deletions test/spreadsheetTemplater/test.js
Original file line number Diff line number Diff line change
@@ -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)')();
});
});
});
90 changes: 4 additions & 86 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit b5fa06c

Please sign in to comment.