1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

testing sync

This commit is contained in:
Laurent Cozic 2017-06-13 20:58:17 +00:00
parent c92b46b651
commit 18adbeea27
12 changed files with 127 additions and 4 deletions

View File

@ -1,3 +1,4 @@
build/
node_modules/
app/src
spec-build/

View File

@ -26,11 +26,13 @@
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.5.1",
"babel-preset-react": "^6.24.1",
"jasmine": "^2.6.0",
"query-string": "4.3.4"
},
"scripts": {
"babelbuild": "babel app -d build",
"build": "babel-changed app -d build --source-maps && babel-changed app/src/models -d build/src/models --source-maps && babel-changed app/src/services -d build/src/services --source-maps",
"clean": "babel-changed --reset"
"clean": "babel-changed --reset",
"test": "babel-changed spec -d spec-build --source-maps && jasmine"
}
}

View File

@ -4,6 +4,4 @@ CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rm -f "$CLIENT_DIR/app/src"
ln -s "$CLIENT_DIR/../ReactNativeClient/src" "$CLIENT_DIR/app"
#npm run build && NODE_PATH="$CLIENT_DIR/build/" node build/import-enex.js
#npm run build && NODE_PATH="$CLIENT_DIR/build/" node build/file-api-test.js
npm run build && NODE_PATH="$CLIENT_DIR/build/" node build/cmd.js

7
CliClient/run_test.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rm -f "$CLIENT_DIR/spec-build/src"
ln -s "$CLIENT_DIR/build/src" "$CLIENT_DIR/spec-build"
npm build && NODE_PATH="$CLIENT_DIR/spec-build/" npm test spec-build/synchronizer.js

1
CliClient/spec/src Symbolic link
View File

@ -0,0 +1 @@
/home/laurent/src/notes/CliClient/../ReactNativeClient/src

View File

@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}

View File

@ -0,0 +1,32 @@
import { Synchronizer } from 'src/synchronizer.js';
import { FileApi } from 'src/file-api.js';
import { FileApiDriverMemory } from 'src/file-api-driver-memory.js';
describe("syncActions", function() {
let fileDriver = new FileApiDriverMemory();
let fileApi = new FileApi('/root', fileDriver);
let synchronizer = new Synchronizer(null, fileApi);
it("and so is a spec", function() {
let localItems = [];
localItems.push({ path: 'test', isDir: true, updatedTime: 1497370000 });
localItems.push({ path: 'test/un', updatedTime: 1497370000 });
localItems.push({ path: 'test/deux', updatedTime: 1497370000 });
let remoteItems = [];
let actions = synchronizer.syncActions(localItems, remoteItems, 0);
expect(actions.length).toBe(3);
// synchronizer.format();
// synchronizer.mkdir('test');
// synchronizer.touch('test/un');
// synchronizer.touch('test/deux');
// synchronizer.touch('test/trois');
});
});

View File

@ -152,6 +152,10 @@ class FileApiDriverLocal {
});
}
format() {
throw new Error('Not supported');
}
}
export { FileApiDriverLocal };

View File

@ -104,6 +104,11 @@ class FileApiDriverMemory {
return Promise.resolve();
}
format() {
this.items_ = [];
return Promise.resolve();
}
}
export { FileApiDriverMemory };

View File

@ -66,6 +66,10 @@ class FileApi {
return this.driver_.move(this.fullPath_(oldPath), this.fullPath_(newPath));
}
format() {
return this.driver_.format();
}
}
export { FileApi };

View File

@ -77,6 +77,62 @@ class Synchronizer {
});
}
// isNewerThan(date1, date2) {
// return date1 > date2;
// }
itemByPath(items, path) {
for (let i = 0; i < items.length; i++) {
if (items[i].path == path) return items[i];
}
return null;
}
syncAction(actionType, where, item, isConflict) {
return {
type: actionType,
where: where,
item: item,
};
}
itemIsNewerThan(item, date) {
return item.updatedTime > date;
}
itemIsOlderThan(item, date) {
return !this.itemIsNewerThan(item, date);
}
syncActions(localItems, remoteItems, lastSyncTime) {
let output = [];
for (let i = 0; i < localItems.length; i++) {
let item = localItems[i];
let remoteItem = this.itemByPath(remoteItems, item.path);
let action = {
localItem: item,
remoteItem: remoteItem,
};
if (!remoteItem) {
action.type = 'create';
action.where = 'there';
} else {
if (this.itemIsOlderThan(remoteItem, lastSyncTime)) {
action.type = 'update';
action.where = 'there';
} else {
action.type = 'conflict'; // Move local to /Conflict; Copy remote here
action.where = 'here';
}
}
output.push(action);
}
return output;
}
processState_uploadChanges() {
let remoteFiles = [];
let processedChangeIds = [];

View File

@ -11,6 +11,7 @@
"app/data/uploads",
"CliClient/node_modules",
"CliClient/build",
"CliClient/spec-build",
"CliClient/app/src",
"ReactNativeClient/node_modules",
"ReactNativeClient/android/app/build",
@ -24,6 +25,7 @@
"*.pro.user",
"*.pro.user.*",
"*.iml",
"*.map",
"CliClient/app/src",
]
}