From ad381d7fbc1a939dcddfcba7c01752d795c491a1 Mon Sep 17 00:00:00 2001 From: Justin Date: Thu, 7 Apr 2022 11:55:15 -0400 Subject: [PATCH] Add tests for TrendsPanel --- app/soapbox/components/hashtag.js | Bin 1864 -> 1886 bytes .../__tests__/trends-panel.test.tsx | 72 ++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx diff --git a/app/soapbox/components/hashtag.js b/app/soapbox/components/hashtag.js index d74911f2e6c9d59247bfd234cb2a3e5c9bbd64a4..1b19bbff3fd355072f479bc7a7381b3a6f510e1c 100644 GIT binary patch delta 34 pcmX@XcaLwwE+$chl*E!m-ICPelFSra^^C;gjFQCk%{!U;SpeoG4E+EA delta 12 Tcmcb|cY<%jE~d>FnEF@%CF2D~ diff --git a/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx b/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx new file mode 100644 index 0000000000..f2d310c555 --- /dev/null +++ b/app/soapbox/features/ui/components/__tests__/trends-panel.test.tsx @@ -0,0 +1,72 @@ +import { Map as ImmutableMap, fromJS } from 'immutable'; +import React from 'react'; + +import { render, screen } from '../../../../jest/test-helpers'; +import TrendsPanel from '../trends-panel'; + +describe('', () => { + it('renders trending hashtags', () => { + const store = { + trends: ImmutableMap({ + items: fromJS([{ + name: 'hashtag 1', + history: [{ accounts: [] }], + }]), + }), + }; + + render(, null, store); + expect(screen.getByTestId('hashtag')).toHaveTextContent(/hashtag 1/i); + }); + + it('renders multiple trends', () => { + const store = { + trends: ImmutableMap({ + items: fromJS([ + { + name: 'hashtag 1', + history: [{ accounts: [] }], + }, + { + name: 'hashtag 2', + history: [{ accounts: [] }], + }, + ]), + }), + }; + + render(, 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(, null, store); + expect(screen.queryAllByTestId('hashtag')).toHaveLength(1); + }); + + it('renders empty', () => { + const store = { + trends: ImmutableMap({ + items: fromJS([]), + }), + }; + + render(, null, store); + expect(screen.queryAllByTestId('hashtag')).toHaveLength(0); + }); +});