123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- import moment from 'moment-timezone';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
- import {
- renderGlobalModal,
- screen,
- userEvent,
- within,
- } from 'sentry-test/reactTestingLibrary';
- import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
- import TrialSubscriptionAction from 'admin/components/trialSubscriptionAction';
- import {PlanTier} from 'getsentry/types';
- describe('TrialSubscriptionAction', function () {
- const organization = OrganizationFixture();
- const onConfirm = jest.fn();
- const now = moment();
- const formattedNow = now.format('MMMM Do YYYY');
- const trialEnd = now.add(14, 'days');
- const formattedTrialEnd = trialEnd.format('MMMM Do YYYY');
- async function confirmTrialDays(days: any) {
- const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
- await userEvent.clear(daysInput);
- await userEvent.type(daysInput, days);
- await userEvent.click(screen.getByTestId('confirm-button'));
- }
- it('can pass trialDays onConfirm', async function () {
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({organization})}
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await confirmTrialDays('30');
- expect(onConfirm).toHaveBeenCalledWith({trialDays: 30});
- });
- it('can pass trialDays and enterprise plan onConfirm', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'mm2_f',
- isFree: true,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- expect(
- screen.getByText('Spike protection will need to be manually disabled.')
- ).toBeInTheDocument();
- await confirmTrialDays('45');
- expect(onConfirm).toHaveBeenCalledWith({
- trialDays: 45,
- startEnterpriseTrial: true,
- trialTier: PlanTier.AM3,
- });
- });
- it('can pass trialDays and extend enterprise plan onConfirm', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'mm2_a_500k',
- isFree: false,
- isEnterpriseTrial: true,
- })}
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await confirmTrialDays('21');
- expect(onConfirm).toHaveBeenCalledWith({trialDays: 21});
- });
- it('can pass trialDays and trialPlanOverride onConfirm', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'am3_f',
- isFree: true,
- })}
- startEnterpriseTrial
- canUseTrialOverride
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
- const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
- await userEvent.click(trialTierInputs[0]!);
- await userEvent.click(screen.getByText('am3 with Dynamic Sampling'));
- await confirmTrialDays('14');
- expect(onConfirm).toHaveBeenCalledWith({
- trialDays: 14,
- startEnterpriseTrial: true,
- trialTier: PlanTier.AM3,
- trialPlanOverride: 'am3_t_ent_ds',
- });
- });
- it('cannot use trialPlanOverride if disabled', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'am3_f',
- isFree: true,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
- const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
- await userEvent.click(trialTierInputs[0]!);
- expect(screen.queryByText('am3 with Dynamic Sampling')).not.toBeInTheDocument();
- });
- it('displays correct trial end date when starting trial', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'mm2_f',
- isFree: true,
- })}
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
- await userEvent.clear(daysInput);
- await userEvent.type(daysInput, '0');
- expect(daysInput).toHaveAccessibleDescription(
- `Their trial will end on ${formattedNow}`
- );
- });
- it('displays correct trial end date when starting enterprise trial', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'mm2_f',
- isFree: true,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
- await userEvent.clear(daysInput);
- await userEvent.type(daysInput, '0');
- expect(daysInput).toHaveAccessibleDescription(
- `Their trial will end on ${formattedNow}`
- );
- });
- it('displays correct trial end date when extending trial', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- trialEnd: trialEnd.toString(),
- plan: 'am1_t',
- isFree: true,
- })}
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
- await userEvent.clear(daysInput);
- await userEvent.type(daysInput, '0');
- expect(daysInput).toHaveAccessibleDescription(
- `Their trial will end on ${formattedTrialEnd}`
- );
- });
- it('displays correct trial end date when converting from trial to enterprise trial', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- trialEnd: trialEnd.toString(),
- plan: 'am1_t',
- isFree: true,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- const daysInput = screen.getByRole('spinbutton', {name: 'Number of Days'});
- await userEvent.clear(daysInput);
- await userEvent.type(daysInput, '0');
- expect(daysInput).toHaveAccessibleDescription(
- `Their trial will end on ${formattedNow}`
- );
- });
- it('displays am3 trial tier option when free plan', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'am2_f',
- isFree: true,
- planTier: PlanTier.AM2,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
- const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
- await userEvent.click(trialTierInputs[1]!);
- expect(screen.getByText('am3')).toBeInTheDocument();
- });
- it('displays am3 trial tier option when am3 plan', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'am3_team',
- isFree: false,
- planTier: PlanTier.AM3,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
- const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
- await userEvent.click(trialTierInputs[1]!);
- expect(screen.getByText('am3')).toBeInTheDocument();
- });
- it('displays am3 trial tier option when am2 plan', async function () {
- jest.mock('sentry/components/core/alert');
- openAdminConfirmModal({
- onConfirm,
- renderModalSpecificContent: deps => (
- <TrialSubscriptionAction
- subscription={SubscriptionFixture({
- organization,
- plan: 'am2_team',
- isFree: false,
- planTier: PlanTier.AM2,
- })}
- startEnterpriseTrial
- {...deps}
- />
- ),
- });
- renderGlobalModal();
- await userEvent.click(screen.getByTestId('trial-plan-tier-choices'));
- const trialTierInputs = within(screen.getByRole('dialog')).getAllByRole('textbox');
- await userEvent.click(trialTierInputs[1]!);
- expect(screen.getByText('am3')).toBeInTheDocument();
- });
- });
|