import React from 'react'; import { render, screen, within } from '@testing-library/react'; import { expect } from 'chai'; import AppRegistry from 'hadron-app-registry'; import userEvent from '@testing-library/user-event'; import configureActions from '../actions'; import Field from './field'; describe('Field', function () { let container: HTMLElement; let testAppRegistry: AppRegistry; beforeEach(function () { testAppRegistry = new AppRegistry(); testAppRegistry.registerStore('Query.Store', { state: { filter: {}, valid: true, userTyping: false, }, filter: {}, listen: (( // eslint-disable-next-line @typescript-eslint/no-unused-vars func: () => { /* noop */ } ) => { return () => {}; }) as any, } as any); }); describe('basic field name', function () { beforeEach(function () { render( ); container = screen.getByTestId('schema-field'); }); it('renders the field name', function () { const fieldName = within(container).getByText('testFieldName'); expect(fieldName).to.be.visible; }); it('renders the various field types', function () { expect(within(container).getByText('String')).to.be.visible; expect(within(container).getByText('Double')).to.be.visible; expect(within(container).queryByText('Int32')).to.not.exist; }); }); describe('document field with nested fields', function () { beforeEach(function () { render( ); container = screen.getByTestId('schema-field'); }); it('renders the field name', function () { const fieldName = within(container).getByText('documentField'); expect(fieldName).to.be.visible; }); it('renders the field type', function () { expect(within(container).getByText('Document')).to.be.visible; }); it('does not render the nested fields', function () { expect(within(container).queryByText('nestedFieldName')).to.not.exist; }); it('renders the nested fields when the field is clicked', function () { const fieldNameButton = within(container).getByText('documentField'); userEvent.click(fieldNameButton, undefined, { skipPointerEventsCheck: true, }); expect(within(container).queryByText('nestedFieldName')).to.be.visible; }); }); describe('array field with various types', function () { beforeEach(function () { render( ); container = screen.getByTestId('schema-field'); }); it('renders the field name', function () { expect(within(container).getByText('arrayField')).to.be.visible; }); it('renders the field type', function () { expect(within(container).getByText('Array')).to.be.visible; }); it('renders the various types found in the array', function () { expect(within(container).getByText('String')).to.be.visible; expect(within(container).getByText('Double')).to.be.visible; expect(within(container).queryByText('Int32')).to.not.exist; }); }); });