From d95ae29341f0383dc74eeec4f5c554ef4d0b8d1d Mon Sep 17 00:00:00 2001 From: Tasso Date: Tue, 16 Jul 2024 10:10:59 -0300 Subject: [PATCH] Fix conflicts with new tests --- .../hooks/useAuditMenu.spec.tsx | 27 +-- .../hooks/useMarketPlaceMenu.spec.tsx | 52 +++-- .../hooks/useAdministrationMenu.spec.tsx | 8 +- .../InfoPanel/RetentionPolicyCallout.spec.tsx | 7 +- .../lib/parseMessageTextToAstMarkdown.spec.ts | 195 +++++++++--------- .../hooks/useGroupingListItems.spec.tsx | 4 +- .../actions/hooks/useSortModeItems.spec.tsx | 4 +- .../actions/hooks/useViewModeItems.spec.tsx | 6 +- .../room/body/RetentionPolicyWarning.spec.tsx | 7 +- 9 files changed, 161 insertions(+), 149 deletions(-) diff --git a/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useAuditMenu.spec.tsx b/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useAuditMenu.spec.tsx index 11eddf934055..6e8e5690b1fe 100644 --- a/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useAuditMenu.spec.tsx +++ b/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useAuditMenu.spec.tsx @@ -1,10 +1,11 @@ import { mockAppRoot } from '@rocket.chat/mock-providers'; -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook, waitFor } from '@testing-library/react'; import { useAuditMenu } from './useAuditMenu'; it('should return an empty array of items if doesn`t have license', async () => { - const { result, waitFor } = renderHook(() => useAuditMenu(), { + const { result } = renderHook(() => useAuditMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ // @ts-expect-error: just for testing @@ -18,13 +19,12 @@ it('should return an empty array of items if doesn`t have license', async () => .build(), }); - await waitFor(() => result.all.length > 1); - expect(result.current).toEqual([]); }); it('should return an empty array of items if have license and not have permissions', async () => { - const { result, waitFor } = renderHook(() => useAuditMenu(), { + const { result } = renderHook(() => useAuditMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ license: { @@ -41,13 +41,12 @@ it('should return an empty array of items if have license and not have permissio .build(), }); - await waitFor(() => result.all.length > 1); - expect(result.current).toEqual([]); }); it('should return auditItems if have license and permissions', async () => { - const { result, waitFor } = renderHook(() => useAuditMenu(), { + const { result } = renderHook(() => useAuditMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ license: { @@ -65,7 +64,7 @@ it('should return auditItems if have license and permissions', async () => { .build(), }); - await waitFor(() => result.current.length > 0); + await waitFor(() => expect(result.current[0]).toBeDefined()); expect(result.current[0].items[0]).toEqual( expect.objectContaining({ @@ -81,7 +80,8 @@ it('should return auditItems if have license and permissions', async () => { }); it('should return auditMessages item if have license and can-audit permission', async () => { - const { result, waitFor } = renderHook(() => useAuditMenu(), { + const { result } = renderHook(() => useAuditMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ license: { @@ -98,7 +98,7 @@ it('should return auditMessages item if have license and can-audit permission', .build(), }); - await waitFor(() => result.current.length > 0); + await waitFor(() => expect(result.current[0]).toBeDefined()); expect(result.current[0].items[0]).toEqual( expect.objectContaining({ @@ -108,7 +108,8 @@ it('should return auditMessages item if have license and can-audit permission', }); it('should return audiLogs item if have license and can-audit-log permission', async () => { - const { result, waitFor } = renderHook(() => useAuditMenu(), { + const { result } = renderHook(() => useAuditMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ license: { @@ -125,7 +126,7 @@ it('should return audiLogs item if have license and can-audit-log permission', a .build(), }); - await waitFor(() => result.current.length > 0); + await waitFor(() => expect(result.current[0]).toBeDefined()); expect(result.current[0].items[0]).toEqual( expect.objectContaining({ diff --git a/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useMarketPlaceMenu.spec.tsx b/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useMarketPlaceMenu.spec.tsx index 2a3d277e69fe..b121b8973fdd 100644 --- a/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useMarketPlaceMenu.spec.tsx +++ b/apps/meteor/client/NavBarV2/NavBarPagesToolbar/hooks/useMarketPlaceMenu.spec.tsx @@ -1,11 +1,12 @@ import { UIActionButtonContext } from '@rocket.chat/apps-engine/definition/ui'; import { mockAppRoot } from '@rocket.chat/mock-providers'; -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook, waitFor } from '@testing-library/react'; import { useMarketPlaceMenu } from './useMarketPlaceMenu'; it('should return and empty array if the user does not have `manage-apps` and `access-marketplace` permission', () => { const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => []) .build(), @@ -16,6 +17,7 @@ it('should return and empty array if the user does not have `manage-apps` and `a it('should return `explore` and `installed` items if the user has `access-marketplace` permission', () => { const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => []) .withPermission('access-marketplace') @@ -37,6 +39,7 @@ it('should return `explore` and `installed` items if the user has `access-market it('should return `explore`, `installed` and `requested` items if the user has `manage-apps` permission', () => { const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => []) .withEndpoint('GET', '/apps/app-request/stats', () => ({ @@ -69,7 +72,8 @@ it('should return `explore`, `installed` and `requested` items if the user has ` }); it('should return one action from the server with no conditions', async () => { - const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), { + const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => [ { @@ -101,18 +105,19 @@ it('should return one action from the server with no conditions', async () => { }), ); - await waitForValueToChange(() => result.current[0].items[3]); - - expect(result.current[0].items[3]).toEqual( - expect.objectContaining({ - id: 'APP_ID_ACTION_ID', - }), + await waitFor(() => + expect(result.current[0].items[3]).toEqual( + expect.objectContaining({ + id: 'APP_ID_ACTION_ID', + }), + ), ); }); describe('Marketplace menu with role conditions', () => { it('should return the action if the user has admin role', async () => { - const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), { + const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => [ { @@ -149,17 +154,18 @@ describe('Marketplace menu with role conditions', () => { }), ); - await waitForValueToChange(() => result.current[0].items[3]); - - expect(result.current[0].items[3]).toEqual( - expect.objectContaining({ - id: 'APP_ID_ACTION_ID', - }), + await waitFor(() => + expect(result.current[0].items[3]).toEqual( + expect.objectContaining({ + id: 'APP_ID_ACTION_ID', + }), + ), ); }); it('should return filter the action if the user doesn`t have admin role', async () => { const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => [ { @@ -206,7 +212,8 @@ describe('Marketplace menu with role conditions', () => { describe('Marketplace menu with permission conditions', () => { it('should return the action if the user has manage-apps permission', async () => { - const { result, waitForValueToChange } = renderHook(() => useMarketPlaceMenu(), { + const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => [ { @@ -241,17 +248,18 @@ describe('Marketplace menu with permission conditions', () => { }), ); - await waitForValueToChange(() => result.current[0].items[3]); - - expect(result.current[0].items[3]).toEqual( - expect.objectContaining({ - id: 'APP_ID_ACTION_ID', - }), + await waitFor(() => + expect(result.current[0].items[3]).toEqual( + expect.objectContaining({ + id: 'APP_ID_ACTION_ID', + }), + ), ); }); it('should return filter the action if the user doesn`t have `any` permission', async () => { const { result } = renderHook(() => useMarketPlaceMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/apps/actionButtons', () => [ { diff --git a/apps/meteor/client/NavBarV2/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx b/apps/meteor/client/NavBarV2/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx index 1315d1053392..29dfe21c2b4c 100644 --- a/apps/meteor/client/NavBarV2/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx +++ b/apps/meteor/client/NavBarV2/NavBarSettingsToolbar/hooks/useAdministrationMenu.spec.tsx @@ -1,10 +1,11 @@ import { mockAppRoot } from '@rocket.chat/mock-providers'; -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook, waitFor } from '@testing-library/react'; import { useAdministrationMenu } from './useAdministrationMenu'; it('should return omnichannel item if has `view-livechat-manager` permission ', async () => { - const { result, waitFor } = renderHook(() => useAdministrationMenu(), { + const { result } = renderHook(() => useAdministrationMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ // @ts-expect-error this is a mock @@ -29,7 +30,8 @@ it('should return omnichannel item if has `view-livechat-manager` permission ', }); it('should show administration item if has at least one admin permission', async () => { - const { result, waitFor } = renderHook(() => useAdministrationMenu(), { + const { result } = renderHook(() => useAdministrationMenu(), { + legacyRoot: true, wrapper: mockAppRoot() .withEndpoint('GET', '/v1/licenses.info', () => ({ // @ts-expect-error this is a mock diff --git a/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx b/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx index 9a2e7eac4c45..1af715cc8071 100644 --- a/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx +++ b/apps/meteor/client/components/InfoPanel/RetentionPolicyCallout.spec.tsx @@ -1,6 +1,5 @@ import { render, screen } from '@testing-library/react'; import React from 'react'; -import '@testing-library/jest-dom/extend-expect'; import { createRenteionPolicySettingsMock as createMock } from '../../../tests/mocks/client/mockRetentionPolicySettings'; import { createFakeRoom } from '../../../tests/mocks/data'; @@ -13,7 +12,10 @@ describe('RetentionPolicyCallout', () => { it('Should render callout if settings are valid', () => { setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); - render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) }); + render(, { + legacyRoot: true, + wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }), + }); expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM'); }); @@ -21,6 +23,7 @@ describe('RetentionPolicyCallout', () => { setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { + legacyRoot: true, wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }), }); expect(screen.queryByRole('alert')).not.toBeInTheDocument(); diff --git a/apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts b/apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts index 1e5856d0103a..527581ae56db 100644 --- a/apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts +++ b/apps/meteor/client/lib/parseMessageTextToAstMarkdown.spec.ts @@ -1,7 +1,7 @@ import type { IMessage, ITranslatedMessage, MessageQuoteAttachment } from '@rocket.chat/core-typings'; import type { Options, Root } from '@rocket.chat/message-parser'; -import { parseMessageAttachments, parseMessageQuoteAttachment, parseMessageTextToAstMarkdown } from './parseMessageTextToAstMarkdown'; +import { parseMessageAttachments, parseMessageAttachment, parseMessageTextToAstMarkdown } from './parseMessageTextToAstMarkdown'; describe('parseMessageTextToAstMarkdown', () => { const date = new Date('2021-10-27T00:00:00.000Z'); @@ -549,7 +549,7 @@ describe('parseMessageAttachments', () => { }); }); -describe('parseMessageQuoteAttachment', () => { +describe('parseMessageAttachment', () => { const parseOptions: Options = { colors: true, emoticons: true, @@ -615,128 +615,121 @@ describe('parseMessageQuoteAttachment', () => { author_name: 'authorName', author_link: 'link', author_icon: 'icon', + message_link: 'http://localhost/any_link', text: 'message **bold** _italic_ and ~strike~', md: messageParserTokenMessage, }; - describe('parseMessageQuoteAttachment', () => { - it('should return md property populated if the quote is parsed', () => { - expect(parseMessageQuoteAttachment(quoteMessage, parseOptions, autoTranslateOptions).md).toStrictEqual(messageParserTokenMessage); - }); + it('should return md property populated if the quote is parsed', () => { + expect(parseMessageAttachment(quoteMessage, parseOptions, autoTranslateOptions).md).toStrictEqual(messageParserTokenMessage); + }); - it('should return md property populated if the quote is not parsed', () => { - expect( - parseMessageQuoteAttachment( - { ...quoteMessage, md: undefined } as unknown as MessageQuoteAttachment, - parseOptions, - autoTranslateOptions, - ).md, - ).toStrictEqual(messageParserTokenMessage); + it('should return md property populated if the quote is not parsed', () => { + expect( + parseMessageAttachment({ ...quoteMessage, md: undefined } as unknown as MessageQuoteAttachment, parseOptions, autoTranslateOptions) + .md, + ).toStrictEqual(messageParserTokenMessage); + }); + + describe('translated', () => { + const translatedQuote = { + ...quoteMessage, + text: 'quote not translated', + translationProvider: 'provider', + translations: { + en: 'quote translated', + }, + }; + const translatedMessageParsed: Root = [ + { + type: 'PARAGRAPH', + value: [ + { + type: 'PLAIN_TEXT', + value: 'quote translated', + }, + ], + }, + ]; + + const enabledAutoTranslatedOptions = { + translated: true, + autoTranslateLanguage: 'en', + }; + it('should return correct quote translated parsed md when translate is active', () => { + expect(parseMessageAttachment(translatedQuote, parseOptions, enabledAutoTranslatedOptions).md).toStrictEqual(translatedMessageParsed); }); - describe('translated', () => { - const translatedQuote = { - ...quoteMessage, - text: 'quote not translated', - translationProvider: 'provider', - translations: { - en: 'quote translated', - }, - }; - const translatedMessageParsed: Root = [ + it('should return text parsed md when translate is active and autoTranslateLanguage is undefined', () => { + expect( + parseMessageAttachment(translatedQuote, parseOptions, { ...enabledAutoTranslatedOptions, autoTranslateLanguage: undefined }).md, + ).toStrictEqual([ { type: 'PARAGRAPH', value: [ { type: 'PLAIN_TEXT', - value: 'quote translated', + value: 'quote not translated', }, ], }, - ]; + ]); + }); - const enabledAutoTranslatedOptions = { - translated: true, - autoTranslateLanguage: 'en', - }; - it('should return correct quote translated parsed md when translate is active', () => { - expect(parseMessageQuoteAttachment(translatedQuote, parseOptions, enabledAutoTranslatedOptions).md).toStrictEqual( - translatedMessageParsed, - ); - }); + it('should return correct multiple attachment quote translated parsed md when translate is active', () => { + const quote = { ...quoteMessage, text: 'text level 2', translations: { en: 'text level 2 translated' } }; - it('should return text parsed md when translate is active and autoTranslateLanguage is undefined', () => { - expect( - parseMessageQuoteAttachment(translatedQuote, parseOptions, { ...enabledAutoTranslatedOptions, autoTranslateLanguage: undefined }) - .md, - ).toStrictEqual([ + const multipleQuotes = { + ...translatedQuote, + attachments: [ { - type: 'PARAGRAPH', - value: [ + ...translatedQuote, + text: 'text', + translations: { + en: 'text translated', + }, + attachments: [quote], + }, + ], + }; + const multipleQuotesParsed = { + ...translatedQuote, + md: translatedMessageParsed, + attachments: [ + { + ...multipleQuotes.attachments[0], + md: [ { - type: 'PLAIN_TEXT', - value: 'quote not translated', + type: 'PARAGRAPH', + value: [ + { + type: 'PLAIN_TEXT', + value: 'text translated', + }, + ], }, ], - }, - ]); - }); - - it('should return correct multiple attachment quote translated parsed md when translate is active', () => { - const quote = { ...quoteMessage, text: 'text level 2', translations: { en: 'text level 2 translated' } }; - - const multipleQuotes = { - ...translatedQuote, - attachments: [ - { - ...translatedQuote, - text: 'text', - translations: { - en: 'text translated', + attachments: [ + { + ...quote, + md: [ + { + type: 'PARAGRAPH', + value: [ + { + type: 'PLAIN_TEXT', + value: 'text level 2 translated', + }, + ], + }, + ], }, - attachments: [quote], - }, - ], - }; - const multipleQuotesParsed = { - ...translatedQuote, - md: translatedMessageParsed, - attachments: [ - { - ...multipleQuotes.attachments[0], - md: [ - { - type: 'PARAGRAPH', - value: [ - { - type: 'PLAIN_TEXT', - value: 'text translated', - }, - ], - }, - ], - attachments: [ - { - ...quote, - md: [ - { - type: 'PARAGRAPH', - value: [ - { - type: 'PLAIN_TEXT', - value: 'text level 2 translated', - }, - ], - }, - ], - }, - ], - }, - ], - }; + ], + }, + ], + }; - expect(parseMessageQuoteAttachment(multipleQuotes, parseOptions, enabledAutoTranslatedOptions)).toStrictEqual(multipleQuotesParsed); - }); + expect(parseMessageAttachment(multipleQuotes, parseOptions, enabledAutoTranslatedOptions)).toStrictEqual(multipleQuotesParsed); }); }); }); diff --git a/apps/meteor/client/sidebarv2/header/actions/hooks/useGroupingListItems.spec.tsx b/apps/meteor/client/sidebarv2/header/actions/hooks/useGroupingListItems.spec.tsx index b5779d825202..08363b0ee036 100644 --- a/apps/meteor/client/sidebarv2/header/actions/hooks/useGroupingListItems.spec.tsx +++ b/apps/meteor/client/sidebarv2/header/actions/hooks/useGroupingListItems.spec.tsx @@ -1,9 +1,9 @@ -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook } from '@testing-library/react'; import { useGroupingListItems } from './useGroupingListItems'; it('should render groupingList items', async () => { - const { result } = renderHook(() => useGroupingListItems()); + const { result } = renderHook(() => useGroupingListItems(), { legacyRoot: true }); expect(result.current[0]).toEqual( expect.objectContaining({ diff --git a/apps/meteor/client/sidebarv2/header/actions/hooks/useSortModeItems.spec.tsx b/apps/meteor/client/sidebarv2/header/actions/hooks/useSortModeItems.spec.tsx index 143d228fe7ca..46d5aab37321 100644 --- a/apps/meteor/client/sidebarv2/header/actions/hooks/useSortModeItems.spec.tsx +++ b/apps/meteor/client/sidebarv2/header/actions/hooks/useSortModeItems.spec.tsx @@ -1,9 +1,9 @@ -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook } from '@testing-library/react'; import { useSortModeItems } from './useSortModeItems'; it('should render sortMode items', async () => { - const { result } = renderHook(() => useSortModeItems()); + const { result } = renderHook(() => useSortModeItems(), { legacyRoot: true }); expect(result.current[0]).toEqual( expect.objectContaining({ diff --git a/apps/meteor/client/sidebarv2/header/actions/hooks/useViewModeItems.spec.tsx b/apps/meteor/client/sidebarv2/header/actions/hooks/useViewModeItems.spec.tsx index 6c6dd7532e7e..e114aa8ad11c 100644 --- a/apps/meteor/client/sidebarv2/header/actions/hooks/useViewModeItems.spec.tsx +++ b/apps/meteor/client/sidebarv2/header/actions/hooks/useViewModeItems.spec.tsx @@ -1,9 +1,11 @@ -import { renderHook } from '@testing-library/react-hooks'; +import { renderHook } from '@testing-library/react'; import { useViewModeItems } from './useViewModeItems'; it('should render viewMode items', async () => { - const { result } = renderHook(() => useViewModeItems()); + const { result } = renderHook(() => useViewModeItems(), { + legacyRoot: true, + }); expect(result.current[0]).toEqual( expect.objectContaining({ diff --git a/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx b/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx index 28a6eca3b283..7f154771471e 100644 --- a/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx +++ b/apps/meteor/client/views/room/body/RetentionPolicyWarning.spec.tsx @@ -1,6 +1,5 @@ import { render, screen } from '@testing-library/react'; import React from 'react'; -import '@testing-library/jest-dom/extend-expect'; import { createRenteionPolicySettingsMock as createMock } from '../../../../tests/mocks/client/mockRetentionPolicySettings'; import { createFakeRoom } from '../../../../tests/mocks/data'; @@ -13,7 +12,10 @@ describe('RetentionPolicyWarning', () => { it('Should render callout if settings are valid', () => { setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); - render(, { wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }) }); + render(, { + legacyRoot: true, + wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }), + }); expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024, 12:30 AM'); }); @@ -21,6 +23,7 @@ describe('RetentionPolicyWarning', () => { setDate(); const fakeRoom = createFakeRoom({ t: 'c' }); render(, { + legacyRoot: true, wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }), }); expect(screen.queryByRole('alert')).not.toBeInTheDocument();