-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/wrong-network-permission-name
- Loading branch information
Showing
18 changed files
with
341 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': patch | ||
--- | ||
|
||
Sends server statistics only once a day despite multiple instance being started at different times. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rocket.chat/livechat": patch | ||
--- | ||
|
||
Fixes livechat popout mode not working correctly in cross domain situations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rocket.chat/i18n': minor | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
Adds a confirmation modal to the cancel subscription action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
apps/meteor/client/views/admin/subscription/components/CancelSubscriptionModal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { CancelSubscriptionModal } from './CancelSubscriptionModal'; | ||
import { DOWNGRADE_LINK } from '../utils/links'; | ||
|
||
it('should display plan name in the title', async () => { | ||
const confirmFn = jest.fn(); | ||
render(<CancelSubscriptionModal planName='Starter' onConfirm={confirmFn} onCancel={jest.fn()} />, { | ||
wrapper: mockAppRoot() | ||
.withTranslations('en', 'core', { | ||
Cancel__planName__subscription: 'Cancel {{planName}} subscription', | ||
}) | ||
.build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should have link to downgrade docs', async () => { | ||
render(<CancelSubscriptionModal planName='Starter' onConfirm={jest.fn()} onCancel={jest.fn()} />, { | ||
wrapper: mockAppRoot() | ||
.withTranslations('en', 'core', { | ||
Cancel__planName__subscription: 'Cancel {{planName}} subscription', | ||
Cancel_subscription_message: | ||
'<strong>This workspace will downgrage to Community and lose free access to premium capabilities.</strong><br/><br/> While you can keep using Rocket.Chat, your team will lose access to unlimited mobile push notifications, read receipts, marketplace apps <4>and other capabilities</4>.', | ||
}) | ||
.build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
expect(screen.getByRole('link', { name: 'and other capabilities' })).toHaveAttribute('href', DOWNGRADE_LINK); | ||
}); | ||
|
||
it('should call onConfirm when confirm button is clicked', async () => { | ||
const confirmFn = jest.fn(); | ||
render(<CancelSubscriptionModal planName='Starter' onConfirm={confirmFn} onCancel={jest.fn()} />, { | ||
wrapper: mockAppRoot().build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Cancel_subscription' })); | ||
expect(confirmFn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onCancel when "Dont cancel" button is clicked', async () => { | ||
const cancelFn = jest.fn(); | ||
render(<CancelSubscriptionModal planName='Starter' onConfirm={jest.fn()} onCancel={cancelFn} />, { | ||
wrapper: mockAppRoot().build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Dont_cancel' })); | ||
expect(cancelFn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onCancel when close button is clicked', async () => { | ||
const cancelFn = jest.fn(); | ||
render(<CancelSubscriptionModal planName='Starter' onConfirm={jest.fn()} onCancel={cancelFn} />, { | ||
wrapper: mockAppRoot().build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Close' })); | ||
expect(cancelFn).toHaveBeenCalled(); | ||
}); |
36 changes: 36 additions & 0 deletions
36
apps/meteor/client/views/admin/subscription/components/CancelSubscriptionModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ExternalLink } from '@rocket.chat/ui-client'; | ||
import React from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
|
||
import GenericModal from '../../../../components/GenericModal'; | ||
import { DOWNGRADE_LINK } from '../utils/links'; | ||
|
||
type CancelSubscriptionModalProps = { | ||
planName: string; | ||
onConfirm(): void; | ||
onCancel(): void; | ||
}; | ||
|
||
export const CancelSubscriptionModal = ({ planName, onCancel, onConfirm }: CancelSubscriptionModalProps) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<GenericModal | ||
variant='danger' | ||
title={t('Cancel__planName__subscription', { planName })} | ||
icon={null} | ||
confirmText={t('Cancel_subscription')} | ||
cancelText={t('Dont_cancel')} | ||
onConfirm={onConfirm} | ||
onCancel={onCancel} | ||
> | ||
<Trans i18nKey='Cancel_subscription_message' t={t}> | ||
<strong>This workspace will downgrade to Community and lose free access to premium capabilities.</strong> | ||
<br /> | ||
<br /> | ||
While you can keep using Rocket.Chat, your team will lose access to unlimited mobile push notifications, read receipts, marketplace | ||
apps and <ExternalLink to={DOWNGRADE_LINK}>other capabilities</ExternalLink>. | ||
</Trans> | ||
</GenericModal> | ||
); | ||
}; |
72 changes: 72 additions & 0 deletions
72
apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
import { act, renderHook, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { useCancelSubscriptionModal } from './useCancelSubscriptionModal'; | ||
import createDeferredMockFn from '../../../../../tests/mocks/utils/createDeferredMockFn'; | ||
|
||
jest.mock('../../../../hooks/useLicense', () => ({ | ||
...jest.requireActual('../../../../hooks/useLicense'), | ||
useLicenseName: () => ({ data: 'Starter' }), | ||
})); | ||
|
||
it('should open modal when open method is called', () => { | ||
const { result } = renderHook(() => useCancelSubscriptionModal(), { | ||
wrapper: mockAppRoot() | ||
.withTranslations('en', 'core', { | ||
Cancel__planName__subscription: 'Cancel {{planName}} subscription', | ||
}) | ||
.build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument(); | ||
|
||
act(() => result.current.open()); | ||
|
||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should close modal cancel is clicked', async () => { | ||
const { result } = renderHook(() => useCancelSubscriptionModal(), { | ||
wrapper: mockAppRoot() | ||
.withTranslations('en', 'core', { | ||
Cancel__planName__subscription: 'Cancel {{planName}} subscription', | ||
}) | ||
.build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
act(() => result.current.open()); | ||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Dont_cancel' })); | ||
|
||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should call remove license endpoint when confirm is clicked', async () => { | ||
const { fn: removeLicenseEndpoint, resolve } = createDeferredMockFn<{ success: boolean }>(); | ||
|
||
const { result } = renderHook(() => useCancelSubscriptionModal(), { | ||
wrapper: mockAppRoot() | ||
.withEndpoint('POST', '/v1/cloud.removeLicense', removeLicenseEndpoint) | ||
.withTranslations('en', 'core', { | ||
Cancel__planName__subscription: 'Cancel {{planName}} subscription', | ||
}) | ||
.build(), | ||
legacyRoot: true, | ||
}); | ||
|
||
act(() => result.current.open()); | ||
expect(result.current.isLoading).toBeFalsy(); | ||
expect(screen.getByText('Cancel Starter subscription')).toBeInTheDocument(); | ||
|
||
await userEvent.click(screen.getByRole('button', { name: 'Cancel_subscription' })); | ||
expect(result.current.isLoading).toBeTruthy(); | ||
await act(() => resolve({ success: true })); | ||
await waitFor(() => expect(result.current.isLoading).toBeFalsy()); | ||
|
||
expect(removeLicenseEndpoint).toHaveBeenCalled(); | ||
expect(screen.queryByText('Cancel Starter subscription')).not.toBeInTheDocument(); | ||
}); |
28 changes: 28 additions & 0 deletions
28
apps/meteor/client/views/admin/subscription/hooks/useCancelSubscriptionModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useSetModal } from '@rocket.chat/ui-contexts'; | ||
import React, { useCallback } from 'react'; | ||
|
||
import { useRemoveLicense } from './useRemoveLicense'; | ||
import { useLicenseName } from '../../../../hooks/useLicense'; | ||
import { CancelSubscriptionModal } from '../components/CancelSubscriptionModal'; | ||
|
||
export const useCancelSubscriptionModal = () => { | ||
const { data: planName = '' } = useLicenseName(); | ||
const removeLicense = useRemoveLicense(); | ||
const setModal = useSetModal(); | ||
|
||
const open = useCallback(() => { | ||
const closeModal = () => setModal(null); | ||
|
||
const handleConfirm = () => { | ||
removeLicense.mutateAsync(); | ||
closeModal(); | ||
}; | ||
|
||
setModal(<CancelSubscriptionModal planName={planName} onConfirm={handleConfirm} onCancel={closeModal} />); | ||
}, [removeLicense, planName, setModal]); | ||
|
||
return { | ||
open, | ||
isLoading: removeLicense.isLoading, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function createDeferredPromise<R = void>() { | ||
let resolve!: (value: R | PromiseLike<R>) => void; | ||
let reject!: (reason?: unknown) => void; | ||
|
||
const promise = new Promise<R>((res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
|
||
return { promise, resolve, reject }; | ||
} | ||
|
||
function createDeferredMockFn<R = void>() { | ||
const deferred = createDeferredPromise<R>(); | ||
const fn = jest.fn(() => deferred.promise); | ||
return { ...deferred, fn }; | ||
} | ||
|
||
export default createDeferredMockFn; |
Oops, something went wrong.