Repository: couchdb-fauxton Updated Branches: refs/heads/master c5c6f1c21 -> 915ca9463
Use ajax call instead of backbone Adds a test to delete a document via the Document Editor screen button This fixes the bug where deleting a document with a symbol (slash +/- hypen) doesn't consistently take you back to the all_docs screen. Also I like AJAX calls better. Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/915ca946 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/915ca946 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/915ca946 Branch: refs/heads/master Commit: 915ca94639aff6280e546f453dc25093dea7db28 Parents: c5c6f1c Author: Michelle Phung <[email protected]> Authored: Tue Nov 17 14:06:12 2015 -0500 Committer: Michelle Phung <[email protected]> Committed: Tue Nov 17 20:07:42 2015 -0500 ---------------------------------------------------------------------- app/addons/documents/base.js | 7 ++-- app/addons/documents/doc-editor/actions.js | 37 +++++++++++++------- .../tests/nightwatch/deletesDocuments.js | 29 ++++++++++++++- 3 files changed, 57 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/915ca946/app/addons/documents/base.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/base.js b/app/addons/documents/base.js index 3dd82c0..c0eaa91 100644 --- a/app/addons/documents/base.js +++ b/app/addons/documents/base.js @@ -70,8 +70,11 @@ function (app, FauxtonAPI, Documents) { }); FauxtonAPI.registerUrls('document', { - server: function (database, doc) { - return app.host + '/' + database + '/' + doc; + server: function (database, doc, query) { + if (_.isUndefined(query)) { + query = ''; + } + return app.host + '/' + database + '/' + doc + query; }, attachment: function (database, doc, filename, query) { http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/915ca946/app/addons/documents/doc-editor/actions.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/doc-editor/actions.js b/app/addons/documents/doc-editor/actions.js index a7f076b..259cfc4 100644 --- a/app/addons/documents/doc-editor/actions.js +++ b/app/addons/documents/doc-editor/actions.js @@ -82,19 +82,30 @@ function (app, FauxtonAPI, ActionTypes) { } function deleteDoc (doc) { - var databaseName = doc.database.id; - doc.destroy().then(function () { - FauxtonAPI.addNotification({ - msg: 'Your document has been successfully deleted.', - clear: true - }); - FauxtonAPI.navigate(FauxtonAPI.urls('allDocs', 'app', databaseName, '')); - }, function () { - FauxtonAPI.addNotification({ - msg: 'Failed to delete your document!', - type: 'error', - clear: true - }); + var databaseName = doc.database.safeID(); + var query = '?rev=' + doc.get('_rev'); + + $.ajax({ + url: FauxtonAPI.urls('document', 'server', databaseName, doc.safeID(), query), + type: 'DELETE', + contentType: 'application/json; charset=UTF-8', + xhrFields: { + withCredentials: true + }, + success: function () { + FauxtonAPI.addNotification({ + msg: 'Your document has been successfully deleted.', + clear: true + }); + FauxtonAPI.navigate(FauxtonAPI.urls('allDocs', 'app', databaseName, '')); + }, + error: function (resp) { + FauxtonAPI.addNotification({ + msg: 'Failed to delete your document!', + type: 'error', + clear: true + }); + } }); } http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/915ca946/app/addons/documents/tests/nightwatch/deletesDocuments.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/tests/nightwatch/deletesDocuments.js b/app/addons/documents/tests/nightwatch/deletesDocuments.js index edee01c..83989e4 100644 --- a/app/addons/documents/tests/nightwatch/deletesDocuments.js +++ b/app/addons/documents/tests/nightwatch/deletesDocuments.js @@ -98,6 +98,33 @@ module.exports = { // now confirm it's gone .waitForElementNotPresent('#sidebar-content span[title="_design/sidebar-update"]', waitTime, false) .end(); - } + }, + + 'Deletes a document via Editor': function (client) { + var waitTime = client.globals.maxWaitTime, + newDatabaseName = client.globals.testDatabaseName, + newDocumentName = 'delete_doc_doc', + baseUrl = client.globals.test_settings.launch_url; + + client + .createDocument(newDocumentName, newDatabaseName) + .loginToGUI() + .url(baseUrl + '#/database/' + newDatabaseName + '/' + newDocumentName) + .waitForElementPresent('#editor-container', waitTime, false) + .clickWhenVisible('#doc-editor-actions-panel button[title="Delete"]') + .clickWhenVisible('button.btn.btn-success.js-btn-success') + .waitForElementPresent('#jump-to-doc-id', waitTime, false) + //check raw JSON + .url(baseUrl + '/' + newDatabaseName + '/_all_docs') + .waitForElementPresent('pre', waitTime, false) + .getText('pre', function (result) { + var data = result.value, + createdDocumentANotPresent = data.indexOf(newDocumentName) === -1; + + this.verify.ok(createdDocumentANotPresent, + 'Checking if new document no longer shows up in _all_docs.'); + }) + .end(); + }, };
