From 74c2e8ea1514115ad1975d954bb962bb7c580681 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 13 Apr 2022 09:41:45 -0400 Subject: [PATCH] Add tests for WhoToFollowPanel --- .../__tests__/who-to-follow-panel.test.tsx | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx diff --git a/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx b/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx new file mode 100644 index 0000000000..700eb621f9 --- /dev/null +++ b/app/soapbox/features/ui/components/__tests__/who-to-follow-panel.test.tsx @@ -0,0 +1,122 @@ +import { Map as ImmutableMap, fromJS } from 'immutable'; +import React from 'react'; + +import { render, screen } from '../../../../jest/test-helpers'; +import WhoToFollowPanel from '../who-to-follow-panel'; + +describe('', () => { + it('renders suggested accounts', () => { + const store = { + accounts: ImmutableMap({ + '1': ImmutableMap({ + id: '1', + acct: 'username', + display_name_html: 'My name', + avatar: 'test.jpg', + }), + }), + suggestions: ImmutableMap({ + items: fromJS([{ + source: 'staff', + account: '1', + }]), + }), + }; + + render(, null, store); + expect(screen.getByTestId('account')).toHaveTextContent(/my name/i); + }); + + it('renders multiple accounts', () => { + const store = { + accounts: ImmutableMap({ + '1': ImmutableMap({ + id: '1', + acct: 'username', + display_name_html: 'My name', + avatar: 'test.jpg', + }), + '2': ImmutableMap({ + id: '1', + acct: 'username2', + display_name_html: 'My other name', + avatar: 'test.jpg', + }), + }), + suggestions: ImmutableMap({ + items: fromJS([ + { + source: 'staff', + account: '1', + }, + { + source: 'staff', + account: '2', + }, + ]), + }), + }; + + render(, null, store); + expect(screen.queryAllByTestId('account')).toHaveLength(2); + }); + + it('respects the limit prop', () => { + const store = { + accounts: ImmutableMap({ + '1': ImmutableMap({ + id: '1', + acct: 'username', + display_name_html: 'My name', + avatar: 'test.jpg', + }), + '2': ImmutableMap({ + id: '1', + acct: 'username2', + display_name_html: 'My other name', + avatar: 'test.jpg', + }), + }), + suggestions: ImmutableMap({ + items: fromJS([ + { + source: 'staff', + account: '1', + }, + { + source: 'staff', + account: '2', + }, + ]), + }), + }; + + render(, null, store); + expect(screen.queryAllByTestId('account')).toHaveLength(1); + }); + + it('renders empty', () => { + const store = { + accounts: ImmutableMap({ + '1': ImmutableMap({ + id: '1', + acct: 'username', + display_name_html: 'My name', + avatar: 'test.jpg', + }), + '2': ImmutableMap({ + id: '1', + acct: 'username2', + display_name_html: 'My other name', + avatar: 'test.jpg', + }), + }), + suggestions: ImmutableMap({ + items: fromJS([]), + }), + }; + + render(, null, store); + expect(screen.queryAllByTestId('account')).toHaveLength(0); + }); +});