import * as React from 'react';
import { render } from '@testing-library/react';
import { fireEvent } from '@testing-library/dom';
import { Button } from '@btri-ui/base';

const defaultProps = {
  onClick: jest.fn(),
};

// AAA模式: 编排（Arrange），执行（Act），断言（Assert）
describe('button test', () => {
  test('Button render', () => {
    // Arrange
    const wrapper = render(<Button>button</Button>);
    const el = wrapper.queryByText('button');

    // Assert
    expect(el).toBeTruthy();
  });

  test('button click', () => {
    // Arrange
    const wrapper = render(<Button {...defaultProps}>button</Button>);
    const el = wrapper.queryByText('button');

    // Act
    fireEvent.click(el);

    // Assert
    expect(defaultProps.onClick).toHaveBeenCalled();
  });
});
