2023-10-20 17:48:27 +05:30
|
|
|
import { billingSuccessResponse } from 'mocks-server/__mockdata__/billing';
|
|
|
|
|
import {
|
2024-12-20 14:00:02 +05:30
|
|
|
licensesSuccessResponse,
|
2023-10-20 17:48:27 +05:30
|
|
|
notOfTrailResponse,
|
|
|
|
|
trialConvertedToSubscriptionResponse,
|
|
|
|
|
} from 'mocks-server/__mockdata__/licenses';
|
2024-12-20 14:00:02 +05:30
|
|
|
import { act, render, screen, waitFor } from 'tests/test-utils';
|
2023-10-20 17:48:27 +05:30
|
|
|
import { getFormattedDate } from 'utils/timeUtils';
|
|
|
|
|
|
|
|
|
|
import BillingContainer from './BillingContainer';
|
|
|
|
|
|
2024-03-13 14:30:49 +05:30
|
|
|
jest.mock('uplot', () => {
|
|
|
|
|
const paths = {
|
|
|
|
|
spline: jest.fn(),
|
|
|
|
|
bars: jest.fn(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const uplotMock = jest.fn(() => ({
|
|
|
|
|
paths,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
paths,
|
|
|
|
|
default: uplotMock,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.ResizeObserver =
|
|
|
|
|
window.ResizeObserver ||
|
|
|
|
|
jest.fn().mockImplementation(() => ({
|
|
|
|
|
disconnect: jest.fn(),
|
|
|
|
|
observe: jest.fn(),
|
|
|
|
|
unobserve: jest.fn(),
|
|
|
|
|
}));
|
|
|
|
|
|
2023-10-20 17:48:27 +05:30
|
|
|
describe('BillingContainer', () => {
|
|
|
|
|
test('Component should render', async () => {
|
2024-12-20 14:00:02 +05:30
|
|
|
render(<BillingContainer />);
|
2024-03-13 14:30:49 +05:30
|
|
|
|
2023-10-20 17:48:27 +05:30
|
|
|
const dataInjection = screen.getByRole('columnheader', {
|
|
|
|
|
name: /data ingested/i,
|
|
|
|
|
});
|
|
|
|
|
expect(dataInjection).toBeInTheDocument();
|
|
|
|
|
const pricePerUnit = screen.getByRole('columnheader', {
|
|
|
|
|
name: /price per unit/i,
|
|
|
|
|
});
|
|
|
|
|
expect(pricePerUnit).toBeInTheDocument();
|
|
|
|
|
const cost = screen.getByRole('columnheader', {
|
|
|
|
|
name: /cost \(billing period to date\)/i,
|
|
|
|
|
});
|
|
|
|
|
expect(cost).toBeInTheDocument();
|
|
|
|
|
|
2024-12-20 14:00:02 +05:30
|
|
|
const dayRemainingInBillingPeriod = await screen.findByText(
|
2025-01-29 13:46:26 +05:30
|
|
|
/Please upgrade plan now to retain your data./i,
|
2024-12-20 14:00:02 +05:30
|
|
|
);
|
|
|
|
|
expect(dayRemainingInBillingPeriod).toBeInTheDocument();
|
|
|
|
|
|
2025-01-29 13:46:26 +05:30
|
|
|
const upgradePlanButton = screen.getByTestId('upgrade-plan-button');
|
|
|
|
|
expect(upgradePlanButton).toBeInTheDocument();
|
2023-10-20 17:48:27 +05:30
|
|
|
|
2024-12-20 14:00:02 +05:30
|
|
|
const dollar = screen.getByText(/\$1,278.3/i);
|
|
|
|
|
await waitFor(() => expect(dollar).toBeInTheDocument());
|
2023-10-20 17:48:27 +05:30
|
|
|
|
2024-03-27 10:23:57 +05:30
|
|
|
const currentBill = screen.getByText('billing');
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(currentBill).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('OnTrail', async () => {
|
|
|
|
|
act(() => {
|
2024-12-20 14:00:02 +05:30
|
|
|
render(<BillingContainer />, undefined, undefined, {
|
2025-03-17 19:27:45 +05:30
|
|
|
trialInfo: licensesSuccessResponse.data,
|
2024-12-20 14:00:02 +05:30
|
|
|
});
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const freeTrailText = await screen.findByText('Free Trial');
|
|
|
|
|
expect(freeTrailText).toBeInTheDocument();
|
|
|
|
|
|
2024-03-27 10:23:57 +05:30
|
|
|
const currentBill = screen.getByText('billing');
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(currentBill).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const dollar0 = await screen.findByText(/\$0/i);
|
|
|
|
|
expect(dollar0).toBeInTheDocument();
|
|
|
|
|
const onTrail = await screen.findByText(
|
|
|
|
|
/You are in free trial period. Your free trial will end on 20 Oct 2023/i,
|
|
|
|
|
);
|
|
|
|
|
expect(onTrail).toBeInTheDocument();
|
|
|
|
|
|
2024-03-27 10:23:57 +05:30
|
|
|
const numberOfDayRemaining = await screen.findByText(/1 days_remaining/i);
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(numberOfDayRemaining).toBeInTheDocument();
|
|
|
|
|
const upgradeButton = await screen.findAllByRole('button', {
|
2024-03-27 10:23:57 +05:30
|
|
|
name: /upgrade_plan/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
expect(upgradeButton[1]).toBeInTheDocument();
|
|
|
|
|
expect(upgradeButton.length).toBe(2);
|
2024-03-27 10:23:57 +05:30
|
|
|
const checkPaidPlan = await screen.findByText(/checkout_plans/i);
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(checkPaidPlan).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const link = screen.getByRole('link', { name: /here/i });
|
|
|
|
|
expect(link).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('OnTrail but trialConvertedToSubscription', async () => {
|
|
|
|
|
act(() => {
|
2024-12-20 14:00:02 +05:30
|
|
|
render(<BillingContainer />, undefined, undefined, {
|
2025-03-17 19:27:45 +05:30
|
|
|
trialInfo: trialConvertedToSubscriptionResponse.data,
|
2024-12-20 14:00:02 +05:30
|
|
|
});
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
|
2024-03-27 10:23:57 +05:30
|
|
|
const currentBill = screen.getByText('billing');
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(currentBill).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const dollar0 = await screen.findByText(/\$0/i);
|
|
|
|
|
expect(dollar0).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const onTrail = await screen.findByText(
|
|
|
|
|
/You are in free trial period. Your free trial will end on 20 Oct 2023/i,
|
|
|
|
|
);
|
|
|
|
|
expect(onTrail).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const receivedCardDetails = await screen.findByText(
|
2024-03-27 10:23:57 +05:30
|
|
|
/card_details_recieved_and_billing_info/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
);
|
|
|
|
|
expect(receivedCardDetails).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const manageBillingButton = await screen.findByRole('button', {
|
2024-03-27 10:23:57 +05:30
|
|
|
name: /manage_billing/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
expect(manageBillingButton).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const dayRemainingInBillingPeriod = await screen.findByText(
|
2024-03-27 10:23:57 +05:30
|
|
|
/1 days_remaining/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
);
|
|
|
|
|
expect(dayRemainingInBillingPeriod).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('Not on ontrail', async () => {
|
2024-12-20 14:00:02 +05:30
|
|
|
const { findByText } = render(<BillingContainer />, undefined, undefined, {
|
2025-03-17 19:27:45 +05:30
|
|
|
trialInfo: notOfTrailResponse.data,
|
2024-12-20 14:00:02 +05:30
|
|
|
});
|
2023-10-20 17:48:27 +05:30
|
|
|
|
|
|
|
|
const billingPeriodText = `Your current billing period is from ${getFormattedDate(
|
|
|
|
|
billingSuccessResponse.data.billingPeriodStart,
|
|
|
|
|
)} to ${getFormattedDate(billingSuccessResponse.data.billingPeriodEnd)}`;
|
|
|
|
|
|
2024-03-13 14:30:49 +05:30
|
|
|
const billingPeriod = await findByText(billingPeriodText);
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(billingPeriod).toBeInTheDocument();
|
|
|
|
|
|
2024-03-27 10:23:57 +05:30
|
|
|
const currentBill = screen.getByText('billing');
|
2023-10-20 17:48:27 +05:30
|
|
|
expect(currentBill).toBeInTheDocument();
|
|
|
|
|
|
2024-03-13 14:30:49 +05:30
|
|
|
const dollar0 = await screen.findByText(/\$1,278.3/i);
|
|
|
|
|
expect(dollar0).toBeInTheDocument();
|
2023-10-20 17:48:27 +05:30
|
|
|
|
|
|
|
|
const metricsRow = await screen.findByRole('row', {
|
2024-03-13 14:30:49 +05:30
|
|
|
name: /metrics 4012 Million 0.1 \$ 401.2/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
expect(metricsRow).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
const logRow = await screen.findByRole('row', {
|
2024-03-13 14:30:49 +05:30
|
|
|
name: /Logs 497 GB 0.4 \$ 198.8/i,
|
2023-10-20 17:48:27 +05:30
|
|
|
});
|
|
|
|
|
expect(logRow).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
});
|