boxons/components/shared/__tests__/Button-test.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-10-13 11:29:36 +00:00
import React from 'react';
import { fireEvent } from '@testing-library/react-native';
import { render } from '@/components/testUtils';
import Button from '@/components/shared/Button';
const renderComponent = ({ status, onPress } = {}) => {
const base = render(<Button label="Press me" status={status} onPress={onPress} />);
return base;
};
describe('[Component] Button', () => {
describe('Ready state', () => {
test('renders correctly', () => {
const button = renderComponent();
expect(button).toMatchSnapshot();
});
it('executes an action when pressing it', () => {
const action = jest.fn();
const button = renderComponent({ onPress: action });
fireEvent.press(button.getByText('Press me'));
expect(action).toHaveBeenCalledWith();
});
});
describe('Disabled state', () => {
test('renders correctly', () => {
const button = renderComponent({ status: 'disabled' });
expect(button).toMatchSnapshot();
});
test('does not do anything when pressing it', () => {
const action = jest.fn();
const button = renderComponent({ status: 'disabled', onPress: action });
fireEvent.press(button.getByText('Press me'));
expect(action).not.toHaveBeenCalled();
});
});
describe('Loading state', () => {
test('renders correctly', () => {
const button = renderComponent({ status: 'loading' });
expect(button).toMatchSnapshot();
});
test('does not do anything when pressing it', () => {
const action = jest.fn();
const button = renderComponent({ status: 'loading', onPress: action });
fireEvent.press(button.getByText('Press me'));
expect(action).not.toHaveBeenCalled();
});
});
});