2015-06-02 04:29:40 +00:00
|
|
|
describe("Zotero.FeedItems", function () {
|
|
|
|
let feed;
|
2016-01-13 13:13:29 +00:00
|
|
|
before(function* () {
|
|
|
|
feed = yield createFeed({ name: 'foo', url: 'http://' + Zotero.randomString() + '.com' });
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
after(function() {
|
2016-01-13 13:13:29 +00:00
|
|
|
return clearFeeds();
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
describe("#getMarkedAsRead", function() {
|
|
|
|
var items = [];
|
|
|
|
var result;
|
2020-12-28 04:41:12 +00:00
|
|
|
|
|
|
|
before(async function () {
|
2016-02-11 11:02:38 +00:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2020-12-28 04:41:12 +00:00
|
|
|
let f = await createDataObject(
|
|
|
|
'feedItem',
|
|
|
|
{
|
|
|
|
libraryID: feed.libraryID,
|
|
|
|
guid: 'http://www.example.com/' + i
|
|
|
|
}
|
|
|
|
);
|
2016-02-11 11:02:38 +00:00
|
|
|
items.push(f);
|
|
|
|
}
|
2020-12-28 04:41:12 +00:00
|
|
|
await items[0].toggleRead();
|
|
|
|
await items[2].toggleRead();
|
|
|
|
result = (await Zotero.FeedItems.getMarkedAsRead(feed.libraryID)).map(x => x.id);
|
2016-02-11 11:02:38 +00:00
|
|
|
});
|
2020-12-28 04:41:12 +00:00
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
it('should get all marked as read items', function() {
|
2020-12-28 04:41:12 +00:00
|
|
|
assert.include(result, items[0].id);
|
|
|
|
assert.include(result, items[2].id);
|
2016-02-11 11:02:38 +00:00
|
|
|
});
|
2020-12-28 04:41:12 +00:00
|
|
|
|
2016-02-11 11:02:38 +00:00
|
|
|
it('should not include items that were not marked', function() {
|
2020-12-28 04:41:12 +00:00
|
|
|
assert.notInclude(result, items[1].id);
|
|
|
|
assert.notInclude(result, items[3].id);
|
2016-02-11 11:02:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("#markAsReadByGUID", function() {
|
|
|
|
var items = [];
|
|
|
|
var result;
|
|
|
|
before(function* () {
|
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
|
let f = yield createDataObject('feedItem', {
|
|
|
|
libraryID: feed.libraryID,
|
|
|
|
guid: 'http://' + Zotero.Utilities.randomString() + '.com/feed.rss'
|
|
|
|
});
|
|
|
|
items.push(f);
|
|
|
|
}
|
|
|
|
yield Zotero.FeedItems.markAsReadByGUID([items[0].guid, items[2].guid]);
|
|
|
|
});
|
|
|
|
it('should mark as read only specified guids', function() {
|
|
|
|
assert.isTrue(items[0].isRead);
|
|
|
|
assert.isTrue(items[2].isRead);
|
|
|
|
});
|
|
|
|
it('should leave other items marked unread', function() {
|
|
|
|
assert.isFalse(items[1].isRead);
|
|
|
|
assert.isFalse(items[3].isRead);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-06-02 04:29:40 +00:00
|
|
|
describe("#getIDFromGUID()", function() {
|
|
|
|
it("should return false for non-existent GUID", function* () {
|
|
|
|
let id = yield Zotero.FeedItems.getIDFromGUID(Zotero.randomString());
|
|
|
|
assert.isFalse(id);
|
|
|
|
});
|
|
|
|
it("should return feed item id from GUID", function* () {
|
|
|
|
let feedItem = yield createDataObject('feedItem', { libraryID: feed.libraryID });
|
2016-02-11 11:02:38 +00:00
|
|
|
yield feedItem.saveTx();
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
let id2 = yield Zotero.FeedItems.getIDFromGUID(feedItem.guid);
|
|
|
|
assert.equal(id2, feedItem.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("#getAsyncByGUID()", function() {
|
|
|
|
it("should return feed item from GUID", function* () {
|
|
|
|
let guid = Zotero.randomString();
|
|
|
|
let feedItem = yield createDataObject('feedItem', { guid, libraryID: feed.libraryID });
|
2016-02-11 11:02:38 +00:00
|
|
|
yield feedItem.saveTx();
|
2015-06-02 04:29:40 +00:00
|
|
|
|
|
|
|
let feedItem2 = yield Zotero.FeedItems.getAsyncByGUID(guid);
|
|
|
|
assert.equal(feedItem2.id, feedItem.id);
|
|
|
|
});
|
|
|
|
it("should return false for non-existent GUID", function* () {
|
|
|
|
let feedItem = yield Zotero.FeedItems.getAsyncByGUID(Zotero.randomString());
|
|
|
|
assert.isFalse(feedItem);
|
|
|
|
});
|
|
|
|
});
|
2016-01-13 13:13:29 +00:00
|
|
|
describe("#toggleReadByID()", function() {
|
|
|
|
var save, feed, items, ids;
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
save = sinon.spy(Zotero.FeedItem.prototype, 'save');
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function* (){
|
|
|
|
feed = yield createFeed();
|
|
|
|
|
|
|
|
items = [];
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
let item = yield createDataObject('feedItem', { guid: Zotero.randomString(), libraryID: feed.id });
|
|
|
|
item.isRead = true;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield item.saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
items.push(item);
|
|
|
|
}
|
2022-06-19 19:09:12 +00:00
|
|
|
ids = items.map(i => i.id);
|
2016-01-13 13:13:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function* () {
|
2019-05-25 11:28:28 +00:00
|
|
|
save.resetHistory();
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
yield clearFeeds();
|
|
|
|
});
|
2017-06-01 19:30:06 +00:00
|
|
|
|
|
|
|
after(function() {
|
|
|
|
save.restore();
|
|
|
|
});
|
|
|
|
|
2016-01-13 13:13:29 +00:00
|
|
|
it('should toggle all items read if at least one unread', function* () {
|
|
|
|
items[0].isRead = false;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield items[0].saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
yield Zotero.FeedItems.toggleReadByID(ids);
|
|
|
|
|
|
|
|
for(let i = 0; i < 10; i++) {
|
|
|
|
assert.isTrue(save.thisValues[i].isRead, "#toggleRead called with true");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should toggle all items unread if all read', function* () {
|
|
|
|
yield Zotero.FeedItems.toggleReadByID(ids);
|
|
|
|
|
|
|
|
for(let i = 0; i < 10; i++) {
|
|
|
|
assert.isFalse(save.thisValues[i].isRead, "#toggleRead called with false");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should toggle all items unread if unread state specified', function* () {
|
|
|
|
items[0].isRead = false;
|
2016-02-11 11:02:38 +00:00
|
|
|
yield items[0].saveTx();
|
2016-01-13 13:13:29 +00:00
|
|
|
|
|
|
|
yield Zotero.FeedItems.toggleReadByID(ids, false);
|
|
|
|
|
|
|
|
for(let i = 0; i < 10; i++) {
|
|
|
|
assert.isFalse(save.thisValues[i].isRead, "#toggleRead called with true");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2015-06-02 04:29:40 +00:00
|
|
|
});
|