2015-09-29 08:05:13 +00:00
|
|
|
describe("Advanced Preferences", function () {
|
|
|
|
describe("Files & Folders", function () {
|
|
|
|
describe("Linked Attachment Base Directory", function () {
|
|
|
|
var setBaseDirectory = Zotero.Promise.coroutine(function* (basePath) {
|
2022-08-10 22:26:23 +00:00
|
|
|
var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xhtml", {
|
2022-09-02 15:01:37 +00:00
|
|
|
pane: 'zotero-prefpane-advanced'
|
2015-09-29 08:05:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Wait for tab to load
|
2022-09-02 15:01:37 +00:00
|
|
|
yield win.Zotero_Preferences.waitForFirstPaneLoad();
|
2015-09-29 08:05:13 +00:00
|
|
|
|
|
|
|
var promise = waitForDialog();
|
|
|
|
yield win.Zotero_Preferences.Attachment_Base_Directory.changePath(basePath);
|
|
|
|
yield promise;
|
|
|
|
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
var clearBaseDirectory = Zotero.Promise.coroutine(function* (basePath) {
|
2022-08-10 22:26:23 +00:00
|
|
|
var win = yield loadWindow("chrome://zotero/content/preferences/preferences.xhtml", {
|
2015-09-29 08:05:13 +00:00
|
|
|
pane: 'zotero-prefpane-advanced',
|
|
|
|
tabIndex: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wait for tab to load
|
2022-09-02 15:01:37 +00:00
|
|
|
yield win.Zotero_Preferences.waitForFirstPaneLoad();
|
2015-09-29 08:05:13 +00:00
|
|
|
|
|
|
|
var promise = waitForDialog();
|
|
|
|
yield win.Zotero_Preferences.Attachment_Base_Directory.clearPath();
|
|
|
|
yield promise;
|
|
|
|
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
Zotero.Prefs.clear('baseAttachmentPath');
|
|
|
|
Zotero.Prefs.clear('saveRelativeAttachmentPath');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should set new base directory", function* () {
|
|
|
|
var basePath = getTestDataDirectory().path;
|
|
|
|
yield setBaseDirectory(basePath);
|
|
|
|
assert.equal(Zotero.Prefs.get('baseAttachmentPath'), basePath);
|
|
|
|
assert.isTrue(Zotero.Prefs.get('saveRelativeAttachmentPath'));
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should clear base directory", function* () {
|
|
|
|
var basePath = getTestDataDirectory().path;
|
|
|
|
yield setBaseDirectory(basePath);
|
|
|
|
yield clearBaseDirectory();
|
|
|
|
|
|
|
|
assert.equal(Zotero.Prefs.get('baseAttachmentPath'), '');
|
|
|
|
assert.isFalse(Zotero.Prefs.get('saveRelativeAttachmentPath'));
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should change absolute path of linked attachment under new base dir to prefixed path", function* () {
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var attachment = yield Zotero.Attachments.linkFromFile({ file });
|
|
|
|
assert.equal(attachment.attachmentPath, file.path);
|
|
|
|
|
|
|
|
var basePath = getTestDataDirectory().path;
|
|
|
|
yield setBaseDirectory(basePath);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
attachment.attachmentPath,
|
|
|
|
Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should change prefixed path to absolute when changing base directory", function* () {
|
|
|
|
var basePath = getTestDataDirectory().path;
|
|
|
|
yield setBaseDirectory(basePath);
|
|
|
|
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var attachment = yield Zotero.Attachments.linkFromFile({ file });
|
|
|
|
assert.equal(
|
|
|
|
attachment.attachmentPath,
|
|
|
|
Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
|
|
|
|
);
|
|
|
|
|
2020-04-29 20:29:22 +00:00
|
|
|
// Choose a nonexistent directory for the base path
|
|
|
|
var otherPath = OS.Path.join(OS.Path.dirname(basePath), 'foobar');
|
|
|
|
yield setBaseDirectory(otherPath);
|
2015-09-29 08:05:13 +00:00
|
|
|
|
|
|
|
assert.equal(attachment.attachmentPath, file.path);
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should change prefixed path to absolute when clearing base directory", function* () {
|
|
|
|
var basePath = getTestDataDirectory().path;
|
|
|
|
yield setBaseDirectory(basePath);
|
|
|
|
|
|
|
|
var file = getTestDataDirectory();
|
|
|
|
file.append('test.png');
|
|
|
|
var attachment = yield Zotero.Attachments.linkFromFile({ file });
|
|
|
|
assert.equal(
|
|
|
|
attachment.attachmentPath,
|
|
|
|
Zotero.Attachments.BASE_PATH_PLACEHOLDER + 'test.png'
|
|
|
|
);
|
|
|
|
|
|
|
|
yield clearBaseDirectory();
|
|
|
|
|
|
|
|
assert.equal(Zotero.Prefs.get('baseAttachmentPath'), '');
|
|
|
|
assert.isFalse(Zotero.Prefs.get('saveRelativeAttachmentPath'));
|
|
|
|
|
|
|
|
assert.equal(attachment.attachmentPath, file.path);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|