pleroma/app/soapbox/features/chats/components/__tests__/chat-widget.test.tsx

102 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-10-03 06:14:45 -07:00
import React from 'react';
import { Route, Switch } from 'react-router-dom';
2023-06-20 12:24:39 -07:00
import { buildAccount } from 'soapbox/jest/factory';
2022-10-03 06:14:45 -07:00
import { render, rootState } from '../../../../jest/test-helpers';
2022-10-17 05:34:19 -07:00
import ChatWidget from '../chat-widget/chat-widget';
2022-10-03 06:14:45 -07:00
const id = '1';
2023-06-20 12:24:39 -07:00
const account = buildAccount({
2022-10-03 06:14:45 -07:00
id,
acct: 'justin-username',
display_name: 'Justin L',
avatar: 'test.jpg',
2023-06-20 12:24:39 -07:00
source: {
chats_onboarded: true,
},
2022-10-03 06:14:45 -07:00
});
const store = rootState
.set('me', id)
2023-06-20 12:24:39 -07:00
.set('entities', {
'ACCOUNTS': {
store: {
[id]: account,
},
lists: {},
},
});
2022-10-03 06:14:45 -07:00
describe('<ChatWidget />', () => {
describe('when on the /chats endpoint', () => {
it('hides the widget', async () => {
const App = () => (
<Switch>
<Route path='/chats' exact><span>Chats page <ChatWidget /></span></Route>
<Route path='/' exact><span data-testid='home'>Homepage <ChatWidget /></span></Route>
</Switch>
);
const screen = render(
<App />,
{},
store,
{ initialEntries: ['/chats'] },
);
expect(screen.queryAllByTestId('pane')).toHaveLength(0);
});
});
2023-06-20 19:44:07 -07:00
// describe('when the user has not onboarded chats', () => {
// it('hides the widget', async () => {
// const accountWithoutChats = buildAccount({
// id,
// acct: 'justin-username',
// display_name: 'Justin L',
// avatar: 'test.jpg',
// source: {
// chats_onboarded: false,
// },
// });
// const newStore = store.set('entities', {
// 'ACCOUNTS': {
// store: {
// [id]: accountWithoutChats,
// },
// lists: {},
// },
// });
2022-10-03 06:14:45 -07:00
2023-06-20 19:44:07 -07:00
// const screen = render(
// <ChatWidget />,
// {},
// newStore,
// );
2022-10-03 06:14:45 -07:00
2023-06-20 19:44:07 -07:00
// expect(screen.queryAllByTestId('pane')).toHaveLength(0);
// });
// });
2022-10-03 06:14:45 -07:00
describe('when the user is onboarded and the endpoint is not /chats', () => {
it('shows the widget', async () => {
const App = () => (
<Switch>
<Route path='/chats' exact><span>Chats page <ChatWidget /></span></Route>
<Route path='/' exact><span data-testid='home'>Homepage <ChatWidget /></span></Route>
</Switch>
);
const screen = render(
<App />,
{},
store,
{ initialEntries: ['/'] },
);
expect(screen.queryAllByTestId('pane')).toHaveLength(1);
});
});
});