bigbuffet-rw/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx

79 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-04-07 08:55:15 -07:00
import { Map as ImmutableMap, fromJS } from 'immutable';
import React from 'react';
import { render, screen } from '../../../../jest/test-helpers';
import TrendsPanel from '../trends-panel';
describe('<TrendsPanel />', () => {
it('renders trending hashtags', () => {
const store = {
trends: ImmutableMap({
items: fromJS([{
name: 'hashtag 1',
2022-05-17 09:47:32 -07:00
history: [{
day: '1652745600',
uses: '294',
accounts: '180',
}],
2022-04-07 08:55:15 -07:00
}]),
}),
};
render(<TrendsPanel limit={1} />, null, store);
expect(screen.getByTestId('hashtag')).toHaveTextContent(/hashtag 1/i);
2022-05-17 09:47:32 -07:00
expect(screen.getByTestId('hashtag')).toHaveTextContent(/180 people talking/i);
expect(screen.getByTestId('sparklines')).toBeInTheDocument();
2022-04-07 08:55:15 -07:00
});
it('renders multiple trends', () => {
const store = {
trends: ImmutableMap({
items: fromJS([
{
name: 'hashtag 1',
history: [{ accounts: [] }],
},
{
name: 'hashtag 2',
history: [{ accounts: [] }],
},
]),
}),
};
render(<TrendsPanel limit={3} />, null, store);
expect(screen.queryAllByTestId('hashtag')).toHaveLength(2);
});
it('respects the limit prop', () => {
const store = {
trends: ImmutableMap({
items: fromJS([
{
name: 'hashtag 1',
history: [{ accounts: [] }],
},
{
name: 'hashtag 2',
history: [{ accounts: [] }],
},
]),
}),
};
render(<TrendsPanel limit={1} />, null, store);
expect(screen.queryAllByTestId('hashtag')).toHaveLength(1);
});
it('renders empty', () => {
const store = {
trends: ImmutableMap({
items: fromJS([]),
}),
};
render(<TrendsPanel limit={1} />, null, store);
expect(screen.queryAllByTestId('hashtag')).toHaveLength(0);
});
});