Skip to content

Commit

Permalink
[WIP] Adjust tests, return CooldownTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Oct 10, 2023
1 parent c691899 commit 22aff77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 55 deletions.
10 changes: 10 additions & 0 deletions src/components/MessageInput/MessageInputFlat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ const MessageInputV1 = <
isUploadEnabled,
maxFilesLeft,
numberOfUploads,
setCooldownRemaining,
uploadNewFiles,
} = useMessageInputContext<StreamChatGenerics>('MessageInputFlat');

const {
CooldownTimer = DefaultCooldownTimer,
FileUploadIcon = DefaultFileUploadIcon,
QuotedMessagePreview = DefaultQuotedMessagePreview,
SendButton = DefaultSendButton,
Expand Down Expand Up @@ -116,6 +118,14 @@ const MessageInputV1 = <
<EmojiPicker />
</div>
)}
{cooldownRemaining && (
<div className='str-chat__input-flat-cooldown'>
<CooldownTimer
cooldownInterval={cooldownRemaining}
setCooldownRemaining={setCooldownRemaining}
/>
</div>
)}
<ChatAutoComplete />
{isUploadEnabled && !cooldownRemaining && (
<div className='str-chat__fileupload-wrapper' data-testid='fileinput'>
Expand Down
66 changes: 11 additions & 55 deletions src/components/MessageInput/__tests__/MessageInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ function axeNoViolations(container) {
});
afterEach(tearDown);

it('should render custom EmojiPicker', async () => {
const CustomEmojiPicker = () => <div data-testid='custom-emoji-picker' />;

await renderComponent({ channelProps: { EmojiPicker: CustomEmojiPicker } });

await waitFor(() => {
const c = screen.getByTestId('custom-emoji-picker');
expect(c).toBeInTheDocument();
});
});

it('should contain placeholder text if no default message text provided', async () => {
await renderComponent();
await waitFor(() => {
Expand Down Expand Up @@ -218,35 +229,6 @@ function axeNoViolations(container) {
expect(results).toHaveNoViolations();
});

it('Should render default emoji svg', async () => {
const { container } = await renderComponent();
const emojiIcon = await screen.findByTitle('Open emoji picker');

await waitFor(() => {
expect(emojiIcon).toBeInTheDocument();
});
const results = await axe(container);
expect(results).toHaveNoViolations();
});

it('Should render custom emoji svg provided as prop', async () => {
const EmojiIcon = () => (
<svg>
<title>NotEmoji</title>
</svg>
);

const { container } = await renderComponent({ channelProps: { EmojiIcon } });

const emojiIcon = await screen.findByTitle('NotEmoji');

await waitFor(() => {
expect(emojiIcon).toBeInTheDocument();
});
const results = await axe(container);
expect(results).toHaveNoViolations();
});

it('Should render default file upload icon', async () => {
const { container } = await renderComponent();
const fileUploadIcon = await screen.findByTitle('Attach files');
Expand Down Expand Up @@ -276,32 +258,6 @@ function axeNoViolations(container) {
expect(results).toHaveNoViolations();
});

it('Should open the emoji picker after clicking the icon, and allow adding emojis to the message', async () => {
const { container } = await renderComponent();

const emojiIcon = await screen.findByTitle('Open emoji picker');

act(() => fireEvent.click(emojiIcon));

await waitFor(() => {
expect(container.querySelector('.emoji-mart')).toBeInTheDocument();
});

const emoji = '💯';
const emojiButton = screen.queryAllByText(emoji)[0];
expect(emojiButton).toBeInTheDocument();
act(() => fireEvent.click(emojiButton));

// expect input to have emoji as value
expect(screen.getByDisplayValue(emoji)).toBeInTheDocument();

// close picker
act(() => fireEvent.click(container));
expect(container.querySelector('.emoji-mart')).not.toBeInTheDocument();
const results = await axe(container);
expect(results).toHaveNoViolations();
});

describe('Attachments', () => {
it('Pasting images and files should result in uploading the files and showing previewers', async () => {
// FIXME: act is missing somewhere within this test which results in unwanted warning
Expand Down

0 comments on commit 22aff77

Please sign in to comment.