-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved testing. Fixed feed updating.
- Loading branch information
Showing
9 changed files
with
220 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// vim: set ts=4 sw=4: | ||
|
||
const { Feed } = require('../www/assets/js/feed'); | ||
const { Item } = require('../www/assets/js/item'); | ||
const { TestData } = require('./testdata.js') | ||
|
||
const mockFeed = new Feed({ items: [ | ||
new Item({ id: 100, read: true }), | ||
new Item({ id: 101, read: true }), | ||
new Item({ id: 102, read: true }), | ||
new Item({ id: 103 }), | ||
new Item({ id: 104 }) | ||
]}); | ||
|
||
test('Feed.getNextUnread', async () => { | ||
expect(mockFeed.getNextUnread(0).id == 103).toBe(true); | ||
expect(mockFeed.getNextUnread(102).id == 103).toBe(true); | ||
expect(mockFeed.getNextUnread(103).id == 104).toBe(true); | ||
expect(mockFeed.getNextUnread(104).id == 103).toBe(true); | ||
}); | ||
|
||
test('Feed.update', async () => { | ||
await TestData.slashdotFeed.update(); | ||
expect(TestData.slashdotFeed.last_updated > 0).toBe(true); | ||
expect(TestData.slashdotFeed.items.length).toBe(1); | ||
expect(TestData.slashdotFeed.description).toBe('News for nerds, stuff that matters'); | ||
expect(TestData.slashdotFeed.icon).toBe('https://slashdot.org//favicon.ico'); | ||
expect(TestData.slashdotFeed.getItemById(105).title).toBe('WordPress Blogs Can Now Be Followed in the Fediverse, Including Mastodon'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,73 +4,7 @@ window.Handlebars = require('handlebars'); | |
|
||
const { Feed } = require('../www/assets/js/feed'); | ||
const { FeedList } = require('../www/assets/js/feedlist'); | ||
|
||
global['fetch'] = jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
text: () => Promise.resolve(`<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<rdf:RDF | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns="http://purl.org/rss/1.0/" | ||
xmlns:admin="http://webns.net/mvcb/" | ||
xmlns:content="http://purl.org/rss/1.0/modules/content/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" | ||
xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" | ||
xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" | ||
> | ||
<channel rdf:about="https://slashdot.org/"> | ||
<title>Slashdot</title> | ||
<link>https://slashdot.org/</link> | ||
<description>News for nerds, stuff that matters</description> | ||
<dc:language>en-us</dc:language> | ||
<dc:rights>Copyright 1997-2016, SlashdotMedia. All Rights Reserved.</dc:rights> | ||
<dc:date>2023-09-17T15:35:11+00:00</dc:date> | ||
<dc:publisher>Dice</dc:publisher> | ||
<dc:creator>[email protected]</dc:creator> | ||
<dc:subject>Technology</dc:subject> | ||
<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase> | ||
<syn:updateFrequency>1</syn:updateFrequency> | ||
<syn:updatePeriod>hourly</syn:updatePeriod> | ||
<items> | ||
<rdf:Seq> | ||
<rdf:li rdf:resource="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed" /> | ||
</rdf:Seq> | ||
</items> | ||
<image rdf:resource="https://a.fsdn.com/sd/topics/topicslashdot.gif" /> | ||
<textinput rdf:resource="https://slashdot.org/search.pl" /> | ||
</channel> | ||
<image rdf:about="https://a.fsdn.com/sd/topics/topicslashdot.gif"> | ||
<title>Slashdot</title> | ||
<url>https://a.fsdn.com/sd/topics/topicslashdot.gif</url> | ||
<link>https://slashdot.org/</link> | ||
</image> | ||
<item rdf:about="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed"> | ||
<title>WordPress Blogs Can Now Be Followed in the Fediverse, Including Mastodon</title> | ||
<link>https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed</link> | ||
<description>An anonymous reader shared this report from TechCrunch: | ||
In March, WordPress.com owner Automattic made a commitment to the fediverse &mdash; the decentralized social networks that include the Twitter rival Mastodon and others &mdash; with the acquisition of an ActivityPub plug-in that allows WordPress blogs to reach readers on other federated platforms. Now, the company is announcing ActivityPub 1.0.0 for WordPress has been released allowing WordPress blogs to be followed by others on apps like Mastodon and others in the fediverse and then receive replies back as comments on their own sites. | ||
Since the acquisition, the company has improved on the original software in a number of ways, including by now allowing the ability to add blog-wide catchall accounts instead of only per-author. It also introduced the ability to add a "follow me" block to help visitors follow your profile and a "followers" block to show off your followers, noted Automattic design engineer Matt Wiebe, in a post on X... For the time being, the software supports self-hosted WordPress blogs, but Wiebe teased that support for WordPress.com blogs was "coming soon." | ||
load | ||
</div></p><p><a href="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0moreanon&amp;utm_medium=feed">Read more of this story</a> at Slashdot.</p><iframe src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;id=23062688&amp;smallembed=1" style="height: 300px; width: 100%; border: none;"></iframe></description> | ||
<dc:creator>EditorDavid</dc:creator> | ||
<dc:date>2023-09-17T15:34:00+00:00</dc:date> | ||
<dc:subject>social</dc:subject> | ||
<slash:department>collating-comments</slash:department> | ||
<slash:section>technology</slash:section> | ||
<slash:hit_parade>0,0,0,0,0,0,0</slash:hit_parade> | ||
</item> | ||
</rdf:RDF>`), | ||
}) | ||
); | ||
|
||
DB.testDisable = true; // DB won't do anything | ||
const { TestData } = require('./testdata.js'); | ||
|
||
const mockFeedlistChildren = [ | ||
new Feed({ title: 'abc', id: 1, unreadCount: 0 }), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,15 @@ | ||
// vim: set ts=4 sw=4: | ||
|
||
import { Feed } from '../www/assets/js/feed' | ||
import { FeedUpdater } from '../www/assets/js/feedupdater'; | ||
|
||
global['fetch'] = jest.fn().mockImplementation(() => | ||
Promise.resolve({ | ||
text: () => Promise.resolve(`<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<rdf:RDF | ||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
xmlns="http://purl.org/rss/1.0/" | ||
xmlns:admin="http://webns.net/mvcb/" | ||
xmlns:content="http://purl.org/rss/1.0/modules/content/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" | ||
xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" | ||
xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" | ||
> | ||
<channel rdf:about="https://slashdot.org/"> | ||
<title>Slashdot</title> | ||
<link>https://slashdot.org/</link> | ||
<description>News for nerds, stuff that matters</description> | ||
<dc:language>en-us</dc:language> | ||
<dc:rights>Copyright 1997-2016, SlashdotMedia. All Rights Reserved.</dc:rights> | ||
<dc:date>2023-09-17T15:35:11+00:00</dc:date> | ||
<dc:publisher>Dice</dc:publisher> | ||
<dc:creator>[email protected]</dc:creator> | ||
<dc:subject>Technology</dc:subject> | ||
<syn:updateBase>1970-01-01T00:00+00:00</syn:updateBase> | ||
<syn:updateFrequency>1</syn:updateFrequency> | ||
<syn:updatePeriod>hourly</syn:updatePeriod> | ||
<items> | ||
<rdf:Seq> | ||
<rdf:li rdf:resource="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed" /> | ||
</rdf:Seq> | ||
</items> | ||
<image rdf:resource="https://a.fsdn.com/sd/topics/topicslashdot.gif" /> | ||
<textinput rdf:resource="https://slashdot.org/search.pl" /> | ||
</channel> | ||
<image rdf:about="https://a.fsdn.com/sd/topics/topicslashdot.gif"> | ||
<title>Slashdot</title> | ||
<url>https://a.fsdn.com/sd/topics/topicslashdot.gif</url> | ||
<link>https://slashdot.org/</link> | ||
</image> | ||
<item rdf:about="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed"> | ||
<title>WordPress Blogs Can Now Be Followed in the Fediverse, Including Mastodon</title> | ||
<link>https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0mainlinkanon&utm_medium=feed</link> | ||
<description>An anonymous reader shared this report from TechCrunch: | ||
In March, WordPress.com owner Automattic made a commitment to the fediverse &mdash; the decentralized social networks that include the Twitter rival Mastodon and others &mdash; with the acquisition of an ActivityPub plug-in that allows WordPress blogs to reach readers on other federated platforms. Now, the company is announcing ActivityPub 1.0.0 for WordPress has been released allowing WordPress blogs to be followed by others on apps like Mastodon and others in the fediverse and then receive replies back as comments on their own sites. | ||
Since the acquisition, the company has improved on the original software in a number of ways, including by now allowing the ability to add blog-wide catchall accounts instead of only per-author. It also introduced the ability to add a "follow me" block to help visitors follow your profile and a "followers" block to show off your followers, noted Automattic design engineer Matt Wiebe, in a post on X... For the time being, the software supports self-hosted WordPress blogs, but Wiebe teased that support for WordPress.com blogs was "coming soon." | ||
Last year Automattic's CEO Matt Mullenweg announced Tumblr would add support for ActivityPub, the article adds. "But more recently, Mullenweg told us he's been investigating not only ActivityPub, but also other protocols like Nostr and Bluesky's AT Protocol."<p><div class="share_submission" style="position:relative;"> | ||
<a class="slashpop" href="http://twitter.com/home?status=WordPress+Blogs+Can+Now+Be+Followed+in+the+Fediverse%2C+Including+Mastodon%3A+https%3A%2F%2Ftech.slashdot.org%2Fstory%2F23%2F09%2F16%2F2226218%2F%3Futm_source%3Dtwitter%26utm_medium%3Dtwitter"><img src="https://a.fsdn.com/sd/twitter_icon_large.png"></a> | ||
<a class="slashpop" href="http://www.facebook.com/sharer.php?u=https%3A%2F%2Ftech.slashdot.org%2Fstory%2F23%2F09%2F16%2F2226218%2Fwordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon%3Futm_source%3Dslashdot%26utm_medium%3Dfacebook"><img src="https://a.fsdn.com/sd/facebook_icon_large.png"></a> | ||
</div></p><p><a href="https://tech.slashdot.org/story/23/09/16/2226218/wordpress-blogs-can-now-be-followed-in-the-fediverse-including-mastodon?utm_source=rss1.0moreanon&amp;utm_medium=feed">Read more of this story</a> at Slashdot.</p><iframe src="https://slashdot.org/slashdot-it.pl?op=discuss&amp;id=23062688&amp;smallembed=1" style="height: 300px; width: 100%; border: none;"></iframe></description> | ||
<dc:creator>EditorDavid</dc:creator> | ||
<dc:date>2023-09-17T15:34:00+00:00</dc:date> | ||
<dc:subject>social</dc:subject> | ||
<slash:department>collating-comments</slash:department> | ||
<slash:section>technology</slash:section> | ||
<slash:hit_parade>0,0,0,0,0,0,0</slash:hit_parade> | ||
</item> | ||
</rdf:RDF>`), | ||
}) | ||
); | ||
import { TestData } from './testdata.js'; | ||
|
||
test('FeedUpdater.fetch', async () => { | ||
let f = await FeedUpdater.fetch('http://rss.slashdot.org/Slashdot/slashdotMain'); | ||
expect(f !== undefined).toBe(true); | ||
expect(f.title).toBe('Slashdot'); | ||
expect(f.source).toBe('http://rss.slashdot.org/Slashdot/slashdotMain'); | ||
expect(f.last_updated - Date.now() / 1000 < 10000).toBe(true); | ||
expect(f.error).toBe(Feed.ERROR_NONE); | ||
expect(f.items[0].title).toBe('WordPress Blogs Can Now Be Followed in the Fediverse, Including Mastodon'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// vim: set ts=4 sw=4: | ||
|
||
window.Handlebars = require('handlebars'); | ||
|
||
const { Feed } = require('../www/assets/js/feed'); | ||
const { Item } = require('../www/assets/js/item'); | ||
const { FeedList } = require('../www/assets/js/feedlist'); | ||
const { ItemList } = require('../www/assets/js/itemlist'); | ||
const { DB } = require('../www/assets/js/db'); | ||
|
||
const mockFeeds = [ | ||
new Feed({ title: 'abc', id: 1, unreadCount: 0, items: []}), | ||
new Feed({ title: 'def', id: 2, unreadCount: 5, items: [ | ||
new Item({ id: 100, time: 203304944, read: true }), | ||
new Item({ id: 101, time: 203304944, read: true }), | ||
new Item({ id: 102, time: 203304944, read: true }), | ||
new Item({ id: 103, time: 203304944 }), | ||
new Item({ id: 104, time: 203304944 }) | ||
]}), | ||
]; | ||
|
||
DB.testDisable = true; // DB won't do anything | ||
|
||
test('Itemlist.nextUnread', () => { | ||
// FIXME: load index.html instead! | ||
document.body.innerHTML = ` | ||
<div id='wrap'> | ||
<div id='main'> | ||
<div class='view' id='feedlist'> | ||
<header id='feedlistViewTitle'> | ||
<span class='title'>Feeds</span> | ||
<span class='addBtn'>+ Add</span> | ||
</header> | ||
<div id='feedlistViewContent'></div> | ||
</div> | ||
<div class='view' id='itemlist'> | ||
<header id='itemlistViewTitle'></header> | ||
<div class='feedInfoError'></div> | ||
<div id='itemlistViewContent'></div> | ||
</div> | ||
<div class='view' id='item'> | ||
<header id='itemViewTitle'></header> | ||
<div id='itemViewContent'></div> | ||
</div> | ||
<div id='linkHover'></div> | ||
</div> | ||
<!-- modal dialog --> | ||
<div id="modal"> | ||
<div id="modalContent"> | ||
</div> | ||
</div> | ||
</div>`; | ||
|
||
let il = new ItemList(); | ||
|
||
FeedList.add(mockFeeds[0], false /* update */); | ||
FeedList.add(mockFeeds[1], false /* update */); | ||
FeedList.render(FeedList.root); | ||
|
||
document.dispatchEvent(new CustomEvent("feedSelected", { detail: { id: 2 } })); | ||
setTimeout(() => { | ||
document.dispatchEvent(new CustomEvent("itemSelected", { detail: { feed: 2, item: 102 } })); | ||
|
||
setTimeout(() => { | ||
expect(ItemList.selected.id).toBe(102); | ||
|
||
ItemList.nextUnread(); | ||
expect(ItemList.selected.id).toBe(103); | ||
|
||
ItemList.nextUnread(); | ||
expect(ItemList.selected.id).toBe(104); | ||
|
||
ItemList.nextUnread(); | ||
expect(ItemList.selected.id).toBe(undefined); | ||
}, 500); | ||
}, 500); | ||
}); | ||
|
Oops, something went wrong.