2015-12-02 16:13:29 +00:00
|
|
|
describe("Sync Preferences", function () {
|
|
|
|
var win, doc;
|
|
|
|
before(function* () {
|
|
|
|
// Load prefs with sync pane
|
|
|
|
win = yield loadWindow("chrome://zotero/content/preferences/preferences.xul", {
|
|
|
|
pane: 'zotero-prefpane-sync',
|
|
|
|
tabIndex: 0
|
|
|
|
});
|
|
|
|
doc = win.document;
|
|
|
|
let defer = Zotero.Promise.defer();
|
|
|
|
let pane = doc.getElementById('zotero-prefpane-sync');
|
|
|
|
if (!pane.loaded) {
|
|
|
|
pane.addEventListener('paneload', function () {
|
|
|
|
defer.resolve();
|
|
|
|
});
|
|
|
|
yield defer.promise;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("Settings", function () {
|
2016-09-24 04:42:29 +00:00
|
|
|
describe("Data Syncing", function () {
|
2015-12-02 16:13:29 +00:00
|
|
|
var getAPIKeyFromCredentialsStub, deleteAPIKey, indicatorElem;
|
|
|
|
|
|
|
|
var setCredentials = Zotero.Promise.coroutine(function* (username, password) {
|
|
|
|
let usernameElem = doc.getElementById('sync-username-textbox');
|
|
|
|
let passwordElem = doc.getElementById('sync-password');
|
|
|
|
usernameElem.value = username;
|
|
|
|
passwordElem.value = password;
|
|
|
|
|
|
|
|
// Triggered by `change` event for usernameElem and passwordElem;
|
|
|
|
yield win.Zotero_Preferences.Sync.linkAccount();
|
|
|
|
});
|
|
|
|
|
|
|
|
var apiKey = Zotero.Utilities.randomString(24);
|
|
|
|
|
|
|
|
var apiResponse = {
|
|
|
|
key: apiKey,
|
|
|
|
username: "Username",
|
|
|
|
userID: 1,
|
|
|
|
access: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
before(function* () {
|
|
|
|
getAPIKeyFromCredentialsStub = sinon.stub(
|
|
|
|
Zotero.Sync.APIClient.prototype, 'createAPIKeyFromCredentials');
|
|
|
|
deleteAPIKey = sinon.stub(Zotero.Sync.APIClient.prototype, 'deleteAPIKey').resolves();
|
|
|
|
indicatorElem = doc.getElementById('sync-status-indicator')
|
|
|
|
sinon.stub(Zotero, 'alert');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function* (){
|
|
|
|
yield win.Zotero_Preferences.Sync.unlinkAccount(false);
|
2017-06-01 19:30:06 +00:00
|
|
|
deleteAPIKey.resetHistory();
|
2015-12-02 16:13:29 +00:00
|
|
|
Zotero.alert.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
Zotero.HTTP.mock = null;
|
|
|
|
Zotero.alert.restore();
|
|
|
|
getAPIKeyFromCredentialsStub.restore();
|
|
|
|
deleteAPIKey.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set API key and display full controls with correct credentials", function* () {
|
|
|
|
getAPIKeyFromCredentialsStub.resolves(apiResponse);
|
|
|
|
yield setCredentials("Username", "correctPassword");
|
|
|
|
|
2016-09-05 07:59:42 +00:00
|
|
|
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey);
|
2015-12-02 16:13:29 +00:00
|
|
|
assert.equal(doc.getElementById('sync-unauthorized').getAttribute('hidden'), 'true');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should display dialog when credentials incorrect", function* () {
|
|
|
|
getAPIKeyFromCredentialsStub.resolves(false);
|
|
|
|
yield setCredentials("Username", "incorrectPassword");
|
|
|
|
|
|
|
|
assert.isTrue(Zotero.alert.called);
|
2016-09-05 07:59:42 +00:00
|
|
|
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), "");
|
2015-12-02 16:13:29 +00:00
|
|
|
assert.equal(doc.getElementById('sync-authorized').getAttribute('hidden'), 'true');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should delete API key and display auth form when 'Unlink Account' clicked", function* () {
|
|
|
|
getAPIKeyFromCredentialsStub.resolves(apiResponse);
|
|
|
|
yield setCredentials("Username", "correctPassword");
|
2016-09-05 07:59:42 +00:00
|
|
|
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey);
|
2015-12-02 16:13:29 +00:00
|
|
|
|
|
|
|
yield win.Zotero_Preferences.Sync.unlinkAccount(false);
|
|
|
|
|
|
|
|
assert.isTrue(deleteAPIKey.called);
|
2016-09-05 07:59:42 +00:00
|
|
|
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), "");
|
2015-12-02 16:13:29 +00:00
|
|
|
assert.equal(doc.getElementById('sync-authorized').getAttribute('hidden'), 'true');
|
|
|
|
});
|
2016-06-27 16:40:38 +00:00
|
|
|
|
|
|
|
it("should not unlink on pressing cancel", function* () {
|
|
|
|
getAPIKeyFromCredentialsStub.resolves(apiResponse);
|
|
|
|
yield setCredentials("Username", "correctPassword");
|
|
|
|
|
|
|
|
waitForDialog(null, 'cancel');
|
|
|
|
|
|
|
|
yield win.Zotero_Preferences.Sync.unlinkAccount();
|
2016-09-05 07:59:42 +00:00
|
|
|
yield assert.eventually.equal(Zotero.Sync.Data.Local.getAPIKey(), apiKey);
|
2016-06-27 16:40:38 +00:00
|
|
|
assert.equal(doc.getElementById('sync-unauthorized').getAttribute('hidden'), 'true');
|
|
|
|
});
|
2015-12-02 16:13:29 +00:00
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|