Add .contentType and .charset options for importFromFile()

And use them in new importTextAttachment() and importHTMLAttachment()
test support functions. These can be used to avoid needing a hidden
browser for determining the character set of the imported text
documents.
This commit is contained in:
Dan Stillman 2017-07-01 06:20:27 -04:00
parent b1fad5a310
commit 9a3ff2d244
3 changed files with 41 additions and 21 deletions

View file

@ -1,27 +1,18 @@
"use strict";
describe("Zotero.Sync.Storage.Local", function () {
var win;
before(function* () {
win = yield loadBrowserWindow();
});
beforeEach(function* () {
yield resetDB({
thisArg: this,
skipBundledFiles: true
})
})
after(function () {
if (win) {
win.close();
}
});
describe("#checkForUpdatedFiles()", function () {
it("should flag modified file for upload and return it", function* () {
// Create attachment
let item = yield importFileAttachment('test.txt')
let item = yield importTextAttachment();
var hash = yield item.attachmentHash;
// Set file mtime to the past (without milliseconds, which aren't used on OS X)
var mtime = (Math.floor(new Date().getTime() / 1000) * 1000) - 1000;
@ -50,7 +41,7 @@ describe("Zotero.Sync.Storage.Local", function () {
it("should skip a file if mod time hasn't changed", function* () {
// Create attachment
let item = yield importFileAttachment('test.txt')
let item = yield importTextAttachment();
var hash = yield item.attachmentHash;
var mtime = yield item.attachmentModificationTime;
@ -72,7 +63,7 @@ describe("Zotero.Sync.Storage.Local", function () {
it("should skip a file if mod time has changed but contents haven't", function* () {
// Create attachment
let item = yield importFileAttachment('test.txt')
let item = yield importTextAttachment();
var hash = yield item.attachmentHash;
// Set file mtime to the past (without milliseconds, which aren't used on OS X)
var mtime = (Math.floor(new Date().getTime() / 1000) * 1000) - 1000;
@ -529,8 +520,8 @@ describe("Zotero.Sync.Storage.Local", function () {
var item1 = yield importFileAttachment('test.png');
item1.version = 10;
yield item1.saveTx();
var item2 = yield importFileAttachment('test.txt');
var item3 = yield importFileAttachment('test.html');
var item2 = yield importTextAttachment();
var item3 = yield importHTMLAttachment();
item3.version = 11;
yield item3.saveTx();
@ -574,14 +565,27 @@ describe("Zotero.Sync.Storage.Local", function () {
})
describe("#resolveConflicts()", function () {
var win;
before(function* () {
win = yield loadBrowserWindow();
});
after(function () {
if (win) {
win.close();
}
});
it("should show the conflict resolution window on attachment conflicts", function* () {
var libraryID = Zotero.Libraries.userLibraryID;
var item1 = yield importFileAttachment('test.png');
item1.version = 10;
yield item1.saveTx();
var item2 = yield importFileAttachment('test.txt');
var item3 = yield importFileAttachment('test.html');
var item2 = yield importTextAttachment();
var item3 = yield importHTMLAttachment();
item3.version = 11;
yield item3.saveTx();
@ -647,6 +651,4 @@ describe("Zotero.Sync.Storage.Local", function () {
assert.isNull(item3.attachmentSyncedHash);
})
})
})