From 8e0e69332ef6a0f3bb896f19a0d1315e18412928 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 20 Jun 2016 01:08:25 -0500 Subject: [PATCH] Fix syncing of search conditions --- chrome/content/zotero/xpcom/search.js | 12 +++++++++--- test/tests/searchTest.js | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index 88598f7afb..7c640c86e8 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -836,7 +836,7 @@ Zotero.Search.prototype.fromJSON = function (json) { } } -Zotero.Collection.prototype.toResponseJSON = function (options = {}) { +Zotero.Search.prototype.toResponseJSON = function (options = {}) { var json = this.constructor._super.prototype.toResponseJSON.apply(this, options); return json; }; @@ -851,8 +851,14 @@ Zotero.Search.prototype.toJSON = function (options = {}) { obj.version = this.version; obj.name = this.name; var conditions = this.getConditions(); - obj.conditions = Object.keys(conditions).map(x => conditions[x]); - + obj.conditions = Object.keys(conditions) + .map(x => ({ + condition: conditions[x].condition + + (conditions[x].mode !== false ? "/" + conditions[x].mode : ""), + operator: conditions[x].operator, + // TODO: Change joinMode to use 'is' + 'any' instead of operator 'any'? + value: conditions[x].value ? conditions[x].value : "" + })); return this._postToJSON(env); } diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js index 41d6a42052..2d20f2b93e 100644 --- a/test/tests/searchTest.js +++ b/test/tests/searchTest.js @@ -195,15 +195,24 @@ describe("Zotero.Search", function() { let s = new Zotero.Search(); s.name = "Test"; s.addCondition('joinMode', 'any'); - s.addCondition('fulltextWord', 'contains', 'afsgagsdg'); + s.addCondition('fulltextContent/regexp', 'contains', 's.+'); let json = s.toJSON(); assert.equal(json.name, "Test"); + assert.lengthOf(json.conditions, 2); + assert.equal(json.conditions[0].condition, 'joinMode'); assert.equal(json.conditions[0].operator, 'any'); - assert.equal(json.conditions[1].condition, 'fulltextWord'); + // TODO: Change to 'is' + 'any'? + assert.strictEqual(json.conditions[0].value, ''); + assert.notProperty(json.conditions[0], 'id'); + assert.notProperty(json.conditions[0], 'required'); + assert.notProperty(json.conditions[0], 'mode'); + + assert.equal(json.conditions[1].condition, 'fulltextContent/regexp'); assert.equal(json.conditions[1].operator, 'contains'); - assert.equal(json.conditions[1].value, 'afsgagsdg'); + assert.equal(json.conditions[1].value, 's.+'); + assert.notProperty(json.conditions[1], 'mode'); }); });