Untitled

 avatar
unknown
plain_text
3 years ago
2.7 kB
5
Indexable
import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { ManageSubaccountPage } from './ManageSubaccountPage';

import { ROUTES } from 'containers/App/routes';
import { renderWithRouter } from 'utils/testHelpers';

const mockedOpenPurchaseDialog = jest.fn();
const mockedOpenCancelPlanDialog = jest.fn();
const mockedHandlePlanSelection = jest.fn();

jest.mock('containers/PurchaseDialog', () => ({
  usePurchaseDialog: () => ({
    openPurchaseDialog: mockedOpenPurchaseDialog,
  }),
}));

jest.mock('containers/ManageBillingPage/useManageBilling', () => ({
  useManageBilling: () => ({
    handlePlanSelection: mockedHandlePlanSelection,
    openCancelPlanDialog: mockedOpenCancelPlanDialog,
  }),
}));

describe('ManageSubaccountPage', () => {
  test('render component', () => {
    renderWithRouter(<ManageSubaccountPage />);

    expect(screen.getByText('Manage Subaccounts')).toHaveAttribute(
      'href',
      ROUTES.subaccounts.path,
    );
    expect(
      screen.getByText('Stop managing this subaccount'),
    ).toBeInTheDocument();
    expect(screen.getByText('Manage Plan')).toBeInTheDocument();
    expect(screen.getByText(/Regular Bill Amount/)).toBeInTheDocument();
    expect(screen.getByText('$700')).toBeInTheDocument();
    expect(
      screen.getByRole('heading', { level: 2, name: 'Plan Information' }),
    ).toBeInTheDocument();
    expect(
      screen.getByRole('button', { name: 'Downgrade' }),
    ).toBeInTheDocument();
    expect(screen.getByRole('navigation')).toBeInTheDocument();
  });

  test('open dialog with plan updates', async () => {
    renderWithRouter(<ManageSubaccountPage />);

    await userEvent.click(
      screen.getByRole('button', { name: 'Purchase Plan Extras' }),
    );

    expect(mockedOpenPurchaseDialog).toHaveBeenCalled();
  });

  test('downgrade plan action', async () => {
    renderWithRouter(<ManageSubaccountPage />);

    await userEvent.click(screen.getByRole('button', { name: 'Downgrade' }));

    expect(mockedHandlePlanSelection).toHaveBeenCalledWith(
      'buttonUrl',
      'POST',
      true,
      false,
    );
  });

  test('cancel app action', async () => {
    renderWithRouter(<ManageSubaccountPage />);

    await userEvent.click(screen.getAllByRole('button')[1]);

    const cancelButton = screen.getByRole('option', {
      name: 'Cancel Platform plan',
    });

    await waitFor(() => userEvent.click(cancelButton));

    expect(mockedOpenCancelPlanDialog).toHaveBeenCalledWith(
      'platform',
      'cancelActionUrl',
      undefined, // requireManualBillingOperation
    );
  });
});
Editor is loading...