2022-06-08 14:43:27 -07:00
|
|
|
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
|
2022-04-07 08:55:15 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { render, screen } from '../../../../jest/test-helpers';
|
2022-06-08 14:43:27 -07:00
|
|
|
import { normalizeTag } from '../../../../normalizers';
|
2022-04-07 08:55:15 -07:00
|
|
|
import TrendsPanel from '../trends-panel';
|
|
|
|
|
|
|
|
describe('<TrendsPanel />', () => {
|
|
|
|
it('renders trending hashtags', () => {
|
|
|
|
const store = {
|
2022-06-08 14:43:27 -07:00
|
|
|
trends: ImmutableRecord({
|
|
|
|
items: ImmutableList([
|
|
|
|
normalizeTag({
|
|
|
|
name: 'hashtag 1',
|
|
|
|
history: [{
|
|
|
|
day: '1652745600',
|
|
|
|
uses: '294',
|
|
|
|
accounts: '180',
|
|
|
|
}],
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
isLoading: false,
|
|
|
|
})(),
|
2022-04-07 08:55:15 -07:00
|
|
|
};
|
|
|
|
|
2022-07-06 10:16:14 -07:00
|
|
|
render(<TrendsPanel limit={1} />, undefined, store);
|
2022-04-07 08:55:15 -07:00
|
|
|
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 = {
|
2022-06-08 14:43:27 -07:00
|
|
|
trends: ImmutableRecord({
|
2022-06-07 09:25:53 -07:00
|
|
|
items: ImmutableList([
|
2022-06-08 14:43:27 -07:00
|
|
|
normalizeTag({
|
2022-04-07 08:55:15 -07:00
|
|
|
name: 'hashtag 1',
|
2022-06-07 09:25:53 -07:00
|
|
|
history: ImmutableList([{ accounts: [] }]),
|
2022-06-08 14:43:27 -07:00
|
|
|
}),
|
|
|
|
normalizeTag({
|
2022-04-07 08:55:15 -07:00
|
|
|
name: 'hashtag 2',
|
2022-06-07 09:25:53 -07:00
|
|
|
history: ImmutableList([{ accounts: [] }]),
|
2022-06-08 14:43:27 -07:00
|
|
|
}),
|
2022-04-07 08:55:15 -07:00
|
|
|
]),
|
2022-06-08 14:43:27 -07:00
|
|
|
isLoading: false,
|
|
|
|
})(),
|
2022-04-07 08:55:15 -07:00
|
|
|
};
|
|
|
|
|
2022-07-06 10:16:14 -07:00
|
|
|
render(<TrendsPanel limit={3} />, undefined, store);
|
2022-04-07 08:55:15 -07:00
|
|
|
expect(screen.queryAllByTestId('hashtag')).toHaveLength(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('respects the limit prop', () => {
|
|
|
|
const store = {
|
2022-06-08 14:43:27 -07:00
|
|
|
trends: ImmutableRecord({
|
2022-06-07 09:25:53 -07:00
|
|
|
items: ImmutableList([
|
2022-06-08 14:43:27 -07:00
|
|
|
normalizeTag({
|
2022-04-07 08:55:15 -07:00
|
|
|
name: 'hashtag 1',
|
2022-06-08 14:43:27 -07:00
|
|
|
history: [{ accounts: [] }],
|
|
|
|
}),
|
|
|
|
normalizeTag({
|
2022-04-07 08:55:15 -07:00
|
|
|
name: 'hashtag 2',
|
2022-06-08 14:43:27 -07:00
|
|
|
history: [{ accounts: [] }],
|
|
|
|
}),
|
2022-04-07 08:55:15 -07:00
|
|
|
]),
|
2022-06-08 14:43:27 -07:00
|
|
|
isLoading: false,
|
|
|
|
})(),
|
2022-04-07 08:55:15 -07:00
|
|
|
};
|
|
|
|
|
2022-07-06 10:16:14 -07:00
|
|
|
render(<TrendsPanel limit={1} />, undefined, store);
|
2022-04-07 08:55:15 -07:00
|
|
|
expect(screen.queryAllByTestId('hashtag')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty', () => {
|
|
|
|
const store = {
|
2022-06-08 14:43:27 -07:00
|
|
|
trends: ImmutableRecord({
|
2022-06-07 09:25:53 -07:00
|
|
|
items: ImmutableList([]),
|
2022-06-08 14:43:27 -07:00
|
|
|
isLoading: false,
|
|
|
|
})(),
|
2022-04-07 08:55:15 -07:00
|
|
|
};
|
|
|
|
|
2022-07-06 10:16:14 -07:00
|
|
|
render(<TrendsPanel limit={1} />, undefined, store);
|
2022-04-07 08:55:15 -07:00
|
|
|
expect(screen.queryAllByTestId('hashtag')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|