Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,54 @@ describe('OutboundMessageUpsellModal', () => {
});

describe('hasModule is false', () => {
it('should render "Learn more" and "Contact sales" buttons', () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.getByRole('button', { name: 'Learn more' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Contact sales' })).toBeInTheDocument();
});
describe('user is not admin', () => {
it('should render only "Learn more" button', () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.getByRole('button', { name: 'Learn more' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Contact sales' })).not.toBeInTheDocument();
});

it('should call openExternalLink with docs link when "Learn more" is clicked', async () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
await userEvent.click(screen.getByRole('button', { name: 'Learn more' }));
expect(openExternalLink).toHaveBeenCalledWith('https://go.rocket.chat/i/omnichannel-docs');
});
it('should render the annotation', () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.getByText('Outbound_message_upsell_annotation')).toBeInTheDocument();
});

it('should call openExternalLink with sales link when "Contact sales" is clicked', async () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
await userEvent.click(screen.getByRole('button', { name: 'Contact sales' }));
expect(openExternalLink).toHaveBeenCalledWith('https://go.rocket.chat/i/contact-sales');
it('should call openExternalLink with docs link when "Learn more" is clicked', async () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
await userEvent.click(screen.getByRole('button', { name: 'Learn more' }));
expect(openExternalLink).toHaveBeenCalledWith('https://go.rocket.chat/i/omnichannel-docs');
});
});

it('should not render the annotation', () => {
render(<OutboundMessageUpsellModal onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.queryByText('Outbound_message_upsell_annotation')).not.toBeInTheDocument();
describe('user is admin', () => {
it('should render "Learn more" and "Contact sales" buttons', () => {
render(<OutboundMessageUpsellModal isAdmin onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.getByRole('button', { name: 'Learn more' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'Contact sales' })).toBeInTheDocument();
});

it('should render "Upgrade" button when isCommunity is true', () => {
render(<OutboundMessageUpsellModal isAdmin isCommunity onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.getByRole('button', { name: 'Upgrade' })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Contact sales' })).not.toBeInTheDocument();
});

it('should call openExternalLink with docs link when "Learn more" is clicked', async () => {
render(<OutboundMessageUpsellModal isAdmin onClose={onClose} />, { wrapper: appRoot.build() });
await userEvent.click(screen.getByRole('button', { name: 'Learn more' }));
expect(openExternalLink).toHaveBeenCalledWith('https://go.rocket.chat/i/omnichannel-docs');
});

it('should call openExternalLink with sales link when "Contact sales" is clicked', async () => {
render(<OutboundMessageUpsellModal isAdmin onClose={onClose} />, { wrapper: appRoot.build() });
await userEvent.click(screen.getByRole('button', { name: 'Contact sales' }));
expect(openExternalLink).toHaveBeenCalledWith('https://go.rocket.chat/i/contact-sales');
});

it('should not render the annotation', () => {
render(<OutboundMessageUpsellModal isAdmin onClose={onClose} />, { wrapper: appRoot.build() });
expect(screen.queryByText('Outbound_message_upsell_annotation')).not.toBeInTheDocument();
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ import GenericUpsellModal from '../../../../GenericUpsellModal';
type OutboundMessageUpsellModalProps = {
hasModule?: boolean;
isAdmin?: boolean;
isCommunity?: boolean;
onClose: () => void;
};

const OMNICHANNEL_DOCS_LINK = 'https://go.rocket.chat/i/omnichannel-docs';
const CONTACT_SALES_LINK = 'https://go.rocket.chat/i/contact-sales';

const OutboundMessageUpsellModal = ({ hasModule, isAdmin, onClose }: OutboundMessageUpsellModalProps) => {
const OutboundMessageUpsellModal = ({ isCommunity, hasModule, isAdmin, onClose }: OutboundMessageUpsellModalProps) => {
const { t } = useTranslation();

const openExternalLink = useExternalLink();

const props = useMemo(() => {
if (!hasModule) {
if (isAdmin && !hasModule) {
return {
cancelText: t('Learn_more'),
onCancel: () => openExternalLink(OMNICHANNEL_DOCS_LINK),
confirmText: t('Contact_sales'),
confirmText: isCommunity ? t('Upgrade') : t('Contact_sales'),
onConfirm: () => openExternalLink(CONTACT_SALES_LINK),
onClose,
};
Expand All @@ -36,7 +37,7 @@ const OutboundMessageUpsellModal = ({ hasModule, isAdmin, onClose }: OutboundMes
onCancel: () => openExternalLink(OMNICHANNEL_DOCS_LINK),
onClose,
};
}, [hasModule, isAdmin, onClose, openExternalLink, t]);
}, [hasModule, isAdmin, isCommunity, onClose, openExternalLink, t]);

return (
<GenericUpsellModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { useMemo } from 'react';

import OutboundMessageUpsellModal from './OutboundMessageUpsellModal';
import { useHasLicenseModule } from '../../../../../hooks/useHasLicenseModule';
import { useLicense } from '../../../../../hooks/useLicense';

export const useOutboundMessageUpsellModal = () => {
const setModal = useSetModal();
const isAdmin = useRole('admin');
const license = useLicense();
const hasModule = useHasLicenseModule('outbound-messaging') === true;

const close = useEffectEvent(() => setModal(null));
const open = useEffectEvent(() => setModal(<OutboundMessageUpsellModal isAdmin={isAdmin} hasModule={hasModule} onClose={close} />));
const open = useEffectEvent(() =>
setModal(<OutboundMessageUpsellModal isCommunity={!license.data?.license} isAdmin={isAdmin} hasModule={hasModule} onClose={close} />),
);

return useMemo(() => ({ open, close }), [open, close]);
};
Loading