Skip to content

Commit

Permalink
Fixing properties annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Jul 15, 2016
1 parent 8a11278 commit fdad07a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 46 deletions.
15 changes: 6 additions & 9 deletions src/SheetsTemplater.gs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,14 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
if (cellProperties.backgroundColor) {
range.setBackground(cellProperties.backgroundColor);
}
if (cellProperties.textSize) {
range.setTextSize(cellProperties.textSize);
if (cellProperties.fontSize) {
range.setFontSize(cellProperties.fontSize);
}
if (cellProperties.color) {
range.setColor(cellProperties.color);
if (cellProperties.fontColor) {
range.setFontColor(cellProperties.fontColor);
}
if (cellProperties.borderStyle) {
range.setBorderStyle(cellProperties.borderStyle);
}
if (cellProperties.borderColor) {
range.setBorderColor(cellProperties.borderColor);
if (cellProperties.borderStyle && cellProperties.borderColor) {
range.setBorder(true, true, true, true, cellProperties.borderColor, SpreadsheetApp.BorderStyle[cellProperties.borderStyle]);
}
};

Expand Down
29 changes: 15 additions & 14 deletions test/annotationsTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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 QuickDrive = QuickDriveConstructor(DriveApp(), SpreadsheetApp());
var QuickDrive = QuickDriveConstructor(DriveApp(), SpreadsheetApp(), new Range());
var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;
Expand All @@ -16,22 +17,22 @@ var jsonMock = {
propertyCell: {
value: 'The value',
backgroundColor: 'rgb(100,100,100)',
color: '#F00',
textSize: 23,
fontColor: '#F00',
fontSize: 23,
borderStyle: 'DOTTED',
borderColor: '#00F',
borderColor: '#00F'
},
anotherPropertyCell: {
value: 'my second value',
color: '#F00',
fontColor: '#F00',
borderColor: '#00F'
},
long: {
obj: {
reference: {
cell: {
value: '',
textSize: 10,
fontSize: 10,
borderColor: '#00F'
}
}
Expand All @@ -50,24 +51,24 @@ describe('Annotations tests', function () {
var thirdCell = range[1][0];
assert.equal('The value', firstCell.getValue());
assert.equal('rgb(100,100,100)', firstCell.getBackground());
assert.equal('#F00', firstCell.getColor());
assert.equal(23, firstCell.getTextSize());
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.getColor());
assert.equal('default', secondCell.getTextSize());
assert.equal('#F00', secondCell.getFontColor());
assert.equal('default', secondCell.getFontSize());
assert.equal('default', secondCell.getBorderStyle());
assert.equal('#00F', secondCell.getBorderColor());
assert.equal('default', secondCell.getBorderColor());

assert.equal('', thirdCell.getValue());
assert.equal('default', thirdCell.getBackground());
assert.equal('default', thirdCell.getColor());
assert.equal(10, thirdCell.getTextSize());
assert.equal('default', thirdCell.getFontColor());
assert.equal(10, thirdCell.getFontSize());
assert.equal('default', thirdCell.getBorderStyle());
assert.equal('#00F', thirdCell.getBorderColor());
assert.equal('default', thirdCell.getBorderColor());
});
});
});
20 changes: 10 additions & 10 deletions test/mock/SpreadsheetApp/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var Cell = function (firstValue) {
formula = '',
backgroundColor = 'default',
borderStyle = 'default',
color = 'default',
textSize = 'default',
fontColor = 'default',
fontSize = 'default',
borderColor = 'default';

var links = {};
Expand Down Expand Up @@ -47,17 +47,17 @@ var Cell = function (firstValue) {
this.setBorderStyle = function (newBorderStyle) {
borderStyle = newBorderStyle;
};
this.getColor = function () {
return color;
this.getFontColor = function () {
return fontColor;
};
this.setColor = function (newColor) {
color = newColor;
this.setFontColor = function (newFontColor) {
fontColor = newFontColor;
};
this.getTextSize = function () {
return textSize;
this.getFontSize = function () {
return fontSize;
};
this.setTextSize = function (newTextSize) {
textSize = newTextSize;
this.setFontSize = function (newFontSize) {
fontSize = newFontSize;
};
this._configureLinks = function (newLinks) {
links = newLinks;
Expand Down
22 changes: 10 additions & 12 deletions test/mock/SpreadsheetApp/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var Range = function (myMatrix) {
return values;
};

this._getCells = function() {
this._getCells = function () {
return matrix;
};
this.copyTo = function (anotherRange) {
Expand All @@ -38,27 +38,25 @@ var Range = function (myMatrix) {
this.setFormula = function (formula) {
setSomeValue(formula, 'Formula');
};
this.setTextSize = function (textSize) {
setSomeValue(textSize, 'TextSize');
this.setFontSize = function (newFontSize) {
setSomeValue(newFontSize, 'FontSize');
};
this.setColor = function (color) {
setSomeValue(color, 'Color');
this.setFontColor = function (color) {
setSomeValue(color, 'FontColor');
};
this.setBorderStyle = function (borderStyle) {
setSomeValue(borderStyle, 'BorderStyle');
this.setBorder = function (top, left, bottom, right, color, style) {
setSomeValue(color, 'BorderColor');
setSomeValue(style, 'BorderStyle');
};
this.setBorderColor = function (borderColor) {
setSomeValue(borderColor, 'BorderColor');
};
var setSomeValue = function(value, propertie) {
var setSomeValue = function (value, propertie) {
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix[0].length; j++) {
matrix[i][j]['set' + propertie](value);
}
}
};

this.getCells = function() {
this.getCells = function () {
return matrix;
};
};
Expand Down
1 change: 0 additions & 1 deletion test/mock/SpreadsheetApp/Sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var Sheet = function (myMatrix) {
formula = parts[0].substring(1),
params = parts[1].substring(0, parts[1].length - 1).split(','),
formulaFunction = formulas[formula];
console.info(parts);
if (!formulaFunction) {
throw new Error('Not testable function: ' + formula);
} else {
Expand Down

0 comments on commit fdad07a

Please sign in to comment.