LogsConfig.test.tsx 1.0 KB

1234567891011121314151617181920212223
  1. import { render, screen, fireEvent } from '@testing-library/react';
  2. import React from 'react';
  3. import { LogsConfig } from './LogsConfig';
  4. import { createDefaultConfigOptions } from './mocks';
  5. describe('ElasticDetails', () => {
  6. it('should pass correct data to onChange', () => {
  7. const onChangeMock = jest.fn();
  8. const expectedMessageField = '@message';
  9. const expectedLevelField = '@level';
  10. render(<LogsConfig onChange={onChangeMock} value={createDefaultConfigOptions().jsonData} />);
  11. const messageField = screen.getByLabelText('Message field name');
  12. const levelField = screen.getByLabelText('Level field name');
  13. fireEvent.change(messageField, { target: { value: expectedMessageField } });
  14. expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ logMessageField: expectedMessageField }));
  15. fireEvent.change(levelField, { target: { value: expectedLevelField } });
  16. expect(onChangeMock).toHaveBeenLastCalledWith(expect.objectContaining({ logLevelField: expectedLevelField }));
  17. });
  18. });