Fix Trends Panel test

This commit is contained in:
Justin 2022-08-10 10:31:09 -04:00
parent 968ec3a7d2
commit cbe9f47a59
1 changed files with 58 additions and 73 deletions

View File

@ -1,85 +1,70 @@
import { List as ImmutableList, Record as ImmutableRecord } from 'immutable';
import React from 'react'; import React from 'react';
import { render, screen } from '../../../../jest/test-helpers'; import { __stub } from 'soapbox/api';
import { normalizeTag } from '../../../../normalizers';
import { render, screen, waitFor } from '../../../../jest/test-helpers';
import TrendsPanel from '../trends-panel'; import TrendsPanel from '../trends-panel';
describe('<TrendsPanel />', () => { describe('<TrendsPanel />', () => {
it('renders trending hashtags', () => { describe('with hashtags', () => {
const store = { beforeEach(() => {
trends: ImmutableRecord({ __stub((mock) => {
items: ImmutableList([ mock.onGet('/api/v1/trends')
normalizeTag({ .reply(200, [
name: 'hashtag 1', {
history: [{ name: 'hashtag 1',
day: '1652745600', url: 'https://example.com',
uses: '294', history: [{
accounts: '180', day: '1652745600',
}], uses: '294',
}), accounts: '180',
]), }],
isLoading: false, },
})(), { name: 'hashtag 2', url: 'https://example.com' },
}; ]);
});
});
render(<TrendsPanel limit={1} />, undefined, store); it('renders trending hashtags', async() => {
expect(screen.getByTestId('hashtag')).toHaveTextContent(/hashtag 1/i); render(<TrendsPanel limit={1} />);
expect(screen.getByTestId('hashtag')).toHaveTextContent(/180 people talking/i);
expect(screen.getByTestId('sparklines')).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByTestId('hashtag')).toHaveTextContent(/hashtag 1/i);
expect(screen.getByTestId('hashtag')).toHaveTextContent(/180 people talking/i);
expect(screen.getByTestId('sparklines')).toBeInTheDocument();
});
});
it('renders multiple trends', async() => {
render(<TrendsPanel limit={3} />);
await waitFor(() => {
expect(screen.queryAllByTestId('hashtag')).toHaveLength(2);
});
});
it('respects the limit prop', async() => {
render(<TrendsPanel limit={1} />);
await waitFor(() => {
expect(screen.queryAllByTestId('hashtag')).toHaveLength(1);
});
});
}); });
it('renders multiple trends', () => { describe('without hashtags', () => {
const store = { beforeEach(() => {
trends: ImmutableRecord({ __stub((mock) => {
items: ImmutableList([ mock.onGet('/api/v1/trends').reply(200, []);
normalizeTag({ });
name: 'hashtag 1', });
history: ImmutableList([{ accounts: [] }]),
}),
normalizeTag({
name: 'hashtag 2',
history: ImmutableList([{ accounts: [] }]),
}),
]),
isLoading: false,
})(),
};
render(<TrendsPanel limit={3} />, undefined, store); it('renders empty', async() => {
expect(screen.queryAllByTestId('hashtag')).toHaveLength(2); render(<TrendsPanel limit={1} />);
});
it('respects the limit prop', () => { await waitFor(() => {
const store = { expect(screen.queryAllByTestId('hashtag')).toHaveLength(0);
trends: ImmutableRecord({ });
items: ImmutableList([ });
normalizeTag({
name: 'hashtag 1',
history: [{ accounts: [] }],
}),
normalizeTag({
name: 'hashtag 2',
history: [{ accounts: [] }],
}),
]),
isLoading: false,
})(),
};
render(<TrendsPanel limit={1} />, undefined, store);
expect(screen.queryAllByTestId('hashtag')).toHaveLength(1);
});
it('renders empty', () => {
const store = {
trends: ImmutableRecord({
items: ImmutableList([]),
isLoading: false,
})(),
};
render(<TrendsPanel limit={1} />, undefined, store);
expect(screen.queryAllByTestId('hashtag')).toHaveLength(0);
}); });
}); });