Skip to content

Commit c556c70

Browse files
committed
add team and livestream pin UI tests
1 parent 42f6658 commit c556c70

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

src/components/Message/MessageLivestream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ MessageLivestreamComponent.propTypes = {
473473
* Returns all allowed actions on message by current user e.g., ['edit', 'delete', 'flag', 'mute', 'react', 'reply']
474474
* Please check [Message](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Message.js) component for default implementation.
475475
* */
476-
getMessageActions: PropTypes.func.isRequired,
476+
getMessageActions: /** @type {PropTypes.Validator<() => Array<string>>} */ (PropTypes.func),
477477
/**
478478
* Function to publish updates on message to channel
479479
*

src/components/Message/__tests__/MessageLivestream.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { cleanup, render, fireEvent } from '@testing-library/react';
2+
import { cleanup, render, fireEvent, waitFor } from '@testing-library/react';
33
import '@testing-library/jest-dom';
44
import {
55
generateChannel,
@@ -163,6 +163,36 @@ describe('<MessageLivestream />', () => {
163163
expect(getByTestId('custom-avatar')).toBeInTheDocument();
164164
});
165165

166+
it('should render pin indicator when pinned is true', async () => {
167+
const message = generateAliceMessage({ pinned: true });
168+
const CustomPinIndicator = () => (
169+
<div data-testid="pin-indicator">Pin Indicator</div>
170+
);
171+
172+
const { getByTestId } = await renderMessageLivestream(message, {
173+
PinIndicator: CustomPinIndicator,
174+
});
175+
176+
await waitFor(() => {
177+
expect(getByTestId('pin-indicator')).toBeInTheDocument();
178+
});
179+
});
180+
181+
it('should not render pin indicator when pinned is false', async () => {
182+
const message = generateAliceMessage({ pinned: false });
183+
const CustomPinIndicator = () => (
184+
<div data-testid="pin-indicator">Pin Indicator</div>
185+
);
186+
187+
const { queryAllByTestId } = await renderMessageLivestream(message, {
188+
PinIndicator: CustomPinIndicator,
189+
});
190+
191+
await waitFor(() => {
192+
expect(queryAllByTestId('pin-indicator')).toHaveLength(0);
193+
});
194+
});
195+
166196
it('should render custom edit message input component when one is given', async () => {
167197
const message = generateAliceMessage();
168198
const updateMessage = jest.fn();

src/components/Message/__tests__/MessageTeam.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable sonarjs/no-duplicate-string */
22
import React from 'react';
3-
import { cleanup, render, fireEvent } from '@testing-library/react';
3+
import { cleanup, render, fireEvent, waitFor } from '@testing-library/react';
44
import '@testing-library/jest-dom';
55
import {
66
generateChannel,
@@ -160,6 +160,36 @@ describe('<MessageTeam />', () => {
160160
expect(getByTestId('custom-avatar')).toBeInTheDocument();
161161
});
162162

163+
it('should render pin indicator when pinned is true', async () => {
164+
const message = generateAliceMessage({ pinned: true });
165+
const CustomPinIndicator = () => (
166+
<div data-testid="pin-indicator">Pin Indicator</div>
167+
);
168+
169+
const { getByTestId } = await renderMessageTeam(message, {
170+
PinIndicator: CustomPinIndicator,
171+
});
172+
173+
await waitFor(() => {
174+
expect(getByTestId('pin-indicator')).toBeInTheDocument();
175+
});
176+
});
177+
178+
it('should not render pin indicator when pinned is false', async () => {
179+
const message = generateAliceMessage({ pinned: false });
180+
const CustomPinIndicator = () => (
181+
<div data-testid="pin-indicator">Pin Indicator</div>
182+
);
183+
184+
const { queryAllByTestId } = await renderMessageTeam(message, {
185+
PinIndicator: CustomPinIndicator,
186+
});
187+
188+
await waitFor(() => {
189+
expect(queryAllByTestId('pin-indicator')).toHaveLength(0);
190+
});
191+
});
192+
163193
it('should render custom edit message input component when one is given', async () => {
164194
const message = generateAliceMessage();
165195
const updateMessage = jest.fn();

0 commit comments

Comments
 (0)