Add utils/badges tests
This commit is contained in:
parent
25f0ff9d86
commit
6f236dd1e6
1 changed files with 43 additions and 0 deletions
43
app/soapbox/utils/__tests__/badges.test.ts
Normal file
43
app/soapbox/utils/__tests__/badges.test.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { normalizeAccount } from 'soapbox/normalizers';
|
||||
|
||||
import {
|
||||
tagToBadge,
|
||||
badgeToTag,
|
||||
filterBadges,
|
||||
getTagDiff,
|
||||
getBadges,
|
||||
} from '../badges';
|
||||
|
||||
import type { Account } from 'soapbox/types/entities';
|
||||
|
||||
test('tagToBadge', () => {
|
||||
expect(tagToBadge('yolo')).toEqual('badge:yolo');
|
||||
});
|
||||
|
||||
test('badgeToTag', () => {
|
||||
expect(badgeToTag('badge:yolo')).toEqual('yolo');
|
||||
expect(badgeToTag('badge:badge:')).toEqual('badge:');
|
||||
});
|
||||
|
||||
test('filterBadges', () => {
|
||||
const tags = ['one', 'badge:two', 'badge:three', 'four'];
|
||||
const badges = ['badge:two', 'badge:three'];
|
||||
expect(filterBadges(tags)).toEqual(badges);
|
||||
});
|
||||
|
||||
test('getTagDiff', () => {
|
||||
const oldTags = ['one', 'two', 'three'];
|
||||
const newTags = ['three', 'four', 'five'];
|
||||
|
||||
const expected = {
|
||||
added: ['four', 'five'],
|
||||
removed: ['one', 'two'],
|
||||
};
|
||||
|
||||
expect(getTagDiff(oldTags, newTags)).toEqual(expected);
|
||||
});
|
||||
|
||||
test('getBadges', () => {
|
||||
const account = normalizeAccount({ id: '1', pleroma: { tags: ['a', 'b', 'badge:c'] } }) as Account;
|
||||
expect(getBadges(account)).toEqual(['badge:c']);
|
||||
});
|
Loading…
Reference in a new issue