Skip to content

Commit

Permalink
New tests and insert properties
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Jul 14, 2016
1 parent e40c109 commit bbd52c5
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 59 deletions.
2 changes: 2 additions & 0 deletions src/SheetsTemplater.gs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
properties.i = i - 1;
properties.j = j - 1;
properties.json[entityName] = array[index];
console.info(properties.json[entityName]);
QuickDrive.processCell(properties);

}
Expand All @@ -175,6 +176,7 @@ var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
};

QuickDrive.processCell = function (properties) {
console.info(' ' + properties.i + ' ' +properties.j);
var cellValue = properties.values[properties.i][properties.j];
var annotationFunction = QuickDrive.getAnnotationType(cellValue)(properties);
};
Expand Down
72 changes: 72 additions & 0 deletions test/annotationsTest.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 SpreadsheetApp = require('./mock/SpreadsheetApp.js').SpreadsheetApp;
var QuickDriveConstructor = require('../src/SheetsTemplater.gs').QuickDrive;
var QuickDrive = QuickDriveConstructor(DriveApp(), SpreadsheetApp());
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)',
color: '#F00',
textSize: 23,
borderStyle: 'DOTTED',
borderColor: '#00F',
},
anotherPropertyCell: {
value: 'my second value',
color: '#F00',
borderColor: '#00F'
},
long: {
obj: {
reference: {
cell: {
value: '',
textSize: 10,
borderColor: '#00F'
}
}
}
}
};
describe('QuickDrive functions', function () {
describe('get new sheet', function () {
it('it should return sheet with text replaced', function () {
var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations));
var file = QuickDriveMock.processSheet(jsonMock);
var range = file.sheet.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.getBackgroundColor());
assert.equal('#F00', firstCell.getColor());
assert.equal(23, firstCell.getTextSize());
assert.equal('DOTTED', firstCell.getBorderStyle());
assert.equal('#00F', firstCell.getBorderColor());

assert.equal('my second value', secondCell.getValue());
assert.equal('default', secondCell.getBackgroundColor());
assert.equal('#F00', secondCell.getColor());
assert.equal('default', secondCell.getTextSize());
assert.equal('SOLID', secondCell.getBorderStyle());
assert.equal('#00F', secondCell.getBorderColor());

assert.equal('', thirdCell.getValue());
assert.equal('default', thirdCell.getBackgroundColor());
assert.equal('default', thirdCell.getColor());
assert.equal(10, thirdCell.getTextSize());
assert.equal('SOLID', thirdCell.getBorderStyle());
assert.equal('#00F', thirdCell.getBorderColor());
});
});
});
66 changes: 66 additions & 0 deletions test/fullTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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 = QuickDriveConstructor(DriveApp(), SpreadsheetApp());
var chai = require('chai');
var assert = chai.assert;
var expect = chai.expect;

var matrixMockWithReplaceAnnotations = [
[new Cell('{=this.reportHeader}'), new Cell('My random text'), new Cell('another random text'), new Cell('')],
[new Cell('{=this.user.name}'), new Cell('{=this.user.lastName}'), new Cell('{=this.user.age}'), new Cell('My user')],
[new Cell('{=this.user.address.cep}'), new Cell('{=this.user.address.city.name}'), new Cell('{=this.user.address.city.state.name}'), new Cell('{=this.user.address.city.state.country.name}')],
[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')]
];

var jsonMock = {
reportHeader: 'My cool header',
user: {
name: 'Matheus',
lastName: 'Martins do Rego',
age: 20,
address: {
cep: '12345-678',
city: {
name: 'Campinas',
state: {
name: 'São Paulo',
country: {
name: 'Brasil'
}
}
}
}
},
curriculum: {
yearsWorking: 3,
languagesThatLikes: [
'Java',
'JavaScript',
'CSS',
'HTML',
'Python'
]
}
};
describe('QuickDrive functions', function () {
describe('get new sheet', function () {
it('it should return sheet with text replaced', function () {
var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations));
var file = QuickDriveMock.processSheet(jsonMock);
assert.equal(JSON.stringify([
['My cool header', 'My random text', 'another random text', ''],
['Matheus', 'Martins do Rego', 20, 'My user'],
['12345-678', 'Campinas', 'São Paulo', 'Brasil'],
['Languages that he likes', '', '', ''],
['', 'Java', '', ''],
['', 'JavaScript', '', ''],
['', 'CSS', '', ''],
['', 'HTML', '', ''],
['', 'Python', '', 'text that will stay on last line']
]), JSON.stringify(file.sheet.getRange(1, 1, file.sheet.getMaxRows(), file.sheet.getMaxColumns()).getValues()));
});
});
});
4 changes: 4 additions & 0 deletions test/mock/SpreadsheetApp/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var Range = function (myMatrix) {
}
}
};

this.getCells = function() {
return matrix;
};
};

exports.Range = Range;
2 changes: 1 addition & 1 deletion test/mock/SpreadsheetApp/Sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Sheet = function (myMatrix) {
});
}
}

};

setupMatrixLinks();
Expand Down Expand Up @@ -67,7 +68,6 @@ var Sheet = function (myMatrix) {
// console.info(newMatrix.length);
// console.info(newMatrix[0].length);
matrix = newMatrix;
setupMatrixLinks();
};

this.getMaxRows = function () {
Expand Down
58 changes: 0 additions & 58 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,61 +74,3 @@ describe('QuickDrive functions', function () {
});
});
});

var matrixMockWithReplaceAnnotations = [
[new Cell('{=this.reportHeader}'), new Cell('My random text'), new Cell('another random text'), new Cell('')],
[new Cell('{=this.user.name}'), new Cell('{=this.user.lastName}'), new Cell('{=this.user.age}'), new Cell('My user')],
[new Cell('{=this.user.address.cep}'), new Cell('{=this.user.address.city.name}'), new Cell('{=this.user.address.city.state.name}'), new Cell('{=this.user.address.city.state.country.name}')],
[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')]
];

var jsonMock = {
reportHeader: 'My cool header',
user: {
name: 'Matheus',
lastName: 'Martins do Rego',
age: 20,
address: {
cep: '12345-678',
city: {
name: 'Campinas',
state: {
name: 'São Paulo',
country: {
name: 'Brasil'
}
}
}
}
},
curriculum: {
yearsWorking: 3,
languagesThatLikes: [
'Java',
'JavaScript',
'CSS',
'HTML',
'Python'
]
}
};
describe('QuickDrive functions', function () {
describe('get new sheet', function () {
it('it should return sheet with text replaced', function () {
var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMockWithReplaceAnnotations));
var file = QuickDriveMock.processSheet(jsonMock);
assert.equal(JSON.stringify([
['My cool header', 'My random text', 'another random text', ''],
['Matheus', 'Martins do Rego', 20, 'My user'],
['12345-678', 'Campinas', 'São Paulo', 'Brasil'],
['Languages that he likes', '', '', ''],
['', 'Java', '', ''],
['', 'JavaScript', '', ''],
['', 'CSS', '', ''],
['', 'HTML', '', ''],
['', 'Python', '', 'text that will stay on last line']
]), JSON.stringify(file.sheet.getRange(1, 1, file.sheet.getMaxRows(), file.sheet.getMaxColumns()).getValues()));
});
});
});

0 comments on commit bbd52c5

Please sign in to comment.