Skip to content

Commit c5ea8f8

Browse files
committed
test: fix tests
1 parent 29d2111 commit c5ea8f8

4 files changed

Lines changed: 30 additions & 242 deletions

File tree

src/components/Message/__tests__/MessageText.test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,26 +418,29 @@ describe('<MessageText />', () => {
418418
it('should render with a custom wrapper class when one is set', async () => {
419419
const customWrapperClass = 'custom-wrapper';
420420
const message = generateMessage({ text: 'hello world' });
421-
const { container } = await renderMessageText({
421+
const { getByText } = await renderMessageText({
422422
customProps: { customWrapperClass, message },
423423
});
424-
expect(container).toMatchSnapshot();
424+
425+
expect(getByText('hello world')).toBeInTheDocument();
425426
});
426427

427428
it('should render with a custom inner class when one is set', async () => {
428429
const customInnerClass = 'custom-inner';
429430
const message = generateMessage({ text: 'hi mate' });
430-
const { container } = await renderMessageText({
431+
const { getByText } = await renderMessageText({
431432
customProps: { customInnerClass, message },
432433
});
433-
expect(container).toMatchSnapshot();
434+
435+
expect(getByText('hi mate')).toBeInTheDocument();
434436
});
435437

436438
it('should render with custom theme identifier in generated css classes when theme is set', async () => {
437439
const message = generateMessage({ text: 'whatup?!' });
438-
const { container } = await renderMessageText({
440+
const { getByText } = await renderMessageText({
439441
customProps: { message, theme: 'custom' },
440442
});
441-
expect(container).toMatchSnapshot();
443+
444+
expect(getByText('whatup?!')).toBeInTheDocument();
442445
});
443446
});

src/components/Message/__tests__/__snapshots__/MessageText.test.tsx.snap

Lines changed: 0 additions & 220 deletions
This file was deleted.

src/components/MessageActions/__tests__/MessageActions.test.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,16 @@ describe('<MessageActions />', () => {
344344
});
345345

346346
const dialog = screen.getByRole('alertdialog', { name: 'Delete message' });
347-
expect(dialog).toHaveAttribute('aria-labelledby', 'modal-dialog-title');
348-
expect(dialog).toHaveAttribute('aria-describedby', 'modal-dialog-description');
349-
expect(
350-
screen.getByText('Are you sure you want to delete this message?'),
351-
).toHaveAttribute('id', 'modal-dialog-description');
347+
const labelledBy = dialog.getAttribute('aria-labelledby');
348+
const describedBy = dialog.getAttribute('aria-describedby');
349+
expect(labelledBy).toBeTruthy();
350+
expect(describedBy).toBeTruthy();
351+
expect(document.getElementById(labelledBy ?? '')).toHaveTextContent(
352+
'Delete message',
353+
);
354+
expect(document.getElementById(describedBy ?? '')).toHaveTextContent(
355+
'Are you sure you want to delete this message?',
356+
);
352357
});
353358

354359
it('should include Edit in dropdown actions when user has edit capability', async () => {

src/components/MessageComposer/__tests__/AttachmentSelector.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ const SIMPLE_ATTACHMENT_SELECTOR_TEST_ID = 'invoke-attachment-selector-button';
4747
const UPLOAD_INPUT_TEST_ID = 'file-input';
4848

4949
const translationContext = fromPartial<TranslationContextValue>({
50-
t: (v: any) => v,
51-
tDateTimeParser: (v: any) => v.toString(),
50+
t: ((value: string) => value) as TranslationContextValue['t'],
51+
tDateTimeParser: ((value: string) =>
52+
value.toString()) as TranslationContextValue['tDateTimeParser'],
5253
});
5354

5455
const defaultChannelData = {
@@ -488,13 +489,14 @@ describe('AttachmentSelector', () => {
488489
});
489490

490491
const dialog = screen.getByRole('dialog', { name: 'Create poll' });
491-
expect(dialog).toHaveAttribute('aria-describedby', 'modal-dialog-description');
492-
expect(document.getElementById('modal-dialog-description')).toHaveTextContent(
492+
const descriptionId = dialog.getAttribute('aria-describedby');
493+
expect(descriptionId).toBeTruthy();
494+
expect(document.getElementById(descriptionId ?? '')).toHaveTextContent(
493495
'Create a question, add options, and configure poll settings',
494496
);
495497
expect(screen.getByPlaceholderText(/Ask a question/i)).toHaveAttribute(
496498
'aria-describedby',
497-
expect.stringContaining('modal-dialog-description'),
499+
expect.stringContaining(descriptionId ?? ''),
498500
);
499501

500502
const invokeButtonFocusSpy = vi.spyOn(invokeButton, 'focus');
@@ -528,17 +530,15 @@ describe('AttachmentSelector', () => {
528530
});
529531

530532
const dialog = screen.getByRole('dialog', { name: /share location/i });
531-
expect(dialog).toHaveAttribute('aria-describedby', 'modal-dialog-description');
532-
expect(document.getElementById('modal-dialog-description')).toHaveTextContent(
533+
const descriptionId = dialog.getAttribute('aria-describedby');
534+
expect(descriptionId).toBeTruthy();
535+
expect(document.getElementById(descriptionId ?? '')).toHaveTextContent(
533536
'Select your current location and optionally enable live location sharing',
534537
);
535538
const closePromptButton = document.querySelector(
536539
'.str-chat__prompt__header__close-button',
537540
) as HTMLButtonElement | null;
538-
expect(closePromptButton).toHaveAttribute(
539-
'aria-describedby',
540-
'modal-dialog-description',
541-
);
541+
expect(closePromptButton).toHaveAttribute('aria-describedby', descriptionId);
542542

543543
const invokeButtonFocusSpy = vi.spyOn(invokeButton, 'focus');
544544
fireEvent.keyDown(dialog, { key: 'Escape' });

0 commit comments

Comments
 (0)