2018-10-10 18:13:31 +02:00
|
|
|
import { JSDOM } from 'jsdom'
|
2018-12-28 16:04:17 +01:00
|
|
|
import { findLink, findTag, findAccount } from '@/utils/tootParser'
|
2018-10-10 18:13:31 +02:00
|
|
|
|
|
|
|
describe('findLink', () => {
|
2018-12-26 12:29:05 +01:00
|
|
|
describe('Pleroma', () => {
|
2019-12-11 14:48:38 +01:00
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
2018-10-10 18:13:31 +02:00
|
|
|
<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>
|
2019-12-11 14:48:38 +01:00
|
|
|
</html>`).window.document
|
2018-10-10 18:13:31 +02:00
|
|
|
|
|
|
|
const target = doc.getElementById('link')
|
|
|
|
it('should find', () => {
|
|
|
|
const res = findLink(target)
|
2018-12-28 16:21:26 +01:00
|
|
|
expect(res).toEqual('https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1')
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-03 04:35:03 +01:00
|
|
|
describe('findTag', () => {
|
2018-12-26 12:29:05 +01:00
|
|
|
describe('Pleroma', () => {
|
2019-12-11 14:48:38 +01:00
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
2018-10-10 18:13:31 +02:00
|
|
|
<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>
|
2019-12-11 14:48:38 +01:00
|
|
|
</html>`).window.document
|
2018-10-10 18:13:31 +02:00
|
|
|
const target = doc.getElementById('tag')
|
|
|
|
it('should find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findTag(target!)
|
2018-12-28 16:21:26 +01:00
|
|
|
expect(res).toEqual('whalebird')
|
2018-11-03 04:35:03 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-26 12:29:05 +01:00
|
|
|
describe('Mastodon', () => {
|
2019-12-11 14:48:38 +01:00
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
2018-11-03 04:35:03 +01:00
|
|
|
<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>
|
2019-12-11 14:48:38 +01:00
|
|
|
</html>`).window.document
|
2018-11-03 04:35:03 +01:00
|
|
|
const target = doc.getElementById('tag')
|
|
|
|
it('should find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findTag(target!)
|
2018-12-28 16:21:26 +01:00
|
|
|
expect(res).toEqual('whalebird')
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('findAccount', () => {
|
2018-12-26 12:29:05 +01:00
|
|
|
describe('in Pleroma', () => {
|
|
|
|
describe('from Mastodon', () => {
|
2019-12-11 14:48:38 +01:00
|
|
|
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>
|
2019-12-11 14:48:38 +01:00
|
|
|
</html>`).window.document
|
2018-11-13 15:30:30 +01:00
|
|
|
const target = doc.getElementById('user')
|
|
|
|
it('should find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findAccount(target!)
|
2021-12-29 16:17:23 +01:00
|
|
|
expect(res).not.toBeNull()
|
|
|
|
expect(res!.username).toEqual('@h3_poteto')
|
|
|
|
expect(res!.acct).toEqual('@h3_poteto@social.mikutter.hachune.net')
|
2018-11-13 15:30:30 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-26 12:29:05 +01:00
|
|
|
describe('from Pleroma', () => {
|
2019-12-11 14:48:38 +01:00
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
2018-11-13 15:30:30 +01:00
|
|
|
<div class="toot">
|
|
|
|
<p><span><a href="https://pleroma.io/users/h3poteto">@<span id="user">h3_poteto</span></a></span> hogehoge</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
2019-12-11 14:48:38 +01:00
|
|
|
</html>`).window.document
|
2018-11-13 15:30:30 +01:00
|
|
|
const target = doc.getElementById('user')
|
|
|
|
it('should find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findAccount(target!)
|
2021-12-29 16:17:23 +01:00
|
|
|
expect(res).not.toBeNull()
|
|
|
|
expect(res!.username).toEqual('@h3poteto')
|
|
|
|
expect(res!.acct).toEqual('@h3poteto@pleroma.io')
|
2018-11-13 15:30:30 +01:00
|
|
|
})
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
2019-12-11 14:48:38 +01:00
|
|
|
|
|
|
|
describe('toot link in Mastodon', () => {
|
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p><span><a id="status" href="https://https://fedibird.com/@h3poteto/103040884240752891">https://fedibird.com/@h3poteto/103040884240752891</a></span> hogehoge</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`).window.document
|
|
|
|
const target = doc.getElementById('status')
|
|
|
|
it('should not find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findAccount(target!)
|
2019-12-11 14:48:38 +01:00
|
|
|
expect(res).toBeNull()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('toot link in Pleroma', () => {
|
|
|
|
const doc = new JSDOM(`<html><head></head><body>
|
|
|
|
<div class="toot">
|
|
|
|
<p><span><a id="status" href="https://pleroma.io/notice/9pqtJ78TcXAytY51Wa">https://pleroma.io/notice/9pqtJ78TcXAytY51Wa</a></span> hogehoge</p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>`).window.document
|
|
|
|
const target = doc.getElementById('status')
|
|
|
|
it('should not find', () => {
|
2022-05-21 14:28:19 +02:00
|
|
|
expect(target).not.toBeNull()
|
|
|
|
const res = findAccount(target!)
|
2019-12-11 14:48:38 +01:00
|
|
|
expect(res).toBeNull()
|
|
|
|
})
|
|
|
|
})
|
2018-10-10 18:13:31 +02:00
|
|
|
})
|
|
|
|
})
|