Drive refactoring

This commit is contained in:
yflory
2017-06-08 17:52:00 +02:00
parent df2b00122a
commit 1c2ea04f11
7 changed files with 570 additions and 542 deletions

View File

@@ -7,12 +7,74 @@ define([
var href1 = "/pad/#/1/edit/a798u+miu2tg5b-QaP9SvA/UIPoGUPewZscBUFhNIi+eBBM/";
var href2 = "/poll/#/1/edit/uFJTXjQUEwV2bl-y3cKVpP/LJ-4qPnpR5iY0HVdwLcnjLsx/";
var href3 = "/code/#/1/edit/R1kZC1mY9khSsrLCyJT+CA/jtQrCxbTiqQJ4HyUxbFBnmG8/";
var href3 = "/code/#/1/view/eRS+YPTTASNqjRbgrznAdQ/2OyNsvfYw7ZwLg6wkJuCaGBzOZvxNLra9n7GN848Zic/";
var href4 = "/slide/#/1/edit/R2bZC1mY9khSsrLCyJT+CA/mlQrCxbTiqQJ4HyUxbFBnmG8/";
var href5 = "/whiteboard/#/1/edit/k8bZC1mY9khSsrLCyJT+CA/moQrCxbTiqQJ4HyUxbFBnmG8/";
var id1 = 1000000000001;
var id2 = 1000000000002;
var id3 = 1000000000003;
var id4 = 1000000000004;
var example = {
"root": {
"Folder": {
"Sub": {}
},
"Folder2": {
"rdmStrFile1": id1
}
},
"template": [id2],
"trash": {
"DeletedF": [{
"path": ["root"],
"element": {}
},{
"path": ["root"],
"element": {
"rdmStrFile3": id3
}
}],
"Title4": [{
"path": ["root", "Folder"],
"element": id4
}]
},
"filesData": {
"1000000000004": {
"atime": 23456783489,
"ctime": 12345678999,
"href": href4,
"title": "Title4"
},
"1000000000003": {
"atime": 23456783456,
"ctime": 12345678901,
"href": href3,
"title": "Title3"
},
"1000000000002": {
"atime": 23456789012,
"ctime": 12345789235,
"href": href2,
"title": "Title2"
},
"1000000000001": {
"atime": 23456789012,
"ctime": 12345789235,
"href": href1,
"title": "Title1",
"filename": "FileName1"
}
}
};
module.test = function (assert) {
var config = {Cryptpad: Cryptpad, workgroup: false};
var config = {Cryptpad: Cryptpad, workgroup: false, testMode: true};
// MIGRATION FROM HREF TO ID
assert(function (cb) {
console.log('START DRIVE1');
var files = {
"root": {
"Folder": {},
@@ -69,6 +131,7 @@ define([
}, "DRIVE1: migration and fixFiles without unsorted");
assert(function (cb) {
console.log('START DRIVE2');
var files = {
"root": {
"Folder": {},
@@ -121,6 +184,7 @@ define([
}, "DRIVE2: migration and fixFiles with unsorted");
assert(function (cb) {
console.log('START DRIVE3');
var files = {
"root": {
"Folder": {},
@@ -170,9 +234,141 @@ define([
return cb(res);
}, "DRIVE4: migration and fixFiles with a pad in trash not root");
};
// userObject Tests
//TODO test with a file not in RECENTPADS
// UTILS
assert(function (cb) {
console.log('START DRIVE utils');
var files = JSON.parse(JSON.stringify(example));
var fo = FO.init(files, config);
fo.fixFiles();
if (fo.isFile({}) || fo.isFile(href1) || !fo.isFile(href1, true) || !fo.isFile(id1)) {
console.log("DRIVE utils: isFile returns an incorrect value");
return cb();
}
if (fo.isReadOnlyFile(id1)) {
console.log("DRIVE utils: isReadOnlyFile returns true for an 'edit' file");
return cb();
}
if (!fo.isReadOnlyFile(id3)) {
console.log("DRIVE utils: isReadOnlyFile returns false for a 'view' file");
return cb();
}
if (!fo.hasSubfolder(files.root.Folder) || fo.hasSubfolder(files.root.Folder2)) {
console.log("DRIVE utils: hasSubfolder returns an incorrect value");
return cb();
}
if (fo.hasFile(files.root.Folder) || !fo.hasFile(files.root.Folder2)) {
console.log("DRIVE utils: hasFile returns an incorrect value");
return cb();
}
if (JSON.stringify(fo.getFileData(id1)) !== JSON.stringify(files.filesData[id1])) {
console.log("DRIVE utils: getFileData returns an incorrect value");
return cb();
}
if (fo.getTitle(id4) !== "Title4" || fo.getTitle(id1) !== "FileName1") {
console.log("DRIVE utils: getTitle returns an incorrect value");
return cb();
}
if (fo.find(["root", "Folder2", "rdmStrFile1"]) !== id1) {
console.log("DRIVE utils: 'find' returns an incorrect value");
return cb();
}
if (fo.getFiles().length !== 4 || fo.getFiles(['trash']).length !== 2) {
console.log("DRIVE utils: getFiles returns an incorrect value");
return cb();
}
if (fo.findFile(id4).length !== 1 || fo.findFile(id4)[0].length !== 4) {
console.log("DRIVE utils: findFile returns an incorrect value");
return cb();
}
if (fo.search('tle2').length !== 1 || fo.search('tle2')[0].data.href !== href2 || fo.search('tle2')[0].paths[0][0] !== 'template') {
console.log("DRIVE utils: search returns an incorrect value");
return cb();
}
return cb(true);
}, "DRIVE utils");
// OPERATIONS
assert(function (cb) {
console.log('START DRIVE operations');
var files = JSON.parse(JSON.stringify(example));
var fo = FO.init(files, config);
fo.fixFiles();
var data = Cryptpad.makePad(href5, 'Title5');
var res;
var id5;
// pushData is synchronous in test mode (no pinning)
fo.pushData(data, function (e, id) {
fo.add(id, ["root", "Folder"]);
id5 = id;
res = JSON.stringify(data) === JSON.stringify(fo.getFileData(id)) &&
fo.getFiles(["root"]).indexOf(id) !== -1;
});
if (!res) {
console.log("DRIVE operations: pushData");
return cb();
}
fo.move([["root", "Folder"], ["template", 0]], ["trash"]);
if (fo.getFiles(["template"]).indexOf(id2) !== -1 ||
fo.getFiles(["trash"]).indexOf(id5) === -1) {
console.log("DRIVE operations: move");
return cb();
}
fo.restore(["trash", "Title2", 0, "element"]);
if (files["template"][0] !== id2 || fo.getFiles(['trash']).indexOf(id2) !== -1) {
console.log("DRIVE operations: restore");
return cb();
}
files["template"] = [];
fo.add(id2, ["template"]);
if (fo.getFiles(['template']).indexOf(id2) === -1) {
console.log("DRIVE operations");
return cb();
}
var path;
fo.addFolder(["root", "Folder2"], "subsub", function (e, o) { path = o.newPath; });
if (!files.root.Folder2.subsub || path.length !== 3) {
console.log("DRIVE operations: add folder");
return cb();
}
fo.forget(href2);
if (files["template"].length !== 0 || fo.getFiles(['trash']).indexOf(id2) === -1) {
console.log("DRIVE operations: forget");
return cb();
}
fo.restore(["trash", "Title2", 0, "element"]);
fo.delete([["root", "Folder2", "subsub"],["template",0]]);
if (files.root.Folder2.subsub || fo.getFiles().indexOf(id2) !== -1) {
console.log("DRIVE operations: delete");
return cb();
}
fo.emptyTrash();
if (JSON.stringify(files.trash) !== "{}" || fo.getFiles().indexOf(id5) !== -1 ||
files.filesData[id5]) {
console.log("DRIVE operations: emptyTrash");
return cb();
}
fo.rename(["root", "Folder2"], "FolderNew");
fo.rename(["root", "FolderNew", "rdmStrFile1"], "NewFileName1");
if (files.root.Folder2 || !files.root.FolderNew ||
fo.getFileData(id1).filename !== "NewFileName1" ||
fo.getTitle(id1) !== "NewFileName1") {
console.log("DRIVE operations: rename");
return cb();
}
fo.replace(href1, href2);
if (fo.getFileData(id1).href !== href2) {
console.log("DRIVE operations: replace");
return cb();
}
cb(true);
}, "DRIVE operations");
};
return module;
});