bigbuffet-rw/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx

124 lines
3 KiB
TypeScript
Raw Normal View History

import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
2022-04-13 06:41:45 -07:00
import React from 'react';
import { render, screen } from '../../../../jest/test-helpers';
import { normalizeAccount } from '../../../../normalizers';
2022-04-13 06:41:45 -07:00
import WhoToFollowPanel from '../who-to-follow-panel';
describe('<WhoToFollow />', () => {
it('renders suggested accounts', () => {
const store = {
accounts: ImmutableMap({
'1': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username',
display_name: 'My name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
}),
suggestions: {
items: ImmutableOrderedSet([{
2022-04-13 06:41:45 -07:00
source: 'staff',
account: '1',
}]),
},
2022-04-13 06:41:45 -07:00
};
2022-07-06 10:16:14 -07:00
render(<WhoToFollowPanel limit={1} />, undefined, store);
2022-04-13 06:41:45 -07:00
expect(screen.getByTestId('account')).toHaveTextContent(/my name/i);
});
it('renders multiple accounts', () => {
const store = {
accounts: ImmutableMap({
'1': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username',
display_name: 'My name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
'2': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username2',
display_name: 'My other name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
}),
suggestions: {
items: ImmutableOrderedSet([
2022-04-13 06:41:45 -07:00
{
source: 'staff',
account: '1',
},
{
source: 'staff',
account: '2',
},
]),
},
2022-04-13 06:41:45 -07:00
};
2022-07-06 10:16:14 -07:00
render(<WhoToFollowPanel limit={3} />, undefined, store);
2022-04-13 06:41:45 -07:00
expect(screen.queryAllByTestId('account')).toHaveLength(2);
});
it('respects the limit prop', () => {
const store = {
accounts: ImmutableMap({
'1': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username',
display_name: 'My name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
'2': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username2',
display_name: 'My other name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
}),
suggestions: {
items: ImmutableOrderedSet([
2022-04-13 06:41:45 -07:00
{
source: 'staff',
account: '1',
},
{
source: 'staff',
account: '2',
},
]),
},
2022-04-13 06:41:45 -07:00
};
2022-07-06 10:16:14 -07:00
render(<WhoToFollowPanel limit={1} />, undefined, store);
2022-04-13 06:41:45 -07:00
expect(screen.queryAllByTestId('account')).toHaveLength(1);
});
it('renders empty', () => {
const store = {
accounts: ImmutableMap({
'1': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username',
display_name: 'My name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
'2': normalizeAccount({
2022-04-13 06:41:45 -07:00
id: '1',
acct: 'username2',
display_name: 'My other name',
2022-04-13 06:41:45 -07:00
avatar: 'test.jpg',
}),
}),
suggestions: {
items: ImmutableOrderedSet([]),
},
2022-04-13 06:41:45 -07:00
};
2022-07-06 10:16:14 -07:00
render(<WhoToFollowPanel limit={1} />, undefined, store);
2022-04-13 06:41:45 -07:00
expect(screen.queryAllByTestId('account')).toHaveLength(0);
});
});