123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import {MemberFixture} from 'sentry-fixture/member';
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {resetMockDate, setMockDate} from 'sentry-test/utils';
- import {PlanFixture} from 'getsentry/__fixtures__/plan';
- import PartnerPlanEndingModal from 'getsentry/components/partnerPlanEndingModal';
- import SubscriptionStore from 'getsentry/stores/subscriptionStore';
- import {PlanName} from 'getsentry/types';
- describe('PartnerPlanEndingModal', function () {
- beforeEach(() => {
- setMockDate(new Date('2024-08-01'));
- MockApiClient.clearMockResponses();
- MockApiClient.addMockResponse({
- url: `/organizations/org-slug/members/`,
- method: 'GET',
- body: [
- MemberFixture({
- email: 'admin@example.com',
- }),
- ],
- });
- });
- afterEach(() => {
- resetMockDate();
- });
- it('shows request upgrade when user does not have billing permissions', async function () {
- const org = OrganizationFixture({access: []});
- const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
- SubscriptionStore.set(org.slug, sub);
- const mockCall = MockApiClient.addMockResponse({
- url: `/organizations/org-slug/partner-migration-request/?referrer=partner_plan_ending_modal`,
- method: 'POST',
- });
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
- expect(screen.getByLabelText('Request to Upgrade')).toBeInTheDocument();
- await userEvent.click(screen.getByLabelText('Request to Upgrade'));
- expect(mockCall).toHaveBeenCalled();
- });
- it('shows an upgrade now button with billing permission', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
- expect(screen.getByLabelText('Upgrade Now')).toBeInTheDocument();
- });
- it('displays 7 days left', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-08'});
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.getByTestId('partner-plan-ending-modal')).toBeInTheDocument();
- expect(screen.getByText('7 days left')).toBeInTheDocument();
- expect(screen.getByText('New Plan on Aug 9, 2024')).toBeInTheDocument();
- });
- it('displays 1 day left', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-08-02'});
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.getByText('1 day left')).toBeInTheDocument();
- expect(screen.getByText('New Plan on Aug 3, 2024')).toBeInTheDocument();
- });
- it('displays team related content', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({
- organization: org,
- contractPeriodEnd: '2024-08-30',
- planDetails: PlanFixture({
- name: PlanName.TEAM_SPONSORED,
- }),
- });
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.queryAllByText('Business')).toHaveLength(0);
- expect(screen.getByText('Team')).toBeInTheDocument();
- });
- it('displays business related content', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({
- organization: org,
- contractPeriodEnd: '2024-08-30',
- planDetails: PlanFixture({
- name: PlanName.BUSINESS_SPONSORED,
- }),
- });
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.queryAllByText('Team')).toHaveLength(0);
- expect(screen.getByText('Business')).toBeInTheDocument();
- });
- it('does not display if plan ended', function () {
- const org = OrganizationFixture({access: ['org:billing']});
- const sub = SubscriptionFixture({organization: org, contractPeriodEnd: '2024-07-31'});
- SubscriptionStore.set(org.slug, sub);
- render(
- <PartnerPlanEndingModal
- closeModal={jest.fn()}
- organization={org}
- subscription={sub}
- />
- );
- expect(screen.queryByTestId('partner-plan-ending-modal')).not.toBeInTheDocument();
- });
- });
|