Skip to content

Commit

Permalink
Test changes and gapp
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusmr13 committed Jul 7, 2016
1 parent 37b8249 commit c93cc91
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 166 deletions.
4 changes: 4 additions & 0 deletions gapps.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "src",
"fileId": "1tVx2IimBlEy63KKegPL_-a7vd0OLyfCfyz6GIi15Q96XIlgN6Yhcpxdm"
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"url": "git@github.com:matheusmr13/quickdrive.git"
},
"scripts": {
"test": "mocha"
"test": "mocha",
"update": "gapps upload"
},
"dependencies": {
"chai": "^3.5.0",
"mocha": "^2.5.3"
"mocha": "^2.5.3",
"node-google-apps-script": "^1.1.5"
},
"devDependencies": {}
}
1 change: 0 additions & 1 deletion src/SheetsTemplater.gs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var QuickDrive = function (DriveApp, SpreadsheetApp, newConfig) {
var QuickDrive = {};

QuickDrive.annotationFunctions = {
REPLACE_TEXT: replaceValue,
FOR_EACH: processForEach,
Expand Down
11 changes: 11 additions & 0 deletions test/mock/Cell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var Cell = function (firstValue) {
var value = firstValue || "";
this.setValue = function (newValue) {
value = newValue;
};
this.getValue = function () {
return value;
};
};

exports.Cell = Cell;
28 changes: 28 additions & 0 deletions test/mock/DriveApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var File = require('./File.js').File;
var Folder = require('./Folder.js').Folder;

var DriveApp = function () {
return {
Access: {
ANYONE: 'ANYONE',
ANYONE_WITH_LINK: 'ANYONE_WITH_LINK',
DOMAIN: 'DOMAIN',
DOMAIN_WITH_LINK: 'DOMAIN_WITH_LINK',
PRIVATE: 'PRIVATE'
},
Permission: {
COMMENT: 'COMMENT',
EDIT: 'EDIT',
NONE: 'NONE',
OWNER: 'OWNER',
VIEW: 'VIEW'
},
getFileById: function (id) {
return new File(id);
},
getFolderById: function (id) {
return new Folder(id);
}
};
};
exports.DriveApp = DriveApp;
150 changes: 0 additions & 150 deletions test/mock/DriveAppMock.js

This file was deleted.

31 changes: 31 additions & 0 deletions test/mock/File.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var File = function (newId) {
var properties = {
id: newId || '',
name: ''
};

this.setSharing = function () {};
this.getId = function () {
return properties.id;
};
this.makeCopy = function (name, folder) {
var newFile = new File();
newFile._setProperties(properties);
newFile.setName(name);
folder.addFile(newFile);
return newFile;
};
this.getName = function () {
return properties.name;
};
this.setName = function (newName) {
properties.name = newName;
};
this._setProperties = function (newProperties) {
for (var propertie in newProperties) {
properties[propertie] = newProperties[propertie];
}
};
};

exports.File = File;
15 changes: 15 additions & 0 deletions test/mock/Folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var Folder = function (newId) {
var files = [],
id = newId || '';
this.getId = function () {
return id;
};
this.addFile = function (file) {
files.push(file);
};
this.getFiles = function () {
return files;
};
};

exports.Folder = Folder;
25 changes: 25 additions & 0 deletions test/mock/Range.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Range = function (myMatrix) {
var matrix = myMatrix || [
[]
];
this.getValues = function () {
var values = [];
for (var i = 0; i < matrix.length; i++) {
values[i] = [];
for (var j = 0; j < matrix[i].length; j++) {
values[i][j] = matrix[i][j].getValue();
}
}
return values;
};

this.setValue = function (value) {
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix.length; j++) {
matrix[i][j].setValue(value);
}
}
};
};

exports.Range = Range;
34 changes: 34 additions & 0 deletions test/mock/Sheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Range = require('./Range').Range;
var Sheet = function (myMatrix) {
var matrix = myMatrix || [
[]
];

this.getRange = function (row, col, lines, cols) {
lines = lines || 1;
cols = cols || 1;
if (!row || !col || row <= 0 || col <= 0 || lines > matrix.length || cols > matrix[0].length) {
throw new Error('Invalid params to range.');
}
var newMatrix = [
[]
];
for (var i = 0; i < lines; i++) {
newMatrix[i] = [];
for (var j = 0; j < cols; j++) {
newMatrix[i][j] = matrix[i + row - 1][j + col - 1];
}
}
return new Range(newMatrix);
};

this.getMaxRows = function () {
return matrix.length;
};

this.getMaxColumns = function () {
return matrix[0].length;
};
};

exports.Sheet = Sheet;
9 changes: 9 additions & 0 deletions test/mock/Spreadsheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var Sheet = require('./Sheet.js').Sheet
var Spreadsheet = function (mock) {
var sheets = [new Sheet(mock)];

this.getSheets = function () {
return sheets;
};
};
exports.Spreadsheet = Spreadsheet;
10 changes: 10 additions & 0 deletions test/mock/SpreadsheetApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var Spreadsheet = require('./Spreadsheet.js').Spreadsheet;
var SpreadsheetApp = function (mock) {
return {
open: function (file) {
return new Spreadsheet(mock || file);
}
}
};

exports.SpreadsheetApp = SpreadsheetApp;
1 change: 0 additions & 1 deletion test/mock/docsMock.js

This file was deleted.

5 changes: 2 additions & 3 deletions test/sheetMockTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var mock = require('./mock/DriveAppMock.js').DriveAppMock;
var SpreadsheetApp = mock.SpreadsheetApp();
var DriveApp = mock.DriveApp();
var SpreadsheetApp = require('./mock/Spreadsheet.js').Spreadsheet();
var DriveApp = require('./mock/DriveApp.js').DriveApp();
var assert = require('chai').assert;

describe('DriveApp sheet mock test', function () {
Expand Down
17 changes: 8 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
evar DriveAppMock = require('./mock/DriveAppMock.js').DriveAppMock;
var DriveApp = DriveAppMock.DriveApp;
var SpreadsheetApp = DriveAppMock.SpreadsheetApp;
var DriveApp = require('./mock/DriveApp.js').DriveApp;
var Cell = require('./mock/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');
Expand Down Expand Up @@ -76,21 +76,20 @@ describe('QuickDrive functions', function () {
});

var matrixMock = [
['asd', 'koko', '{=this.my_header}', 'my left header'],
['asd', 'koko', '{=this.my_header}', 'my left header'],
['asd', 'koko', '{=this.my_header}', 'my left header']
[new Cell('asd'), new Cell('koko'), new Cell('{=this.my_header}'), new Cell('my left header')],
[new Cell('asd'), new Cell('koko'), new Cell('{=this.my_header}'), new Cell('my left header')],
[new Cell('asd'), new Cell('koko'), new Cell('{=this.my_header}'), new Cell('my left header')]
];

var jsonMock = {
this: {
my_header: 'header title'
}
my_header: 'header title'
};
describe('QuickDrive functions', function () {
describe('get new sheet', function () {
it('it should return sheet with text replaced', function () {
var QuickDriveMock = QuickDriveConstructor(DriveApp(), SpreadsheetApp(matrixMock));
var file = QuickDriveMock.processSheet(jsonMock);
console.info(file.sheet.getRange(1,1,3,4).getValues());
});
});
});

0 comments on commit c93cc91

Please sign in to comment.