Account normalizer emojification tests
This commit is contained in:
parent
049d726ff5
commit
b46f31e9f4
2 changed files with 200 additions and 7 deletions
140
app/soapbox/__fixtures__/account-with-emojis.json
Normal file
140
app/soapbox/__fixtures__/account-with-emojis.json
Normal file
|
@ -0,0 +1,140 @@
|
|||
{
|
||||
"acct": "alex",
|
||||
"avatar": "https://media.gleasonator.com/6d64aecb17348b23aaff78db4687b9476cb0da1c07cc6a819c2e6ec7144c18b1.png",
|
||||
"avatar_static": "https://media.gleasonator.com/6d64aecb17348b23aaff78db4687b9476cb0da1c07cc6a819c2e6ec7144c18b1.png",
|
||||
"bot": false,
|
||||
"created_at": "2020-01-08T01:25:43.000Z",
|
||||
"display_name": "Alex Gleason 😂 :soapbox: :ablobcatrainbow:",
|
||||
"emojis": [
|
||||
{
|
||||
"shortcode": "ablobcatrainbow",
|
||||
"static_url": "https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png",
|
||||
"url": "https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png",
|
||||
"visible_in_picker": false
|
||||
},
|
||||
{
|
||||
"shortcode": "soapbox",
|
||||
"static_url": "https://gleasonator.com/emoji/Gleasonator/soapbox.png",
|
||||
"url": "https://gleasonator.com/emoji/Gleasonator/soapbox.png",
|
||||
"visible_in_picker": false
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"name": "Website",
|
||||
"value": "<a href=\"https://alexgleason.me\" rel=\"ugc\">https://alexgleason.me</a>"
|
||||
},
|
||||
{
|
||||
"name": "Soapbox :ablobcatrainbow:",
|
||||
"value": "<a href=\"https://soapbox.pub\" rel=\"ugc\">https://soapbox.pub</a> :soapbox:"
|
||||
},
|
||||
{
|
||||
"name": "Email",
|
||||
"value": "alex@alexgleason.me"
|
||||
},
|
||||
{
|
||||
"name": "Gender identity",
|
||||
"value": "Soyboy"
|
||||
},
|
||||
{
|
||||
"name": "Donate (PayPal)",
|
||||
"value": "<a href=\"https://paypal.me/gleasonator\" rel=\"ugc\">https://paypal.me/gleasonator</a>"
|
||||
},
|
||||
{
|
||||
"name": "$BTC",
|
||||
"value": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n"
|
||||
},
|
||||
{
|
||||
"name": "$ETH",
|
||||
"value": "0xAc9aB5Fc04Dc1cB1789Af75b523Bd23C70B2D717"
|
||||
},
|
||||
{
|
||||
"name": "$DOGE",
|
||||
"value": "D5zVZs6jrRakaPVGiErkQiHt9sayzm6V5D"
|
||||
},
|
||||
{
|
||||
"name": "$XMR",
|
||||
"value": "45JDCLrjJ4bgVUSbbs2yjy9m5Mf4VLPW8fG7jw9sq5u69rXZZopQogZNeyYkMBnXpkaip4p4QwaaJNhdTotPa9g44DBCzdK"
|
||||
}
|
||||
],
|
||||
"followers_count": 2476,
|
||||
"following_count": 1584,
|
||||
"fqn": "alex@gleasonator.com",
|
||||
"header": "https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png",
|
||||
"header_static": "https://media.gleasonator.com/accounts/headers/000/000/001/original/9d0e4dbf1c9dbc8f.png",
|
||||
"id": "9v5bmRalQvjOy0ECcC",
|
||||
"last_status_at": "2022-03-12T16:35:10",
|
||||
"locked": false,
|
||||
"note": "I create Fediverse software that empowers people online. :soapbox:<br/><br/>I'm vegan btw<br/><br/>Note: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.",
|
||||
"pleroma": {
|
||||
"accepts_chat_messages": true,
|
||||
"also_known_as": [
|
||||
"https://mitra.social/users/alex"
|
||||
],
|
||||
"ap_id": "https://gleasonator.com/users/alex",
|
||||
"background_image": null,
|
||||
"birthday": "1993-07-03",
|
||||
"favicon": "https://gleasonator.com/favicon.png",
|
||||
"hide_favorites": true,
|
||||
"hide_followers": false,
|
||||
"hide_followers_count": false,
|
||||
"hide_follows": false,
|
||||
"hide_follows_count": false,
|
||||
"is_admin": true,
|
||||
"is_confirmed": true,
|
||||
"is_moderator": false,
|
||||
"is_suggested": true,
|
||||
"relationship": {},
|
||||
"skip_thread_containment": false,
|
||||
"tags": []
|
||||
},
|
||||
"source": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "Website",
|
||||
"value": "https://alexgleason.me"
|
||||
},
|
||||
{
|
||||
"name": "Soapbox :ablobcatrainbow:",
|
||||
"value": "https://soapbox.pub :soapbox:"
|
||||
},
|
||||
{
|
||||
"name": "Email",
|
||||
"value": "alex@alexgleason.me"
|
||||
},
|
||||
{
|
||||
"name": "Gender identity",
|
||||
"value": "Soyboy"
|
||||
},
|
||||
{
|
||||
"name": "Donate (PayPal)",
|
||||
"value": "https://paypal.me/gleasonator"
|
||||
},
|
||||
{
|
||||
"name": "$BTC",
|
||||
"value": "bc1q9cx35adpm73aq2fw40ye6ts8hfxqzjr5unwg0n"
|
||||
},
|
||||
{
|
||||
"name": "$ETH",
|
||||
"value": "0xAc9aB5Fc04Dc1cB1789Af75b523Bd23C70B2D717"
|
||||
},
|
||||
{
|
||||
"name": "$DOGE",
|
||||
"value": "D5zVZs6jrRakaPVGiErkQiHt9sayzm6V5D"
|
||||
},
|
||||
{
|
||||
"name": "$XMR",
|
||||
"value": "45JDCLrjJ4bgVUSbbs2yjy9m5Mf4VLPW8fG7jw9sq5u69rXZZopQogZNeyYkMBnXpkaip4p4QwaaJNhdTotPa9g44DBCzdK"
|
||||
}
|
||||
],
|
||||
"note": "I create Fediverse software that empowers people online. :soapbox:\r\n\r\nI'm vegan btw\r\n\r\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.",
|
||||
"pleroma": {
|
||||
"actor_type": "Person",
|
||||
"discoverable": false
|
||||
},
|
||||
"sensitive": false
|
||||
},
|
||||
"statuses_count": 23674,
|
||||
"url": "https://gleasonator.com/users/alex",
|
||||
"username": "alex"
|
||||
}
|
|
@ -4,6 +4,8 @@ import { normalizeAccount } from '../account';
|
|||
|
||||
describe('normalizeAccount()', () => {
|
||||
it('normalizes a mention', () => {
|
||||
const avatarMissing = require('images/avatar-missing.png');
|
||||
|
||||
const mention = fromJS({
|
||||
acct: 'NEETzsche@iddqd.social',
|
||||
id: '9v5bw7hEGBPc9nrpzc',
|
||||
|
@ -14,6 +16,8 @@ describe('normalizeAccount()', () => {
|
|||
const result = normalizeAccount(mention);
|
||||
expect(result.emojis).toEqual(fromJS([]));
|
||||
expect(result.display_name).toEqual('NEETzsche');
|
||||
expect(result.avatar).toEqual(avatarMissing);
|
||||
expect(result.avatar_static).toEqual(avatarMissing);
|
||||
expect(result.verified).toBe(false);
|
||||
});
|
||||
|
||||
|
@ -21,14 +25,14 @@ describe('normalizeAccount()', () => {
|
|||
const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.get('birthday')).toEqual('1993-07-03');
|
||||
expect(result.birthday).toEqual('1993-07-03');
|
||||
});
|
||||
|
||||
it('normalizes Pleroma birthday', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
|
||||
expect(result.get('birthday')).toEqual('1993-07-03');
|
||||
expect(result.birthday).toEqual('1993-07-03');
|
||||
});
|
||||
|
||||
it('normalizes Pleroma legacy fields', () => {
|
||||
|
@ -54,30 +58,79 @@ describe('normalizeAccount()', () => {
|
|||
it('normalizes a verified Pleroma user', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/mk.json'));
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.get('verified')).toBe(true);
|
||||
expect(result.verified).toBe(true);
|
||||
});
|
||||
|
||||
it('normalizes an unverified Pleroma user', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/pleroma-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.get('verified')).toBe(false);
|
||||
expect(result.verified).toBe(false);
|
||||
});
|
||||
|
||||
it('normalizes a verified Truth Social user', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/realDonaldTrump.json'));
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.get('verified')).toBe(true);
|
||||
expect(result.verified).toBe(true);
|
||||
});
|
||||
|
||||
it('normalizes Fedibird location', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/fedibird-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.get('location')).toBe('Texas, USA');
|
||||
expect(result.location).toBe('Texas, USA');
|
||||
});
|
||||
|
||||
it('normalizes Truth Social location', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/truthsocial-account.json'));
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.get('location')).toBe('Texas');
|
||||
expect(result.location).toBe('Texas');
|
||||
});
|
||||
|
||||
it('sets display_name from username', () => {
|
||||
const account = fromJS({ username: 'alex' });
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.display_name).toBe('alex');
|
||||
});
|
||||
|
||||
it('sets display_name from acct', () => {
|
||||
const account = fromJS({ acct: 'alex@gleasonator.com' });
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.display_name).toBe('alex');
|
||||
});
|
||||
|
||||
it('overrides a whitespace display_name', () => {
|
||||
const account = fromJS({ username: 'alex', display_name: ' ' });
|
||||
const result = normalizeAccount(account);
|
||||
expect(result.display_name).toBe('alex');
|
||||
});
|
||||
|
||||
it('emojifies display name as `display_name_html`', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json'));
|
||||
const result = normalizeAccount(account);
|
||||
const expected = 'Alex Gleason <img draggable="false" class="emojione" alt="😂" title=":joy:" src="/packs/emoji/1f602.svg" /> <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /> <img draggable="false" class="emojione" alt=":ablobcatrainbow:" title=":ablobcatrainbow:" src="https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png" />';
|
||||
expect(result.display_name_html).toBe(expected);
|
||||
});
|
||||
|
||||
it('emojifies note as `note_emojified`', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json'));
|
||||
const result = normalizeAccount(account);
|
||||
const expected = 'I create Fediverse software that empowers people online. <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" /><br/><br/>I'm vegan btw<br/><br/>Note: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.';
|
||||
expect(result.note_emojified).toBe(expected);
|
||||
});
|
||||
|
||||
it('unescapes HTML note as `note_plain`', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json'));
|
||||
const result = normalizeAccount(account);
|
||||
const expected = 'I create Fediverse software that empowers people online. :soapbox:\n\nI\'m vegan btw\n\nNote: If you have a question for me, please tag me publicly. This gives the opportunity for others to chime in, and bystanders to learn.';
|
||||
expect(result.note_plain).toBe(expected);
|
||||
});
|
||||
|
||||
it('emojifies custom profile field', () => {
|
||||
const account = fromJS(require('soapbox/__fixtures__/account-with-emojis.json'));
|
||||
const result = normalizeAccount(account);
|
||||
const field = result.fields.get(1);
|
||||
|
||||
expect(field.name_emojified).toBe('Soapbox <img draggable="false" class="emojione" alt=":ablobcatrainbow:" title=":ablobcatrainbow:" src="https://gleasonator.com/emoji/blobcat/ablobcatrainbow.png" />');
|
||||
expect(field.value_emojified).toBe('<a href="https://soapbox.pub" rel="ugc">https://soapbox.pub</a> <img draggable="false" class="emojione" alt=":soapbox:" title=":soapbox:" src="https://gleasonator.com/emoji/Gleasonator/soapbox.png" />');
|
||||
expect(field.value_plain).toBe('https://soapbox.pub :soapbox:');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue