import { expect } from 'chai'; import { LeftPane, RowType, PropsType, HeaderType, } from '../../components/LeftPane'; import { setup as setupI18n } from '../../../js/modules/i18n'; import enMessages from '../../../_locales/en/messages.json'; const i18n = setupI18n('en', enMessages); describe('LeftPane', () => { /* eslint-disable @typescript-eslint/no-explicit-any */ const defaultProps = { archivedConversations: [], conversations: [], i18n, openConversationInternal: () => null, pinnedConversations: [], renderExpiredBuildDialog: () => '
' as any, renderMainHeader: () => '' as any, renderMessageSearchResult: () => '' as any, renderNetworkStatus: () => '' as any, renderRelinkDialog: () => '' as any, renderUpdateDialog: () => '' as any, showArchivedConversations: () => null, showInbox: () => null, startNewConversation: () => null, }; /* eslint-enable @typescript-eslint/no-explicit-any */ describe('getRowFromIndex', () => { let leftPane: LeftPane; describe('given only pinned chats', () => { beforeEach(function beforeEach() { const props: PropsType = { ...defaultProps, pinnedConversations: [ { id: 'philly-convo', isPinned: true, isSelected: false, lastUpdated: Date.now(), title: 'Philip Glass', type: 'direct', }, { id: 'robbo-convo', isPinned: true, isSelected: false, lastUpdated: Date.now(), title: 'Robert Moog', type: 'direct', }, ], }; leftPane = new LeftPane(props); }); it('return pinned chats, not headers', () => { expect(leftPane.getRowFromIndex(0)).to.eql({ index: 0, type: RowType.PinnedConversation, }); expect(leftPane.getRowFromIndex(1)).to.eql({ index: 1, type: RowType.PinnedConversation, }); }); }); describe('given only non-pinned chats', () => { it('returns conversations, not headers', () => { const props: PropsType = { ...defaultProps, conversations: [ { id: 'fred-convo', isSelected: false, lastUpdated: Date.now(), title: 'Fred Willard', type: 'direct', }, { id: 'robbo-convo', isPinned: false, isSelected: false, lastUpdated: Date.now(), title: 'Robert Moog', type: 'direct', }, ], }; leftPane = new LeftPane(props); expect(leftPane.getRowFromIndex(0)).to.eql({ index: 0, type: RowType.Conversation, }); expect(leftPane.getRowFromIndex(1)).to.eql({ index: 1, type: RowType.Conversation, }); }); }); describe('given only pinned and non-pinned chats', () => { beforeEach(function beforeEach() { const props: PropsType = { ...defaultProps, conversations: [ { id: 'fred-convo', isSelected: false, lastUpdated: Date.now(), title: 'Fred Willard', type: 'direct', }, ], pinnedConversations: [ { id: 'philly-convo', isPinned: true, isSelected: false, lastUpdated: Date.now(), title: 'Philip Glass', type: 'direct', }, ], }; leftPane = new LeftPane(props); }); it('returns headers and conversations', () => { expect(leftPane.getRowFromIndex(0)).to.eql({ headerType: HeaderType.Pinned, type: RowType.Header, }); expect(leftPane.getRowFromIndex(1)).to.eql({ index: 0, type: RowType.PinnedConversation, }); expect(leftPane.getRowFromIndex(2)).to.eql({ headerType: HeaderType.Chats, type: RowType.Header, }); expect(leftPane.getRowFromIndex(3)).to.eql({ index: 0, type: RowType.Conversation, }); }); }); describe('given not showing archive with archived conversation', () => { beforeEach(function beforeEach() { const props: PropsType = { ...defaultProps, archivedConversations: [ { id: 'jerry-convo', isSelected: false, lastUpdated: Date.now(), title: 'Jerry Jordan', type: 'direct', }, ], conversations: [ { id: 'fred-convo', isSelected: false, lastUpdated: Date.now(), title: 'Fred Willard', type: 'direct', }, ], showArchived: false, }; leftPane = new LeftPane(props); }); it('returns an archive button last', () => { expect(leftPane.getRowFromIndex(1)).to.eql({ type: RowType.ArchiveButton, }); }); }); describe('given showing archive and archive chats', () => { beforeEach(function beforeEach() { const props: PropsType = { ...defaultProps, archivedConversations: [ { id: 'fred-convo', isSelected: false, lastUpdated: Date.now(), title: 'Fred Willard', type: 'direct', }, ], showArchived: true, }; leftPane = new LeftPane(props); }); it('returns archived conversations', () => { expect(leftPane.getRowFromIndex(0)).to.eql({ index: 0, type: RowType.ArchivedConversation, }); }); }); }); });