-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5fa06c
commit e2c82a2
Showing
8 changed files
with
218 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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; | ||
var expect = chai.expect; | ||
|
||
var matrixMockWithReplaceAnnotations = [ | ||
[new Cell('{*this.propertyCell}'), new Cell('{*this.anotherPropertyCell}')], | ||
[new Cell('{*this.long.obj.reference.cell}'), new Cell('')] | ||
]; | ||
|
||
var jsonMock = { | ||
propertyCell: { | ||
value: 'The value', | ||
backgroundColor: 'rgb(100,100,100)', | ||
fontColor: '#F00', | ||
fontSize: 23, | ||
borderStyle: 'DOTTED', | ||
borderColor: '#00F' | ||
}, | ||
anotherPropertyCell: { | ||
value: 'my second value', | ||
fontColor: '#F00', | ||
borderColor: '#00F' | ||
}, | ||
long: { | ||
obj: { | ||
reference: { | ||
cell: { | ||
value: '', | ||
fontSize: 10, | ||
borderColor: '#00F' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
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._processFormulas().getRange(1,1,2,2).getCells(); | ||
var firstCell = range[0][0]; | ||
var secondCell = range[0][1]; | ||
var thirdCell = range[1][0]; | ||
assert.equal('The value', firstCell.getValue()); | ||
assert.equal('rgb(100,100,100)', firstCell.getBackground()); | ||
assert.equal('#F00', firstCell.getFontColor()); | ||
assert.equal(23, firstCell.getFontSize()); | ||
assert.equal('DOTTED', firstCell.getBorderStyle()); | ||
assert.equal('#00F', firstCell.getBorderColor()); | ||
|
||
assert.equal('my second value', secondCell.getValue()); | ||
assert.equal('default', secondCell.getBackground()); | ||
assert.equal('#F00', secondCell.getFontColor()); | ||
assert.equal('default', secondCell.getFontSize()); | ||
assert.equal('default', secondCell.getBorderStyle()); | ||
assert.equal('default', secondCell.getBorderColor()); | ||
|
||
assert.equal('', thirdCell.getValue()); | ||
assert.equal('default', thirdCell.getBackground()); | ||
assert.equal('default', thirdCell.getFontColor()); | ||
assert.equal(10, thirdCell.getFontSize()); | ||
assert.equal('default', thirdCell.getBorderStyle()); | ||
assert.equal('default', thirdCell.getBorderColor()); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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; | ||
var expect = chai.expect; | ||
|
||
var matrixMockWithReplaceAnnotations = [ | ||
[new Cell('Languages that he likes'), new Cell(''), new Cell(''), new Cell('')], | ||
[new Cell('{~this.curriculum.languagesThatLikes : languages}'), new Cell('{=languages}'), new Cell('{~}'), new Cell('text that will stay on last line')], | ||
[new Cell('-'), new Cell('-'), new Cell('-'), new Cell('-')], | ||
]; | ||
|
||
var jsonMock = { | ||
curriculum: { | ||
languagesThatLikes: [ | ||
'Java', | ||
'JavaScript', | ||
'CSS', | ||
'HTML', | ||
'Python' | ||
] | ||
} | ||
}; | ||
describe('forEach annotation', function () { | ||
it('it should return sheet forEach replaced', function () { | ||
var QuickDriveMock = new QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations)); | ||
var file = QuickDriveMock.processSheet(jsonMock); | ||
assert.equal(JSON.stringify([ | ||
['Languages that he likes', '', '', ''], | ||
['', 'Java', '', ''], | ||
['', 'JavaScript', '', ''], | ||
['', 'CSS', '', ''], | ||
['', 'HTML', '', ''], | ||
['', 'Python', '', 'text that will stay on last line'], | ||
['-', '-', '-', '-'] | ||
]), JSON.stringify(file.sheet._processFormulas().getRange(1, 1, file.sheet.getMaxRows(), file.sheet.getMaxColumns()).getValues())); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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('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('Testing annottations', function () { | ||
require('./allProperties.js'); | ||
require('./forEach.js'); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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('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('./annotations/mainTest.js'); | ||
require('./macro/mainTest.js'); | ||
require('./sheetMockTest.js'); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
require('./spreadsheetTemplater/test.js'); | ||
require('./spreadsheetTemplater/sheetMockTest.js'); | ||
require('./spreadsheetTemplater/macro/fullTest.js'); | ||
require('./spreadsheetTemplater/annotations/annotationsTest.js'); | ||
require('./spreadsheetTemplater/mainTest.js'); |