Adds Zotero.FeedReader tests
This commit is contained in:
parent
2d46e3d59b
commit
8a2dc6e7f2
8 changed files with 775 additions and 464 deletions
167
test/tests/feedReaderTest.js
Normal file
167
test/tests/feedReaderTest.js
Normal file
|
@ -0,0 +1,167 @@
|
|||
"use strict";
|
||||
|
||||
describe("Zotero.FeedReader", function () {
|
||||
|
||||
var htmlUrl = getTestDataItemUrl("test.html");
|
||||
|
||||
var feedUrl = getTestDataItemUrl("feed.rss");
|
||||
var feedInfo = {
|
||||
title: 'Liftoff News',
|
||||
subtitle: 'Liftoff to Space Exploration.',
|
||||
updated: new Date("Tue, 10 Jun 2003 09:41:01 GMT"),
|
||||
creators: [{
|
||||
firstName: '',
|
||||
lastName: 'editor@example.com',
|
||||
creatorType: 'author',
|
||||
fieldMode: 1
|
||||
}],
|
||||
language: 'en-us'
|
||||
};
|
||||
|
||||
var detailedFeedUrl = getTestDataItemUrl("feedDetailed.rss");
|
||||
var detailedFeedInfo = {
|
||||
title: 'Feed',
|
||||
subtitle: 'Feed Description',
|
||||
creators: [{firstName: 'Feed', lastName: 'Author', creatorType: 'author'}],
|
||||
publicationTitle: 'Publication',
|
||||
publisher: 'Publisher',
|
||||
rights: '©2016 Published by Publisher',
|
||||
ISSN: '0000-0000',
|
||||
language: 'en'
|
||||
};
|
||||
|
||||
describe('FeedReader()', function () {
|
||||
it('should throw if url not provided', function() {
|
||||
assert.throw(() => new Zotero.FeedReader())
|
||||
});
|
||||
|
||||
it('should throw if url invalid', function() {
|
||||
assert.throw(() => new Zotero.FeedReader('invalid url'))
|
||||
});
|
||||
});
|
||||
|
||||
describe('#process()', function() {
|
||||
it('should reject if the provided url is not a valid feed', function* () {
|
||||
let fr = new Zotero.FeedReader(htmlUrl);
|
||||
let e = yield getPromiseError(fr.process());
|
||||
assert.ok(e);
|
||||
e = yield getPromiseError(fr._feedItems[fr._feedItems.length-1].promise);
|
||||
assert.ok(e);
|
||||
});
|
||||
|
||||
it('should set #feedProperties on FeedReader object', function* () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
assert.throw(() => fr.feedProperties);
|
||||
yield fr.process();
|
||||
assert.ok(fr.feedProperties);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#terminate()', function() {
|
||||
it('should reject last feed item and feed processing promise if feed not processed yet', function* () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
fr.terminate("test");
|
||||
let e = yield getPromiseError(fr.process());
|
||||
assert.ok(e);
|
||||
e = yield getPromiseError(fr._feedItems[fr._feedItems.length-1].promise);
|
||||
assert.ok(e);
|
||||
});
|
||||
|
||||
it('should reject last feed item if feed processed', function* () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
yield fr.process();
|
||||
fr.terminate("test");
|
||||
let e = yield getPromiseError(fr._feedItems[fr._feedItems.length-1].promise);
|
||||
assert.ok(e);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#feedProperties', function() {
|
||||
it('should throw if accessed before feed is processed', function () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
assert.throw(() => fr.feedProperties);
|
||||
});
|
||||
|
||||
it('should have correct values for a sparse feed', function* () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
yield fr.process();
|
||||
assert.deepEqual(fr.feedProperties, feedInfo);
|
||||
});
|
||||
|
||||
it('should have correct values for a detailed feed', function* () {
|
||||
let fr = new Zotero.FeedReader(detailedFeedUrl);
|
||||
yield fr.process();
|
||||
assert.deepEqual(fr.feedProperties, detailedFeedInfo);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ItemIterator()', function() {
|
||||
it('should throw if called before feed is resolved', function() {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
assert.throw(() => new fr.ItemIterator);
|
||||
});
|
||||
|
||||
it('should parse items correctly for a sparse feed', function* () {
|
||||
let expected = {
|
||||
guid: 'http://liftoff.msfc.nasa.gov/2003/06/03.html#item573',
|
||||
title: 'Star City',
|
||||
abstractNote: 'How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia\'s Star City.',
|
||||
url: 'http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp',
|
||||
dateModified: '2003-06-03 09:39:21',
|
||||
date: '2003-06-03 09:39:21',
|
||||
creators: [{
|
||||
firstName: '',
|
||||
lastName: 'editor@example.com',
|
||||
creatorType: 'author',
|
||||
fieldMode: 1
|
||||
}],
|
||||
language: 'en-us',
|
||||
itemType: 'journalArticle'
|
||||
};
|
||||
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
yield fr.process();
|
||||
let itemIterator = new fr.ItemIterator();
|
||||
let item = yield itemIterator.next().value;
|
||||
assert.deepEqual(item, expected);
|
||||
});
|
||||
|
||||
it('should parse items correctly for a detailed feed', function* () {
|
||||
let expected = { guid: 'http://www.example.com/item1',
|
||||
title: 'Title 1',
|
||||
abstractNote: 'Description 1',
|
||||
url: 'http://www.example.com/item1',
|
||||
dateModified: '2016-01-07 00:00:00',
|
||||
date: '2016-01-07',
|
||||
creators: [
|
||||
{ firstName: 'Author1 A. T.', lastName: 'Rohtua', creatorType: 'author' },
|
||||
{ firstName: 'Author2 A.', lastName: 'Auth', creatorType: 'author' },
|
||||
{ firstName: 'Author3', lastName: 'Autho', creatorType: 'author' },
|
||||
{ firstName: 'Contributor1 A. T.', lastName: 'Rotubirtnoc', creatorType: 'contributor' },
|
||||
{ firstName: 'Contributor2 C.', lastName: 'Contrib', creatorType: 'contributor' },
|
||||
{ firstName: 'Contributor3', lastName: 'Contr', creatorType: 'contributor' }
|
||||
],
|
||||
publicationTitle: 'Publication',
|
||||
ISSN: '0000-0000',
|
||||
publisher: 'Publisher',
|
||||
rights: '©2016 Published by Publisher',
|
||||
language: 'en',
|
||||
itemType: 'journalArticle'
|
||||
};
|
||||
|
||||
let fr = new Zotero.FeedReader(detailedFeedUrl);
|
||||
yield fr.process();
|
||||
let itemIterator = new fr.ItemIterator();
|
||||
let item = yield itemIterator.next().value;
|
||||
assert.deepEqual(item, expected);
|
||||
});
|
||||
it('should resolve last item with null', function* () {
|
||||
let fr = new Zotero.FeedReader(feedUrl);
|
||||
yield fr.process();
|
||||
let itemIterator = new fr.ItemIterator();
|
||||
let item;
|
||||
while(item = yield itemIterator.next().value);
|
||||
assert.isNull(item);
|
||||
});
|
||||
});
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue