Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [M3-8463] - Add unit tests for CheckoutBar component #10818

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10818-tests-1724394944251.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tests
---

Add unit test cases for CheckoutBar component ([#10818](https://github.com/linode/manager/pull/10818))
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { fireEvent } from '@testing-library/react';
import React from 'react';

import { renderWithTheme } from 'src/utilities/testHelpers';

import { CheckoutBar } from './CheckoutBar';

import type { CheckoutBarProps } from './CheckoutBar';

const defaultArgs: CheckoutBarProps = {
calculatedPrice: 30.0,
children: <div>Child items can go here!</div>,
heading: 'Checkout',
onDeploy: vi.fn(),
submitText: 'Submit',
};

describe('CheckoutBar', () => {
it('should render heading, children, and submit button', () => {
const { getByTestId, getByText } = renderWithTheme(
<CheckoutBar {...defaultArgs} />
);

expect(getByText('Checkout')).toBeVisible();
expect(getByTestId('Button')).toBeInTheDocument();
expect(getByTestId('Button')).toHaveTextContent('Submit');
expect(getByText('Child items can go here!')).toBeInTheDocument();
});

it('should render Agreement item if provided', () => {
const { getByText } = renderWithTheme(
<CheckoutBar
{...defaultArgs}
agreement={<div>Agreement item can go here!</div>}
/>
);

expect(getByText('Agreement item can go here!')).toBeInTheDocument();
});

it('should render Footer item if provided', () => {
const { getByText } = renderWithTheme(
<CheckoutBar
{...defaultArgs}
footer={<div>Footer element can go here!</div>}
/>
);

expect(getByText('Footer element can go here!')).toBeInTheDocument();
});

it('should disable submit button and show loading icon if isMakingRequest is true', () => {
const { getByTestId } = renderWithTheme(
<CheckoutBar {...defaultArgs} isMakingRequest={true} />
);

expect(getByTestId('Button')).toBeDisabled();
expect(getByTestId('loadingIcon')).toBeInTheDocument();
});

it("should disable submit button and show 'Submit' text if disabled prop is set", () => {
const { getByTestId } = renderWithTheme(
<CheckoutBar {...defaultArgs} disabled />
);

const button = getByTestId('Button');
expect(button).toBeDisabled();
expect(button).toHaveTextContent('Submit');
});

it('should call onDeploy when the submit button is not disabled', () => {
const { getByText } = renderWithTheme(<CheckoutBar {...defaultArgs} />);

const button = getByText('Submit');
expect(button).not.toBeDisabled();
fireEvent.click(button);
expect(defaultArgs.onDeploy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SxTypography,
} from './styles';

interface CheckoutBarProps {
export interface CheckoutBarProps {
pmakode-akamai marked this conversation as resolved.
Show resolved Hide resolved
/**
* JSX element to be displayed as an agreement section.
*/
Expand Down
Loading