Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Upgrade React #32288

Merged
merged 10 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adapt unit tests
  • Loading branch information
tassoevan committed Jan 28, 2025
commit 80eed2c8858cb50ef56beec9bd3064a129314399
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useAuditMenu } from './useAuditMenu';

it('should return an empty array of items if doesn`t have license', async () => {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error: just for testing
Expand All @@ -24,7 +23,6 @@ it('should return an empty array of items if doesn`t have license', async () =>

it('should return an empty array of items if have license and not have permissions', async () => {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand All @@ -46,7 +44,6 @@ it('should return an empty array of items if have license and not have permissio

it('should return auditItems if have license and permissions', async () => {
const { result } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand Down Expand Up @@ -81,7 +78,6 @@ 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 } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand Down Expand Up @@ -109,7 +105,6 @@ 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 } = renderHook(() => useAuditMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
license: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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(),
Expand All @@ -17,7 +16,6 @@ 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')
Expand All @@ -39,7 +37,6 @@ 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', () => ({
Expand Down Expand Up @@ -73,7 +70,6 @@ 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 } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -117,7 +113,6 @@ it('should return one action from the server with no conditions', async () => {
describe('Marketplace menu with role conditions', () => {
it('should return the action if the user has admin role', async () => {
const { result } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -165,7 +160,6 @@ describe('Marketplace menu with role conditions', () => {

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', () => [
{
Expand Down Expand Up @@ -213,7 +207,6 @@ 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 } = renderHook(() => useMarketPlaceMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/apps/actionButtons', () => [
{
Expand Down Expand Up @@ -259,7 +252,6 @@ describe('Marketplace menu with permission conditions', () => {

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', () => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useAdministrationMenu } from './useAdministrationMenu';

it('should return omnichannel item if has `view-livechat-manager` permission ', async () => {
const { result } = renderHook(() => useAdministrationMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error this is a mock
Expand All @@ -31,7 +30,6 @@ 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 } = renderHook(() => useAdministrationMenu(), {
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/licenses.info', () => ({
// @ts-expect-error this is a mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const renderModal = (modalElement: ReactElement) => {
const {
result: { current: setModal },
} = renderHook(() => useSetModal(), {
legacyRoot: true,
wrapper: ({ children }) => (
<Suspense fallback={null}>
<ModalProviderWithRegion>{children}</ModalProviderWithRegion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('RetentionPolicyCallout', () => {
it('Should render callout if settings are valid', () => {
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyCallout room={fakeRoom} />, {
legacyRoot: true,
wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000 }),
});
expect(screen.getByRole('alert')).toHaveTextContent('a minute June 1, 2024 at 12:30 AM');
Expand All @@ -23,7 +22,6 @@ describe('RetentionPolicyCallout', () => {
it('Should not render callout if settings are invalid', () => {
const fakeRoom = createFakeRoom({ t: 'c' });
render(<RetentionPolicyCallout room={fakeRoom} />, {
legacyRoot: true,
wrapper: createMock({ appliesToChannels: true, TTLChannels: 60000, advancedPrecisionCron: '* * * 12 *', advancedPrecision: true }),
});
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/client/components/MarkdownText.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const markdownText = `
it('should render html elements as expected using default parser', async () => {
const { container } = render(<MarkdownText content={markdownText} variant='document' />, {
wrapper: mockAppRoot().build(),
legacyRoot: true,
});

const normalizedHtml = normalizeHtml(container.innerHTML);
Expand Down Expand Up @@ -73,7 +72,6 @@ it('should render html elements as expected using default parser', async () => {
it('should render html elements as expected using inline parser', async () => {
const { container } = render(<MarkdownText content={markdownText} variant='inline' />, {
wrapper: mockAppRoot().build(),
legacyRoot: true,
});

const normalizedHtml = normalizeHtml(container.innerHTML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ it('should not fetch and add selected department if it is already in the departm
selectedDepartment: '5',
}),
{
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/livechat/department', () => ({
count: 25,
Expand Down Expand Up @@ -90,7 +89,6 @@ it('should fetch and add selected department if it is not part of departments li
selectedDepartment: '56f5be8bcf8cd67f9e9bcfdc',
}),
{
legacyRoot: true,
wrapper: mockAppRoot()
.withEndpoint('GET', '/v1/livechat/department', () => ({
count: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const defaultProps = {

it('should show Undo request button when roomOpen is true and transcriptRequest exist', async () => {
const onDiscardMock = jest.fn();
render(<TranscriptModal {...defaultProps} onDiscard={onDiscardMock} />, { legacyRoot: true });
render(<TranscriptModal {...defaultProps} onDiscard={onDiscardMock} />);

const undoRequestButton = await screen.findByText('Undo_request');
await userEvent.click(undoRequestButton);
Expand All @@ -33,14 +33,14 @@ it('should show Undo request button when roomOpen is true and transcriptRequest
});

it('should show Request button when roomOpen is true and transcriptRequest not exist', async () => {
render(<TranscriptModal {...{ ...defaultProps, room: { ...room, transcriptRequest: undefined } }} />, { legacyRoot: true });
render(<TranscriptModal {...{ ...defaultProps, room: { ...room, transcriptRequest: undefined } }} />);

const requestBtn = await screen.findByRole('button', { name: 'request-button' });
expect(requestBtn).toBeInTheDocument();
});

it('should show Send button when roomOpen is false', async () => {
render(<TranscriptModal {...{ ...defaultProps, room: { ...room, open: false } }} />, { legacyRoot: true });
render(<TranscriptModal {...{ ...defaultProps, room: { ...room, open: false } }} />);

const sendBtn = await screen.findByRole('button', { name: 'send-button' });
expect(sendBtn).toBeInTheDocument();
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/client/components/WarningModal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import WarningModal from './WarningModal';

it('should look good', async () => {
render(<WarningModal text='text' confirmText='confirm' cancelText='cancel' confirm={() => undefined} close={() => undefined} />, {
legacyRoot: true,
wrapper: mockAppRoot().build(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('Thread Metrics', () => {
.withSetting('Message_TimeFormat', 'LT')
.withTranslations(...mockedTranslations)
.buildWithRouter(navigateCallback),
legacyRoot: true,
},
);

Expand Down Expand Up @@ -151,7 +150,6 @@ describe('Thread Metrics', () => {
.withSetting('Message_TimeFormat', 'LT')
.withTranslations(...mockedTranslations)
.buildWithRouter(navigateCallback),
legacyRoot: true,
},
);
const followButton = screen.getByTitle('Not_following');
Expand Down Expand Up @@ -184,7 +182,6 @@ describe('Thread Metrics', () => {
toggleFollowMock(() => undefined),
)
.build(),
legacyRoot: true,
});
const followButton = screen.getByTitle('Not_following');
expect(followButton).toBeVisible();
Expand All @@ -199,7 +196,6 @@ describe('Thread Metrics', () => {
toggleFollowMock(() => undefined),
)
.build(),
legacyRoot: true,
});
const followButton = screen.getByTitle('Following');
expect(followButton).toBeVisible();
Expand All @@ -208,23 +204,20 @@ describe('Thread Metrics', () => {
it('should render unread badge', () => {
render(<ThreadMetricsFollow unread={true} mention={false} all={false} mid='mid' rid='rid' following={false} />, {
wrapper: mockAppRoot().build(),
legacyRoot: true,
});
const badge = screen.getByTitle('Unread');
expect(badge).toBeVisible();
});
it('should render mention-all badge', () => {
render(<ThreadMetricsFollow unread={true} mention={false} all={true} mid='mid' rid='rid' following={false} />, {
wrapper: mockAppRoot().build(),
legacyRoot: true,
});
const badge = screen.getByTitle('mention-all');
expect(badge).toBeVisible();
});
it('should render Mentions_you badge', () => {
render(<ThreadMetricsFollow unread={true} mention={true} all={false} mid='mid' rid='rid' following={false} />, {
wrapper: mockAppRoot().build(),
legacyRoot: true,
});
const badge = screen.getByTitle('Mentions_you');
expect(badge).toBeVisible();
Expand All @@ -237,7 +230,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', true)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
expect(screen.getByTitle('follower')).toBeVisible();
const avatars = screen.getAllByRole('figure');
Expand All @@ -250,7 +242,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', true)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
expect(screen.getByTitle('followers')).toBeVisible();
const avatars = screen.getAllByRole('figure');
Expand All @@ -263,7 +254,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', true)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
expect(screen.getByTitle('followers')).toBeVisible();
const avatars = screen.getAllByRole('figure');
Expand All @@ -277,7 +267,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', true)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
expect(screen.getByTitle('followers')).toBeVisible();

Expand All @@ -294,7 +283,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', false)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
const follower = screen.getByTitle('follower');
expect(follower).toBeVisible();
Expand All @@ -311,7 +299,6 @@ describe('Thread Metrics', () => {
.withUserPreference('displayAvatars', false)
.withTranslations(...mockedTranslations)
.build(),
legacyRoot: true,
});
const follower = screen.getByTitle('followers');
expect(follower).toBeVisible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ it('should be call rest `POST /v1/chat.react` method', async () => {
const fn = jest.fn();

const { result } = renderHook(() => useToggleReactionMutation(), {
legacyRoot: true,
wrapper: mockAppRoot().withEndpoint('POST', '/v1/chat.react', fn).withJohnDoe().build(),
});

Expand All @@ -25,7 +24,6 @@ it('should not work for non-logged in users', async () => {
const fn = jest.fn();

const { result } = renderHook(() => useToggleReactionMutation(), {
legacyRoot: true,
wrapper: mockAppRoot().withEndpoint('POST', '/v1/chat.react', fn).build(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ it('should show normal message', () => {
showUserAvatar={true}
/>,
{
legacyRoot: true,
wrapper: mockAppRoot().build(),
},
);
Expand All @@ -78,7 +77,6 @@ it('should show fallback content for ignored user', () => {
showUserAvatar={true}
/>,
{
legacyRoot: true,
wrapper: mockAppRoot().build(),
},
);
Expand All @@ -100,7 +98,6 @@ it('should show ignored message', () => {
showUserAvatar={true}
/>,
{
legacyRoot: true,
wrapper: mockAppRoot().build(),
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('useE2EERoomAction', () => {
it('should dispatch error toast message when otrState is ESTABLISHED', async () => {
(useOTR as jest.Mock).mockReturnValue({ otrState: OtrRoomState.ESTABLISHED });

const { result } = renderHook(() => useE2EERoomAction(), { legacyRoot: true });
const { result } = renderHook(() => useE2EERoomAction());

await act(async () => {
await result?.current?.action?.();
Expand All @@ -96,7 +96,7 @@ describe('useE2EERoomAction', () => {
it('should dispatch error toast message when otrState is ESTABLISHING', async () => {
(useOTR as jest.Mock).mockReturnValue({ otrState: OtrRoomState.ESTABLISHING });

const { result } = renderHook(() => useE2EERoomAction(), { legacyRoot: true });
const { result } = renderHook(() => useE2EERoomAction());

act(() => {
result?.current?.action?.();
Expand All @@ -108,7 +108,7 @@ describe('useE2EERoomAction', () => {
it('should dispatch error toast message when otrState is REQUESTED', async () => {
(useOTR as jest.Mock).mockReturnValue({ otrState: OtrRoomState.REQUESTED });

const { result } = renderHook(() => useE2EERoomAction(), { legacyRoot: true });
const { result } = renderHook(() => useE2EERoomAction());

act(() => {
result?.current?.action?.();
Expand All @@ -120,7 +120,7 @@ describe('useE2EERoomAction', () => {
it('should open Enable E2EE confirmation modal', async () => {
(useOTR as jest.Mock).mockReturnValue({ otrState: OtrRoomState.NOT_STARTED });

const { result } = renderHook(() => useE2EERoomAction(), { legacyRoot: true });
const { result } = renderHook(() => useE2EERoomAction());
act(() => {
result?.current?.action?.();
});
Expand Down
Loading