Item predicate matching

This commit is contained in:
Mo Bitar
2018-07-03 18:21:55 -05:00
parent 8c9fd9308d
commit 662b3d6a07
2 changed files with 16 additions and 27 deletions

View File

@@ -125,32 +125,10 @@ class SingletonManager {
filterItemsWithPredicate(items, predicate) {
return items.filter((candidate) => {
return this.itemSatisfiesPredicate(candidate, predicate);
return candidate.satisfiesPredicate(predicate);
})
}
itemSatisfiesPredicate(candidate, predicate) {
for(var key in predicate) {
var predicateValue = predicate[key];
var candidateValue = candidate[key];
if(typeof predicateValue == 'object') {
// Check nested properties
if(!candidateValue) {
// predicateValue is 'object' but candidateValue is null
return false;
}
if(!this.itemSatisfiesPredicate(candidateValue, predicateValue)) {
return false;
}
}
else if(candidateValue != predicateValue) {
return false;
}
}
return true;
}
}
angular.module('app').service('singletonManager', SingletonManager);

View File

@@ -157,7 +157,7 @@ describe("notes and tags", () => {
expect(tag.notes.length).to.equal(0);
});
it.only('resets cached note tags string when tag is renamed', () => {
it('resets cached note tags string when tag is renamed', () => {
let modelManager = Factory.createModelManager();
let pair = createRelatedNoteTagPair();
@@ -384,7 +384,15 @@ describe("syncing", () => {
};
})
it('syncing a note many times does not cause duplication', async () => {
const wait = (secs) => {
return new Promise((resolve, reject) => {
setTimeout(function () {
resolve();
}, secs * 1000);
})
}
it.only('syncing a note many times does not cause duplication', async () => {
modelManager.resetLocalMemory();
let pair = createRelatedNoteTagPair();
let noteParams = pair[0];
@@ -394,17 +402,20 @@ describe("syncing", () => {
let note = modelManager.allItemsMatchingTypes(["Note"])[0];
let tag = modelManager.allItemsMatchingTypes(["Tag"])[0];
for(var i = 0; i < 25; i++) {
for(var i = 0; i < 9; i++) {
note.setDirty(true);
tag.setDirty(true);
await syncManager.sync();
syncManager.clearSyncToken();
expect(tag.content.references.length).to.equal(1);
expect(note.tags.length).to.equal(1);
expect(tag.notes.length).to.equal(1);
expect(modelManager.allItems.length).to.equal(2);
console.log("Waiting 1.1s...");
await wait(1.1);
}
}).timeout(10000);
}).timeout(20000);
it("handles signing in and merging data", async () => {