2015-06-02 04:29:40 +00:00
|
|
|
describe("Zotero.Feed", function() {
|
|
|
|
// Clean up after after tests
|
|
|
|
after(function* () {
|
2016-01-13 13:13:29 +00:00
|
|
|
yield clearFeeds();
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should be an instance of Zotero.Library", function() {
|
|
|
|
let feed = new Zotero.Feed();
|
|
|
|
assert.instanceOf(feed, Zotero.Library);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#constructor()", function() {
|
|
|
|
it("should accept required fields as arguments", function* () {
|
|
|
|
let feed = new Zotero.Feed();
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed.saveTx(), /^Feed name not set$/);
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
feed = new Zotero.Feed({
|
|
|
|
name: 'Test ' + Zotero.randomString(),
|
|
|
|
url: 'http://www.' + Zotero.randomString() + '.com'
|
|
|
|
});
|
|
|
|
yield assert.isFulfilled(feed.saveTx());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#isFeed", function() {
|
|
|
|
it("should be true", function() {
|
|
|
|
let feed = new Zotero.Feed();
|
|
|
|
assert.isTrue(feed.isFeed);
|
|
|
|
});
|
|
|
|
it("should be falsy for regular Library", function() {
|
|
|
|
let library = new Zotero.Library();
|
|
|
|
assert.notOk(library.isFeed);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#editable", function() {
|
|
|
|
it("should always be not editable", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
assert.isFalse(feed.editable);
|
|
|
|
feed.editable = true;
|
|
|
|
assert.isFalse(feed.editable);
|
|
|
|
yield feed.saveTx();
|
|
|
|
assert.isFalse(feed.editable);
|
|
|
|
});
|
2016-02-11 11:02:38 +00:00
|
|
|
it("should allow adding items without editCheck override", function* () {
|
2015-06-02 04:29:40 +00:00
|
|
|
let feed = yield createFeed();
|
|
|
|
let feedItem = new Zotero.FeedItem('book', { guid: Zotero.randomString() });
|
|
|
|
feedItem.libraryID = feed.libraryID;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield assert.isFulfilled(feedItem.saveTx());
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-27 07:21:00 +00:00
|
|
|
describe("#libraryTypeID", function () {
|
|
|
|
it("should be undefind", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
assert.isUndefined(feed.libraryTypeID);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-02 04:29:40 +00:00
|
|
|
describe("#url", function() {
|
|
|
|
it("should throw if trying to set an invalid URL", function *() {
|
|
|
|
let feed = new Zotero.Feed({ name: 'Test ' + Zotero.randomString() });
|
|
|
|
|
|
|
|
assert.throws(function() {feed.url = 'foo'}, /^Invalid feed URL /);
|
|
|
|
assert.throws(function() {feed.url = 'ftp://example.com'}, /^Invalid feed URL /);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#save()", function() {
|
|
|
|
it("should save a new feed to the feed library", function* () {
|
|
|
|
let props = {
|
|
|
|
name: 'Test ' + Zotero.randomString(),
|
|
|
|
url: 'http://' + Zotero.randomString() + '.com/'
|
|
|
|
};
|
|
|
|
let feed = yield createFeed(props);
|
|
|
|
|
|
|
|
assert.equal(feed.name, props.name, "name is correct");
|
|
|
|
assert.equal(feed.url.toLowerCase(), props.url.toLowerCase(), "url is correct");
|
|
|
|
});
|
|
|
|
it("should save a feed with all fields set", function* () {
|
|
|
|
let props = {
|
|
|
|
name: 'Test ' + Zotero.randomString(),
|
|
|
|
url: 'http://' + Zotero.randomString() + '.com/',
|
|
|
|
refreshInterval: 30,
|
2016-12-13 14:07:43 +00:00
|
|
|
cleanupReadAfter: 1,
|
|
|
|
cleanupUnreadAfter: 30
|
2015-06-02 04:29:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let feed = yield createFeed(props);
|
|
|
|
|
|
|
|
assert.equal(feed.name, props.name, "name is correct");
|
|
|
|
assert.equal(feed.url.toLowerCase(), props.url.toLowerCase(), "url is correct");
|
|
|
|
assert.equal(feed.refreshInterval, props.refreshInterval, "refreshInterval is correct");
|
2016-12-13 14:07:43 +00:00
|
|
|
assert.equal(feed.cleanupReadAfter, props.cleanupReadAfter, "cleanupReadAfter is correct");
|
|
|
|
assert.equal(feed.cleanupUnreadAfter, props.cleanupUnreadAfter, "cleanupUnreadAfter is correct");
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
assert.isNull(feed.lastCheck, "lastCheck is null");
|
|
|
|
assert.isNull(feed.lastUpdate, "lastUpdate is null");
|
|
|
|
assert.isNull(feed.lastCheckError, "lastCheckError is null");
|
|
|
|
});
|
|
|
|
it("should throw if name or url are missing", function *() {
|
|
|
|
let feed = new Zotero.Feed();
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed.saveTx(), /^Feed name not set$/);
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
feed.name = 'Test ' + Zotero.randomString();
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed.saveTx(), /^Feed URL not set$/);
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
feed = new Zotero.Feed();
|
|
|
|
feed.url = 'http://' + Zotero.randomString() + '.com';
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed.saveTx(), /^Feed name not set$/);
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
it("should not allow saving a feed with the same url", function *() {
|
|
|
|
let url = 'http://' + Zotero.randomString() + '.com';
|
|
|
|
let feed1 = yield createFeed({ url });
|
|
|
|
|
|
|
|
let feed2 = new Zotero.Feed({ name: 'Test ' + Zotero.randomString(), url });
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed2.saveTx(), /^Feed for URL already exists: /);
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
// Perform check with normalized URL
|
|
|
|
feed2.url = url + '/';
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed2.saveTx(), /^Feed for URL already exists: /);
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
feed2.url = url.toUpperCase();
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(feed2.saveTx(), /^Feed for URL already exists: /);
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
it("should allow saving a feed with the same name", function *() {
|
|
|
|
let name = 'Test ' + Zotero.randomString();
|
|
|
|
let feed1 = yield createFeed({ name });
|
|
|
|
|
|
|
|
let feed2 = new Zotero.Feed({ name , url: 'http://' + Zotero.randomString() + '.com' });
|
|
|
|
|
|
|
|
yield assert.isFulfilled(feed2.saveTx(), "allow saving feed with an existing name");
|
|
|
|
|
|
|
|
assert.equal(feed1.name, feed2.name, "feed names remain the same");
|
|
|
|
});
|
|
|
|
it("should save field to DB after editing", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
|
|
|
|
feed.name = 'bar';
|
|
|
|
yield feed.saveTx();
|
|
|
|
|
|
|
|
let dbVal = yield Zotero.DB.valueQueryAsync('SELECT name FROM feeds WHERE libraryID=?', feed.libraryID);
|
|
|
|
assert.equal(feed.name, 'bar');
|
|
|
|
assert.equal(dbVal, feed.name);
|
|
|
|
});
|
2016-02-11 11:02:38 +00:00
|
|
|
it("should add a new synced setting after creation", function* () {
|
|
|
|
let url = 'http://' + Zotero.Utilities.randomString(10, 'abcde') + '.com/feed.rss';
|
|
|
|
|
|
|
|
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.notOk(syncedFeeds[url]);
|
|
|
|
|
|
|
|
yield createFeed({url});
|
|
|
|
|
|
|
|
syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.ok(syncedFeeds[url]);
|
|
|
|
});
|
|
|
|
it("should remove previous feed and add a new one if url changed", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
|
|
|
|
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.ok(syncedFeeds[feed.url]);
|
|
|
|
|
|
|
|
let oldUrl = feed.url;
|
|
|
|
feed.url = 'http://' + Zotero.Utilities.randomString(10, 'abcde') + '.com/feed.rss';
|
|
|
|
yield feed.saveTx();
|
|
|
|
|
|
|
|
syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.notOk(syncedFeeds[oldUrl]);
|
|
|
|
assert.ok(syncedFeeds[feed.url]);
|
|
|
|
});
|
2016-12-13 14:07:43 +00:00
|
|
|
it('should update syncedSettings if `name`, `url`, `refreshInterval` or `cleanupUnreadAfter` was modified', function* () {
|
2016-09-22 08:05:30 +00:00
|
|
|
let feed = yield createFeed();
|
|
|
|
let syncedSetting = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
yield Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, 'feeds', syncedSetting, 0, true);
|
|
|
|
|
|
|
|
feed.name = "New name";
|
|
|
|
yield feed.saveTx();
|
|
|
|
assert.isFalse(Zotero.SyncedSettings.getMetadata(Zotero.Libraries.userLibraryID, 'feeds').synced)
|
|
|
|
});
|
2016-12-13 14:07:43 +00:00
|
|
|
it('should not update syncedSettings if `name`, `url`, `refreshInterval` or `cleanupUnreadAfter` were not modified', function* () {
|
2016-09-22 08:05:30 +00:00
|
|
|
let feed = yield createFeed();
|
|
|
|
let syncedSetting = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
yield Zotero.SyncedSettings.set(Zotero.Libraries.userLibraryID, 'feeds', syncedSetting, 0, true);
|
|
|
|
|
|
|
|
feed._set('_feedLastCheck', Zotero.Date.dateToSQL(new Date(), true));
|
|
|
|
yield feed.saveTx();
|
|
|
|
assert.isTrue(Zotero.SyncedSettings.getMetadata(Zotero.Libraries.userLibraryID, 'feeds').synced)
|
|
|
|
});
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
describe("#erase()", function() {
|
|
|
|
it("should erase a saved feed", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
let id = feed.libraryID;
|
|
|
|
let url = feed.url;
|
|
|
|
|
|
|
|
yield feed.eraseTx();
|
|
|
|
|
|
|
|
assert.isFalse(Zotero.Libraries.exists(id));
|
|
|
|
assert.isFalse(Zotero.Feeds.existsByURL(url));
|
|
|
|
|
|
|
|
let dbValue = yield Zotero.DB.valueQueryAsync('SELECT COUNT(*) FROM feeds WHERE libraryID=?', id);
|
|
|
|
assert.equal(dbValue, '0');
|
|
|
|
});
|
|
|
|
it("should clear feedItems from cache", function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
|
|
|
|
let feedItem = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
|
|
|
assert.ok(yield Zotero.FeedItems.getAsync(feedItem.id));
|
|
|
|
|
|
|
|
yield feed.eraseTx();
|
|
|
|
|
|
|
|
assert.notOk(yield Zotero.FeedItems.getAsync(feedItem.id));
|
|
|
|
});
|
2016-02-11 11:02:38 +00:00
|
|
|
it("should remove synced settings", function* () {
|
|
|
|
let url = 'http://' + Zotero.Utilities.randomString(10, 'abcde') + '.com/feed.rss';
|
|
|
|
let feed = yield createFeed({url});
|
|
|
|
|
|
|
|
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.ok(syncedFeeds[feed.url]);
|
|
|
|
|
|
|
|
yield feed.eraseTx();
|
|
|
|
|
|
|
|
syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
|
|
|
assert.notOk(syncedFeeds[url]);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#storeSyncedSettings", function() {
|
2016-06-22 07:24:22 +00:00
|
|
|
it("should store settings for feed in compact format", function* () {
|
|
|
|
let url = 'http://' + Zotero.Utilities.randomString().toLowerCase() + '.com/feed.rss';
|
2016-12-13 14:07:43 +00:00
|
|
|
let settings = [Zotero.Utilities.randomString(), 1, 30, 1];
|
2016-06-22 07:24:22 +00:00
|
|
|
let feed = yield createFeed({
|
|
|
|
url,
|
|
|
|
name: settings[0],
|
2016-12-13 14:07:43 +00:00
|
|
|
cleanupReadAfter: settings[1],
|
|
|
|
cleanupUnreadAfter: settings[2],
|
|
|
|
refreshInterval: settings[3]
|
2016-06-22 07:24:22 +00:00
|
|
|
});
|
2016-02-11 11:02:38 +00:00
|
|
|
|
|
|
|
let syncedFeeds = Zotero.SyncedSettings.get(Zotero.Libraries.userLibraryID, 'feeds');
|
2016-06-22 07:24:22 +00:00
|
|
|
assert.deepEqual(syncedFeeds[url], settings);
|
2016-02-11 11:02:38 +00:00
|
|
|
});
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
|
2016-01-13 13:13:29 +00:00
|
|
|
describe("#clearExpiredItems()", function() {
|
2016-12-13 14:07:43 +00:00
|
|
|
var feed, readExpiredFI, unreadExpiredFI, readFeedItem, feedItem, readStillInFeed, feedItemIDs;
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
before(function* (){
|
2016-12-13 14:07:43 +00:00
|
|
|
feed = yield createFeed({cleanupReadAfter: 1, cleanupUnreadAfter: 3});
|
2016-01-13 13:13:29 +00:00
|
|
|
|
2016-12-13 14:07:43 +00:00
|
|
|
readExpiredFI = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
2016-01-13 13:13:29 +00:00
|
|
|
// Read 2 days ago
|
2016-12-13 14:07:43 +00:00
|
|
|
readExpiredFI.isRead = true;
|
|
|
|
readExpiredFI._feedItemReadTime = Zotero.Date.dateToSQL(
|
2016-01-13 13:13:29 +00:00
|
|
|
new Date(Date.now() - 2 * 24*60*60*1000), true);
|
2016-12-13 14:07:43 +00:00
|
|
|
yield readExpiredFI.saveTx();
|
|
|
|
|
|
|
|
// Added 5 days ago
|
|
|
|
unreadExpiredFI = yield createDataObject('feedItem', {
|
|
|
|
libraryID: feed.libraryID,
|
|
|
|
dateAdded: Zotero.Date.dateToSQL(new Date(Date.now() - 5 * 24*60*60*1000), true),
|
|
|
|
dateModified: Zotero.Date.dateToSQL(new Date(Date.now() - 5 * 24*60*60*1000), true)
|
|
|
|
});
|
|
|
|
yield unreadExpiredFI.saveTx();
|
2016-02-11 11:02:38 +00:00
|
|
|
|
|
|
|
readStillInFeed = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
|
|
|
// Read 2 days ago
|
|
|
|
readStillInFeed.isRead = true;
|
|
|
|
readStillInFeed._feedItemReadTime = Zotero.Date.dateToSQL(
|
|
|
|
new Date(Date.now() - 2 * 24*60*60*1000), true);
|
|
|
|
yield readStillInFeed.saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
readFeedItem = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
|
|
|
readFeedItem.isRead = true;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield readFeedItem.saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
feedItem = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
|
|
|
|
|
|
|
feedItemIDs = yield Zotero.FeedItems.getAll(feed.libraryID).map((row) => row.id);
|
|
|
|
|
|
|
|
assert.include(feedItemIDs, feedItem.id, "feed contains unread feed item");
|
|
|
|
assert.include(feedItemIDs, readFeedItem.id, "feed contains read feed item");
|
2016-12-13 14:07:43 +00:00
|
|
|
assert.include(feedItemIDs, readExpiredFI.id, "feed contains expired feed item");
|
2016-02-11 11:02:38 +00:00
|
|
|
assert.include(feedItemIDs, readStillInFeed.id, "feed contains expired but still in rss feed item");
|
2016-01-13 13:13:29 +00:00
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
yield feed.clearExpiredItems(new Set([readStillInFeed.id]));
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
feedItemIDs = yield Zotero.FeedItems.getAll(feed.libraryID).map((row) => row.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should clear expired items', function() {
|
2016-12-13 14:07:43 +00:00
|
|
|
assert.notInclude(feedItemIDs, readExpiredFI.id, "feed no longer contains expired read feed item");
|
|
|
|
assert.notInclude(feedItemIDs, unreadExpiredFI.id, "feed no longer contains expired feed item");
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not clear read items that have not expired yet', function() {
|
|
|
|
assert.include(feedItemIDs, readFeedItem.id, "feed still contains new feed item");
|
2016-02-11 11:02:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not clear read items that are still in rss', function() {
|
|
|
|
assert.include(feedItemIDs, readStillInFeed.id, "feed still contains read still in rss feed item");
|
|
|
|
});
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
it('should not clear unread items', function() {
|
|
|
|
assert.include(feedItemIDs, feedItem.id, "feed still contains new feed item");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#updateFeed()', function() {
|
2016-09-22 08:05:30 +00:00
|
|
|
var feed, scheduleNextFeedCheck;
|
2016-02-11 11:02:38 +00:00
|
|
|
var feedUrl = getTestDataUrl("feed.rss");
|
|
|
|
var modifiedFeedUrl = getTestDataUrl("feedModified.rss");
|
2021-05-22 17:44:42 +00:00
|
|
|
var win;
|
2016-01-13 13:13:29 +00:00
|
|
|
|
2021-05-22 17:44:42 +00:00
|
|
|
before(async function() {
|
|
|
|
// Browser window is needed as parent window to load the feed reader scripts.
|
|
|
|
win = await loadBrowserWindow();
|
2017-06-19 04:53:08 +00:00
|
|
|
scheduleNextFeedCheck = sinon.stub(Zotero.Feeds, 'scheduleNextFeedCheck').resolves();
|
2016-09-22 08:05:30 +00:00
|
|
|
});
|
|
|
|
|
2016-02-05 18:29:15 +00:00
|
|
|
beforeEach(function* (){
|
2017-06-19 04:53:08 +00:00
|
|
|
scheduleNextFeedCheck.resetHistory();
|
2016-02-05 18:29:15 +00:00
|
|
|
feed = yield createFeed();
|
|
|
|
feed._feedUrl = feedUrl;
|
|
|
|
yield feed.updateFeed();
|
|
|
|
});
|
|
|
|
|
2016-01-13 13:13:29 +00:00
|
|
|
afterEach(function* () {
|
|
|
|
yield clearFeeds();
|
|
|
|
});
|
|
|
|
|
2017-06-01 19:30:06 +00:00
|
|
|
after(function() {
|
2021-05-22 17:44:42 +00:00
|
|
|
if (win) {
|
|
|
|
win.close();
|
|
|
|
}
|
2017-06-01 19:30:06 +00:00
|
|
|
scheduleNextFeedCheck.restore();
|
|
|
|
});
|
|
|
|
|
2016-01-13 13:13:29 +00:00
|
|
|
it('should schedule next feed check', function* () {
|
|
|
|
let feed = yield createFeed();
|
|
|
|
feed._feedUrl = feedUrl;
|
|
|
|
yield feed.updateFeed();
|
|
|
|
assert.equal(scheduleNextFeedCheck.called, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should add new feed items', function* () {
|
2016-02-11 11:02:38 +00:00
|
|
|
let feedItems = yield Zotero.FeedItems.getAll(feed.id, true);
|
2016-02-05 18:29:15 +00:00
|
|
|
assert.equal(feedItems.length, 3);
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
it('should set lastCheck and lastUpdated values', function* () {
|
|
|
|
yield clearFeeds();
|
2016-01-13 13:13:29 +00:00
|
|
|
let feed = yield createFeed();
|
|
|
|
feed._feedUrl = feedUrl;
|
|
|
|
|
|
|
|
assert.notOk(feed.lastCheck);
|
|
|
|
assert.notOk(feed.lastUpdate);
|
|
|
|
|
|
|
|
yield feed.updateFeed();
|
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
assert.isTrue(feed.lastCheck > Zotero.Date.dateToSQL(new Date(Date.now() - 1000*60), true), 'feed.lastCheck updated');
|
|
|
|
assert.isTrue(feed.lastUpdate > Zotero.Date.dateToSQL(new Date(Date.now() - 1000*60), true), 'feed.lastUpdate updated');
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
2021-11-06 03:16:12 +00:00
|
|
|
it('should update modified items, preserving isRead', function* () {
|
2016-02-11 11:02:38 +00:00
|
|
|
let feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
|
2016-01-13 13:13:29 +00:00
|
|
|
feedItem.isRead = true;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield feedItem.saveTx();
|
|
|
|
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
|
2016-01-13 13:13:29 +00:00
|
|
|
assert.isTrue(feedItem.isRead);
|
|
|
|
|
2016-02-05 18:29:15 +00:00
|
|
|
let oldDateModified = feedItem.getField('date');
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
feed._feedUrl = modifiedFeedUrl;
|
|
|
|
yield feed.updateFeed();
|
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
|
2016-01-13 13:13:29 +00:00
|
|
|
|
2016-02-05 18:29:15 +00:00
|
|
|
assert.notEqual(oldDateModified, feedItem.getField('date'));
|
2021-11-06 03:16:12 +00:00
|
|
|
assert.isTrue(feedItem.isRead);
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
|
|
|
it('should skip items that are not modified', function* () {
|
2016-02-05 18:29:15 +00:00
|
|
|
let save = sinon.spy(Zotero.FeedItem.prototype, 'save');
|
|
|
|
|
|
|
|
feed._feedUrl = modifiedFeedUrl;
|
2016-01-13 13:13:29 +00:00
|
|
|
yield feed.updateFeed();
|
2016-02-05 18:29:15 +00:00
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
assert.equal(save.thisValues[0].guid, "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
|
2016-02-05 18:29:15 +00:00
|
|
|
save.restore();
|
|
|
|
});
|
|
|
|
it('should update unread count', function* () {
|
|
|
|
assert.equal(feed.unreadCount, 3);
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
let feedItems = yield Zotero.FeedItems.getAll(feed.id);
|
2016-02-05 18:29:15 +00:00
|
|
|
for (let feedItem of feedItems) {
|
|
|
|
feedItem.isRead = true;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield feedItem.saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
feed._feedUrl = modifiedFeedUrl;
|
|
|
|
yield feed.updateFeed();
|
|
|
|
|
2021-11-06 03:16:12 +00:00
|
|
|
assert.equal(feed.unreadCount, 1);
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
2016-02-11 11:02:38 +00:00
|
|
|
it('should add a link to enclosed pdfs from <enclosure/> elements', function* () {
|
|
|
|
let feedItem = yield Zotero.FeedItems.getAsyncByGUID("http://liftoff.msfc.nasa.gov/2003/06/03.html#item573");
|
|
|
|
let pdf = yield Zotero.Items.getAsync(feedItem.getAttachments()[0]);
|
2016-01-13 13:13:29 +00:00
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
assert.equal(pdf.getField('url'), "http://www.example.com/example.pdf");
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-02 04:29:40 +00:00
|
|
|
describe("Adding items", function() {
|
|
|
|
let feed;
|
|
|
|
before(function* () {
|
|
|
|
feed = yield createFeed();
|
|
|
|
})
|
|
|
|
it("should not allow adding collections", function* () {
|
|
|
|
let collection = new Zotero.Collection({ name: 'test', libraryID: feed.libraryID });
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(collection.saveTx({ skipEditCheck: true }), /^Cannot add /);
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
it("should not allow adding saved search", function* () {
|
|
|
|
let search = new Zotero.Search({ name: 'test', libraryID: feed.libraryID });
|
2017-05-31 15:52:06 +00:00
|
|
|
yield assert.isRejected(search.saveTx({ skipEditCheck: true }), /^Cannot add /);
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
it("should allow adding feed item", function* () {
|
|
|
|
let feedItem = new Zotero.FeedItem('book', { guid: Zotero.randomString() });
|
|
|
|
feedItem.libraryID = feed.libraryID;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield assert.isFulfilled(feedItem.saveTx());
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|