123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379 |
- import {OrganizationFixture} from 'sentry-fixture/organization';
- import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
- import {renderGlobalModal, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {DataCategory} from 'sentry/types/core';
- import AddGiftEventsAction from 'admin/components/addGiftEventsAction';
- import {openAdminConfirmModal} from 'admin/components/adminConfirmationModal';
- import {MAX_ADMIN_CATEGORY_GIFTS} from 'getsentry/constants';
- describe('Gift', function () {
- const mockOrg = OrganizationFixture();
- const mockSub = SubscriptionFixture({organization: mockOrg});
- describe('Errors', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.ERRORS}
- {...deps}
- />
- ),
- });
- };
- function getErrorInput() {
- return screen.getByRole('textbox', {
- name: 'How many errors in multiples of 1,000s? (50 is 50,000 errors)',
- });
- }
- async function setNumEvents(numEvents: string) {
- await userEvent.clear(getErrorInput());
- await userEvent.type(getErrorInput(), numEvents);
- }
- it('has valid event volume', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.ERRORS] / 1000;
- triggerGiftModal();
- renderGlobalModal();
- const errorInput = getErrorInput();
- await setNumEvents('1');
- expect(errorInput).toHaveValue('1');
- expect(errorInput).toHaveAccessibleDescription('Total: 1,000');
- await setNumEvents('-50');
- expect(errorInput).toHaveValue('50');
- expect(errorInput).toHaveAccessibleDescription('Total: 50,000');
- await setNumEvents(`${maxValue + 5}`);
- expect(errorInput).toHaveValue('10000');
- expect(errorInput).toHaveAccessibleDescription('Total: 10,000,000');
- await setNumEvents('10,');
- expect(errorInput).toHaveValue('10');
- expect(errorInput).toHaveAccessibleDescription('Total: 10,000');
- await setNumEvents('5.');
- expect(errorInput).toHaveValue('5');
- expect(errorInput).toHaveAccessibleDescription('Total: 5,000');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- describe('Attachments', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.ATTACHMENTS}
- {...deps}
- />
- ),
- });
- };
- function getAttachmentsInput() {
- return screen.getByRole('textbox', {
- name: 'How many attachments in GB?',
- });
- }
- async function setNumAttachments(numAttachments: string) {
- await userEvent.clear(getAttachmentsInput());
- await userEvent.type(getAttachmentsInput(), numAttachments);
- }
- it('has valid event volume', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.ATTACHMENTS];
- triggerGiftModal();
- renderGlobalModal();
- const attachmentsInput = getAttachmentsInput();
- await setNumAttachments('1');
- expect(attachmentsInput).toHaveValue('1');
- expect(attachmentsInput).toHaveAccessibleDescription('Total: 1 GB');
- await setNumAttachments('-50');
- expect(attachmentsInput).toHaveValue('50');
- expect(attachmentsInput).toHaveAccessibleDescription('Total: 50 GB');
- await setNumAttachments(`${maxValue + 5}`);
- expect(attachmentsInput).toHaveValue('10000');
- expect(attachmentsInput).toHaveAccessibleDescription('Total: 10,000 GB');
- await setNumAttachments('10,');
- expect(attachmentsInput).toHaveValue('10');
- expect(attachmentsInput).toHaveAccessibleDescription('Total: 10 GB');
- await setNumAttachments('5.');
- expect(attachmentsInput).toHaveValue('5');
- expect(attachmentsInput).toHaveAccessibleDescription('Total: 5 GB');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- describe('Profile Duration', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.PROFILE_DURATION}
- {...deps}
- />
- ),
- });
- };
- function getProfileDurationInput() {
- return screen.getByRole('textbox', {
- name: 'How many profile hours?',
- });
- }
- async function setProfileDuration(duration: string) {
- await userEvent.clear(getProfileDurationInput());
- await userEvent.type(getProfileDurationInput(), duration);
- }
- it('has valid profile duration input', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.PROFILE_DURATION];
- triggerGiftModal();
- renderGlobalModal();
- const profileDurationInput = getProfileDurationInput();
- await setProfileDuration('1');
- expect(profileDurationInput).toHaveValue('1');
- expect(profileDurationInput).toHaveAccessibleDescription('Total: 1 hour');
- await setProfileDuration('-50');
- expect(profileDurationInput).toHaveValue('50');
- expect(profileDurationInput).toHaveAccessibleDescription('Total: 50 hours');
- await setProfileDuration(`${maxValue + 5}`);
- expect(profileDurationInput).toHaveValue('10000');
- expect(profileDurationInput).toHaveAccessibleDescription('Total: 10,000 hours');
- await setProfileDuration('10,');
- expect(profileDurationInput).toHaveValue('10');
- expect(profileDurationInput).toHaveAccessibleDescription('Total: 10 hours');
- await setProfileDuration('5.');
- expect(profileDurationInput).toHaveValue('5');
- expect(profileDurationInput).toHaveAccessibleDescription('Total: 5 hours');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- describe('Replays', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.REPLAYS}
- {...deps}
- />
- ),
- });
- };
- function getReplayInput() {
- return screen.getByRole('textbox', {
- name: 'How many replays? (50 is 50 replays)',
- });
- }
- async function setNumReplays(numReplays: string) {
- await userEvent.clear(getReplayInput());
- await userEvent.type(getReplayInput(), numReplays);
- }
- it('has valid replay input', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.REPLAYS];
- triggerGiftModal();
- renderGlobalModal();
- const replayInput = getReplayInput();
- await setNumReplays('1');
- expect(replayInput).toHaveValue('1');
- expect(replayInput).toHaveAccessibleDescription('Total: 1');
- await setNumReplays('-50');
- expect(replayInput).toHaveValue('50');
- expect(replayInput).toHaveAccessibleDescription('Total: 50');
- await setNumReplays(`${maxValue + 5}`);
- expect(replayInput).toHaveValue('1000000');
- expect(replayInput).toHaveAccessibleDescription('Total: 1,000,000');
- await setNumReplays('10,');
- expect(replayInput).toHaveValue('10');
- expect(replayInput).toHaveAccessibleDescription('Total: 10');
- await setNumReplays('5.');
- expect(replayInput).toHaveValue('5');
- expect(replayInput).toHaveAccessibleDescription('Total: 5');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- describe('Monitors', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.MONITOR_SEATS}
- {...deps}
- />
- ),
- });
- };
- function getMonitorInput() {
- return screen.getByRole('textbox', {
- name: 'How many cron monitors? (50 is 50 cron monitors)',
- });
- }
- async function setNumMonitors(numMonitors: string) {
- await userEvent.clear(getMonitorInput());
- await userEvent.type(getMonitorInput(), numMonitors);
- }
- it('has valid monitor input', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.MONITOR_SEATS];
- triggerGiftModal();
- renderGlobalModal();
- const monitorInput = getMonitorInput();
- await setNumMonitors('1');
- expect(monitorInput).toHaveValue('1');
- expect(monitorInput).toHaveAccessibleDescription('Total: 1');
- await setNumMonitors('-50');
- expect(monitorInput).toHaveValue('50');
- expect(monitorInput).toHaveAccessibleDescription('Total: 50');
- await setNumMonitors(`${maxValue + 5}`);
- expect(monitorInput).toHaveValue('10000');
- expect(monitorInput).toHaveAccessibleDescription('Total: 10,000');
- await setNumMonitors('10,');
- expect(monitorInput).toHaveValue('10');
- expect(monitorInput).toHaveAccessibleDescription('Total: 10');
- await setNumMonitors('5.');
- expect(monitorInput).toHaveValue('5');
- expect(monitorInput).toHaveAccessibleDescription('Total: 5');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- describe('Uptime Monitors', function () {
- const triggerGiftModal = () => {
- openAdminConfirmModal({
- renderModalSpecificContent: deps => (
- <AddGiftEventsAction
- subscription={mockSub}
- dataCategory={DataCategory.UPTIME}
- {...deps}
- />
- ),
- });
- };
- function getMonitorInput() {
- return screen.getByRole('textbox', {
- name: 'How many uptime monitors? (50 is 50 uptime monitors)',
- });
- }
- async function setNumMonitors(numMonitors: string) {
- await userEvent.clear(getMonitorInput());
- await userEvent.type(getMonitorInput(), numMonitors);
- }
- it('has valid monitor input', async function () {
- const maxValue = MAX_ADMIN_CATEGORY_GIFTS[DataCategory.UPTIME];
- triggerGiftModal();
- renderGlobalModal();
- const monitorInput = getMonitorInput();
- await setNumMonitors('1');
- expect(monitorInput).toHaveValue('1');
- expect(monitorInput).toHaveAccessibleDescription('Total: 1');
- await setNumMonitors('-50');
- expect(monitorInput).toHaveValue('50');
- expect(monitorInput).toHaveAccessibleDescription('Total: 50');
- await setNumMonitors(`${maxValue + 5}`);
- expect(monitorInput).toHaveValue('10000');
- expect(monitorInput).toHaveAccessibleDescription('Total: 10,000');
- await setNumMonitors('10,');
- expect(monitorInput).toHaveValue('10');
- expect(monitorInput).toHaveAccessibleDescription('Total: 10');
- await setNumMonitors('5.');
- expect(monitorInput).toHaveValue('5');
- expect(monitorInput).toHaveAccessibleDescription('Total: 5');
- });
- it('disables confirm button when no number is entered', function () {
- triggerGiftModal();
- renderGlobalModal();
- expect(screen.getByTestId('confirm-button')).toBeDisabled();
- });
- });
- });
|