Skip to content

Commit

Permalink
Changing tests folder
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Aug 15, 2016
1 parent b5fa06c commit e2c82a2
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 164 deletions.
72 changes: 72 additions & 0 deletions test/spreadsheetTemplater/annotations/allProperties.js
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());
});
});
74 changes: 0 additions & 74 deletions test/spreadsheetTemplater/annotations/annotationsTest.js

This file was deleted.

41 changes: 41 additions & 0 deletions test/spreadsheetTemplater/annotations/forEach.js
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()));
});
});
51 changes: 51 additions & 0 deletions test/spreadsheetTemplater/annotations/mainTest.js
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.
53 changes: 53 additions & 0 deletions test/spreadsheetTemplater/mainTest.js
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');
86 changes: 0 additions & 86 deletions test/spreadsheetTemplater/test.js

This file was deleted.

5 changes: 1 addition & 4 deletions test/test.js
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');

0 comments on commit e2c82a2

Please sign in to comment.