2018-10-10 18:13:31 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import { JSDOM } from 'jsdom'
|
2018-11-03 04:35:03 +01:00
|
|
|
import { findLink, findTag, findAccount } from '../../src/renderer/utils/tootParser'
|
2018-10-10 18:13:31 +02:00
|
|
|
|
|
|
|
describe('findLink', () => {
|
|
|
|
context('Pleroma', () => {
|
|
|
|
const doc = (new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p>
|
|
|
|
I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streaming update of Pleroma. But it contains a bug, so it is resolved in version 2.4.1. <br /><a href="https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1" id="link">https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1</a><br /><a href="https://pleroma.io/tag/whalebird">#Whalebird</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`)).window.document
|
|
|
|
|
|
|
|
const target = doc.getElementById('link')
|
|
|
|
it('should find', () => {
|
|
|
|
const res = findLink(target)
|
|
|
|
assert.strictEqual(res, 'https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-03 04:35:03 +01:00
|
|
|
describe('findTag', () => {
|
2018-10-10 18:13:31 +02:00
|
|
|
context('Pleroma', () => {
|
|
|
|
const doc = (new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p>
|
|
|
|
I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streaming update of Pleroma. But it contains a bug, so it is resolved in version 2.4.1. <br /><a href="https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1">https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1</a><br /><a id="tag" href="https://pleroma.io/tag/whalebird">#Whalebird</a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`)).window.document
|
|
|
|
const target = doc.getElementById('tag')
|
|
|
|
it('should find', () => {
|
2018-11-03 04:35:03 +01:00
|
|
|
const res = findTag(target)
|
|
|
|
assert.strictEqual(res, 'whalebird')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
context('Mastodon', () => {
|
|
|
|
const doc = (new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p>
|
|
|
|
I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streaming update of Pleroma. But it contains a bug, so it is resolved in version 2.4.1. <br /><a href="https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1">https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1</a><br /><a id="tag" class="hashtag" href="https://pleroma.io/tag/whalebird">#<span>Whalebird</span></a>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`)).window.document
|
|
|
|
const target = doc.getElementById('tag')
|
|
|
|
it('should find', () => {
|
|
|
|
const res = findTag(target)
|
|
|
|
assert.strictEqual(res, 'whalebird')
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('findAccount', () => {
|
2018-11-13 15:30:30 +01:00
|
|
|
context('in Pleroma', () => {
|
|
|
|
context('from Mastodon', () => {
|
|
|
|
const doc = (new JSDOM(`<html><head></head><body>
|
2018-10-10 18:13:31 +02:00
|
|
|
<div class="toot">
|
|
|
|
<p><span><a href="https://social.mikutter.hachune.net/@h3_poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`)).window.document
|
2018-11-13 15:30:30 +01:00
|
|
|
const target = doc.getElementById('user')
|
|
|
|
it('should find', () => {
|
|
|
|
const res = findAccount(target)
|
|
|
|
assert.strictEqual(res.username, '@h3_poteto')
|
|
|
|
assert.strictEqual(res.acct, '@h3_poteto@social.mikutter.hachune.net')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
context('from Pleroma', () => {
|
|
|
|
const doc = (new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p><span><a href="https://pleroma.io/users/h3poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`)).window.document
|
|
|
|
const target = doc.getElementById('user')
|
|
|
|
it('should find', () => {
|
|
|
|
const res = findAccount(target)
|
|
|
|
assert.strictEqual(res.username, '@h3poteto')
|
|
|
|
assert.strictEqual(res.acct, '@h3poteto@pleroma.io')
|
|
|
|
})
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|