diff --git a/packages/components/src/internal/components/domainproperties/LookupFieldOptions.spec.tsx b/packages/components/src/internal/components/domainproperties/LookupFieldOptions.spec.tsx deleted file mode 100644 index 8d5d53b9e7..0000000000 --- a/packages/components/src/internal/components/domainproperties/LookupFieldOptions.spec.tsx +++ /dev/null @@ -1,517 +0,0 @@ -import React from 'react'; -import { mount, ReactWrapper } from 'enzyme'; - -import { MockLookupProvider } from '../../../test/MockLookupProvider'; - -import { createFormInputId, createFormInputName } from './utils'; -import { - DOMAIN_FIELD_FULLY_LOCKED, - DOMAIN_FIELD_LOOKUP_CONTAINER, - DOMAIN_FIELD_LOOKUP_QUERY, - DOMAIN_FIELD_LOOKUP_SCHEMA, - DOMAIN_FIELD_NOT_LOCKED, - DOMAIN_FIELD_PARTIALLY_LOCKED, - INT_RANGE_URI, -} from './constants'; -import { DomainField } from './models'; -import { - FolderSelect, - FolderSelectProps, - IFolderSelectImplState, - ISchemaSelectImplState, - ITargetTableSelectImplState, - SchemaSelect, - SchemaSelectProps, - TargetTableSelect, - TargetTableSelectProps, -} from './Lookup/Fields'; -import { LookupFieldOptions } from './LookupFieldOptions'; -import { PropDescType } from './PropDescType'; - -describe('LookupFieldOptions', () => { - const waitForLoad = jest.fn(field => Promise.resolve(!field.state().loading)); - - // Helper methods to select fields - const folderFieldSelector = ( - field: ReactWrapper, - domainIndex: number, - index: number - ): ReactWrapper => { - return field - .find({ - id: createFormInputId(DOMAIN_FIELD_LOOKUP_CONTAINER, domainIndex, index), - name: createFormInputName(DOMAIN_FIELD_LOOKUP_CONTAINER), - }) - .not({ bsClass: 'form-control' }) - .not({ className: 'form-control' }); - }; - - const schemaFieldSelector = ( - field: ReactWrapper, - domainIndex: number, - index: number - ): ReactWrapper => { - return field - .find({ - id: createFormInputId(DOMAIN_FIELD_LOOKUP_SCHEMA, domainIndex, index), - name: createFormInputName(DOMAIN_FIELD_LOOKUP_SCHEMA), - }) - .not({ bsClass: 'form-control' }) - .not({ className: 'form-control' }); - }; - - const queryFieldSelector = ( - field: ReactWrapper, - domainIndex: number, - index: number - ): ReactWrapper => { - return field - .find({ - id: createFormInputId(DOMAIN_FIELD_LOOKUP_QUERY, domainIndex, index), - name: createFormInputName(DOMAIN_FIELD_LOOKUP_QUERY), - }) - .not({ bsClass: 'form-control' }) - .not({ className: 'form-control' }); - }; - - // Tests - test('Lookup field options', () => { - const _container = '/StudyVerifyProject/My Study'; - const _schema = 'exp'; - const _query = 'Data'; - const _index = 1; - const _domainIndex = 1; - const _label = 'Lookup Field Options'; - const _container0 = 'StudyVerifyProject'; - const _container1 = 'My Study'; - const _schema0 = 'exp'; - const _schema2 = 'study'; - const _queries1 = 'DataInputs'; - - const field = DomainField.create({ - name: 'key', - rangeURI: INT_RANGE_URI, - propertyId: 1, - propertyURI: 'test', - }); - - const lookupField = mount( - - - - ); - - // Verify section label - const sectionLabel = lookupField.find({ className: 'domain-field-section-heading' }); - expect(sectionLabel.length).toEqual(1); - expect(sectionLabel.text()).toEqual(_label); - - // Folder - const folderField = folderFieldSelector(lookupField, _domainIndex, _index); - - expect(folderField.length).toEqual(1); - - return waitForLoad(folderField).then(() => { - expect(folderField.props().value).toEqual(_container); - expect(folderField.state().containers.size).toEqual(2); - expect(folderField.state().containers.get(0).name).toEqual(_container0); - expect(folderField.state().containers.get(1).name).toEqual(_container1); - - // Schema - const schemaField = schemaFieldSelector(lookupField, _domainIndex, _index); - - expect(schemaField.length).toEqual(1); - - return waitForLoad(schemaField).then(() => { - expect(schemaField.props().value).toEqual(_schema); - expect(schemaField.state().schemas.length).toEqual(5); - expect(schemaField.state().schemas[0].schemaName).toEqual(_schema0); - expect(schemaField.state().schemas[4].schemaName).toEqual(_schema2); - - // Query - const queryField = queryFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(queryField).then(() => { - expect(queryField.props().value).toEqual(_query); - expect(queryField.state().queries.length).toEqual(3); - expect(queryField.state().queries[1].name).toEqual(_queries1); - - expect(lookupField).toMatchSnapshot(); - lookupField.unmount(); - }); - }); - }); - }); - - test('Selected container changes schemas', () => { - const _container1 = '/StudyVerifyProject/My Study'; - const _container2 = '/StudyVerifyProject'; - const _index = 1; - const _domainIndex = 1; - const _schema = 'exp'; - const _query = 'Data'; - const _label = 'Lookup Field Options'; - const _newSchema = 'lists'; - - const field = DomainField.create({ - name: 'key', - rangeURI: INT_RANGE_URI, - propertyId: 1, - propertyURI: 'test', - }); - - const lookupField = mount( - - - - ); - - // Get container field and wait for it to populate - const container = folderFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(container).then(() => { - expect(container.props().value).toEqual(_container1); - - // Get schema field and wait for load - const schema = schemaFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(schema).then(() => { - expect(schema.props().value).toEqual(_schema); - expect(schema.state().schemas.length).toEqual(5); - - lookupField.setProps({ - children: ( - - ), - }); - - return waitForLoad(container).then(() => { - // Wait for schema to load and verify values updated - return waitForLoad(schema).then(() => { - expect(schema.state().schemas.length).toEqual(1); - expect(schema.state().schemas[0].schemaName).toEqual(_newSchema); - - expect(lookupField).toMatchSnapshot(); - lookupField.unmount(); - }); - }); - }); - }); - }); - - test('Selected schema changes queries', () => { - const _container = '/StudyVerifyProject/My Study'; - const _schema1 = 'exp'; - const _schema2 = 'study'; - const _query1 = 'Data'; - const _query2 = 'Treatment'; - const _label = 'Lookup Field Options'; - const _index = 1; - const _domainIndex = 1; - - const field = DomainField.create({ - name: 'key', - rangeURI: INT_RANGE_URI, - propertyId: 1, - propertyURI: 'test', - }); - - const lookupField = mount( - - - - ); - - // Folder - const folderField = folderFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(folderField).then(() => { - expect(folderField.props().value).toEqual(_container); - - // Schema - const schemaField = schemaFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(schemaField).then(() => { - expect(schemaField.props().value).toEqual(_schema1); - - // Query - let queryField = queryFieldSelector(lookupField, _domainIndex, _index); - return waitForLoad(queryField).then(() => { - expect(queryField.state().queries.length).toEqual(4); - - lookupField.setProps({ - children: ( - - ), - }); - - queryField = queryFieldSelector(lookupField, _domainIndex, _index); - return waitForLoad(schemaField).then(() => { - return waitForLoad(queryField).then(() => { - // Verify query field - expect(queryField.state().queries.length).toEqual(1); - expect(queryField.state().queries[0].name).toEqual(_query2); - - expect(lookupField).toMatchSnapshot(); - lookupField.unmount(); - }); - }); - }); - }); - }); - }); - - test('Selected container changes queries', () => { - const _container1 = '/StudyVerifyProject/My Study'; - const _container2 = '/StudyVerifyProject'; - const _schema1 = 'exp'; - const _query1 = 'Data'; - const _label = 'Lookup Field Options'; - const _index = 1; - const _domainIndex = 1; - - const field = DomainField.create({ - name: 'key', - rangeURI: INT_RANGE_URI, - propertyId: 1, - propertyURI: 'test', - }); - - const lookupField = mount( - - - - ); - - // Folder - const folderField = folderFieldSelector(lookupField, _domainIndex, _index); - let queryField = queryFieldSelector(lookupField, _domainIndex, _index); - expect(queryField.state().queries).toBeUndefined(); - return waitForLoad(folderField).then(() => { - expect(folderField.props().value).toEqual(_container1); - - return waitForLoad(queryField).then(() => { - expect(queryField.state().queries.length).toEqual(3); - - lookupField.setProps({ - children: ( - - ), - }); - - return waitForLoad(folderField).then(() => { - // Query - queryField = queryFieldSelector(lookupField, _domainIndex, _index); - return waitForLoad(queryField).then(() => { - queryField = queryFieldSelector(lookupField, _domainIndex, _index); - // Verify query field - expect(queryField.props().value).toEqual(''); - expect(queryField.state().queries.length).toBe(0); - - expect(lookupField).toMatchSnapshot(); - lookupField.unmount(); - }); - }); - }); - }); - }); - - test('lockType', () => { - const base = { - field: new DomainField({ - original: {}, - dataType: PropDescType.fromName('string'), - lookupSchema: 'schema', - lookupQueryValue: 'query', - }), - lookupContainer: 'container', - onMultiChange: jest.fn, - onChange: jest.fn, - index: 0, - domainIndex: 0, - label: 'Foo', - }; - - function validateDisabled(lockType: string, expectDisabled: boolean) { - const component = ( - - - - ); - const wrapper = mount(component); - expect(wrapper.find(FolderSelect).prop('disabled')).toBe(expectDisabled); - expect(wrapper.find(SchemaSelect).prop('disabled')).toBe(expectDisabled); - expect(wrapper.find(TargetTableSelect).prop('disabled')).toBe(expectDisabled); - wrapper.unmount(); - } - - validateDisabled(DOMAIN_FIELD_NOT_LOCKED, false); - validateDisabled(DOMAIN_FIELD_PARTIALLY_LOCKED, true); - validateDisabled(DOMAIN_FIELD_FULLY_LOCKED, true); - }); - - test('Invalid lookup', () => { - const _index = 1; - const _domainIndex = 1; - const _invalidLookup = 'rangeURI|InvalidLookup'; - - const field = DomainField.create({ - name: 'key', - rangeURI: INT_RANGE_URI, - propertyId: 1, - propertyURI: 'test', - }); - - const lookupField = mount( - - - - ); - - const folderField = folderFieldSelector(lookupField, _domainIndex, _index); - return waitForLoad(folderField).then(() => { - // Query - const queryField = queryFieldSelector(lookupField, _domainIndex, _index); - - return waitForLoad(queryField).then(() => { - // Verify query field - expect(queryField.state().queries.length).toEqual(4); // exp queries plus unknown query - expect(queryField.props().value).toEqual(_invalidLookup); - lookupField.unmount(); - }); - }); - }); -}); diff --git a/packages/components/src/internal/components/domainproperties/LookupFieldOptions.test.tsx b/packages/components/src/internal/components/domainproperties/LookupFieldOptions.test.tsx new file mode 100644 index 0000000000..6de4f79524 --- /dev/null +++ b/packages/components/src/internal/components/domainproperties/LookupFieldOptions.test.tsx @@ -0,0 +1,404 @@ +import React from 'react'; +import { render, waitFor } from '@testing-library/react'; + +import { MockLookupProvider } from '../../../test/MockLookupProvider'; + +import { createFormInputId } from './utils'; +import { + DOMAIN_FIELD_FULLY_LOCKED, + DOMAIN_FIELD_LOOKUP_CONTAINER, + DOMAIN_FIELD_LOOKUP_QUERY, + DOMAIN_FIELD_LOOKUP_SCHEMA, + DOMAIN_FIELD_NOT_LOCKED, + DOMAIN_FIELD_PARTIALLY_LOCKED, + INT_RANGE_URI, +} from './constants'; +import { DomainField } from './models'; +import { LookupFieldOptions } from './LookupFieldOptions'; +import { PropDescType } from './PropDescType'; + +describe('LookupFieldOptions', () => { + function getFolderSelect(domainIndex: number, index: number): HTMLSelectElement { + return document.getElementById( + createFormInputId(DOMAIN_FIELD_LOOKUP_CONTAINER, domainIndex, index) + ) as HTMLSelectElement; + } + + function getSchemaSelect(domainIndex: number, index: number): HTMLSelectElement { + return document.getElementById( + createFormInputId(DOMAIN_FIELD_LOOKUP_SCHEMA, domainIndex, index) + ) as HTMLSelectElement; + } + + function getQuerySelect(domainIndex: number, index: number): HTMLSelectElement { + return document.getElementById( + createFormInputId(DOMAIN_FIELD_LOOKUP_QUERY, domainIndex, index) + ) as HTMLSelectElement; + } + + test('Lookup field options', async () => { + const _container = '/StudyVerifyProject/My Study'; + const _schema = 'exp'; + const _index = 1; + const _domainIndex = 1; + const _label = 'Lookup Field Options'; + + const field = DomainField.create({ + name: 'key', + rangeURI: INT_RANGE_URI, + propertyId: 1, + propertyURI: 'test', + }); + + render( + + + + ); + + // Verify section label + expect(document.querySelector('.domain-field-section-heading')).toHaveTextContent(_label); + + // Folder: wait for 2 containers to load (plus the "Current Folder" option = 3 total) + await waitFor(() => expect(getFolderSelect(_domainIndex, _index).options.length).toBeGreaterThan(1)); + const folderOptions = Array.from(getFolderSelect(_domainIndex, _index).options).map(o => o.text); + expect(folderOptions).toHaveLength(3); + expect(folderOptions).toContain('/StudyVerifyProject'); + expect(folderOptions).toContain('/StudyVerifyProject/My Study'); + + // Schema: wait for 5 schemas to load for /StudyVerifyProject/My Study (sorted by fullyQualifiedName) + await waitFor(() => expect(getSchemaSelect(_domainIndex, _index).options.length).toBe(5)); + expect(getSchemaSelect(_domainIndex, _index).options[0].value).toBe('exp'); + expect(getSchemaSelect(_domainIndex, _index).options[4].value).toBe('study'); + + // Query: wait for 3 queries to load for exp schema + await waitFor(() => expect(getQuerySelect(_domainIndex, _index).options.length).toBe(3)); + const queryOptions = Array.from(getQuerySelect(_domainIndex, _index).options).map(o => o.text); + expect(queryOptions[1]).toContain('DataInputs'); + }); + + test('Selected container changes schemas', async () => { + const _container1 = '/StudyVerifyProject/My Study'; + const _container2 = '/StudyVerifyProject'; + const _index = 1; + const _domainIndex = 1; + const _schema = 'exp'; + const _label = 'Lookup Field Options'; + + const field = DomainField.create({ + name: 'key', + rangeURI: INT_RANGE_URI, + propertyId: 1, + propertyURI: 'test', + }); + + const { rerender } = render( + + + + ); + + // Wait for initial schemas to load for /StudyVerifyProject/My Study (5 schemas) + await waitFor(() => expect(getSchemaSelect(_domainIndex, _index).options.length).toBe(5)); + expect(getSchemaSelect(_domainIndex, _index).options[0].value).toBe('exp'); + expect(getSchemaSelect(_domainIndex, _index).options[1].value).toBe('exp.data'); + expect(getSchemaSelect(_domainIndex, _index).options[2].value).toBe('exp.materials'); + expect(getSchemaSelect(_domainIndex, _index).options[3].value).toBe('lists'); + expect(getSchemaSelect(_domainIndex, _index).options[4].value).toBe('study'); + + // Re-render with the new container + rerender( + + + + ); + + // Schema count should update to 1 for /StudyVerifyProject (only 'lists') + await waitFor(() => expect(getSchemaSelect(_domainIndex, _index).options.length).toBe(2)); + expect(getSchemaSelect(_domainIndex, _index).options[0].value).toBe(''); + expect(getSchemaSelect(_domainIndex, _index).options[1].value).toBe('lists'); + }); + + test('Selected schema changes queries', async () => { + const _container = '/StudyVerifyProject/My Study'; + const _schema1 = 'exp'; + const _schema2 = 'study'; + const _label = 'Lookup Field Options'; + const _index = 1; + const _domainIndex = 1; + + const field = DomainField.create({ + name: 'key', + rangeURI: INT_RANGE_URI, + propertyId: 1, + propertyURI: 'test', + }); + + const { rerender } = render( + + + + ); + + // Wait for initial query options (4: 3 from exp + 1 prepended for invalid lookup since lookupIsValid is not set) + await waitFor(() => expect(getQuerySelect(_domainIndex, _index).options.length).toBe(4)); + expect(getSchemaSelect(_domainIndex, _index).options[0].value).toBe('exp'); + expect(getSchemaSelect(_domainIndex, _index).options[1].value).toBe('exp.data'); + expect(getSchemaSelect(_domainIndex, _index).options[2].value).toBe('exp.materials'); + expect(getSchemaSelect(_domainIndex, _index).options[3].value).toBe('lists'); + + // Re-render with the new schema (study) + rerender( + + + + ); + + // Query options should update to 1 (study schema has 1 query: Treatment) + await waitFor(() => expect(getQuerySelect(_domainIndex, _index).options.length).toBe(2)); + expect(getQuerySelect(_domainIndex, _index).options[0].text).toContain(''); + expect(getQuerySelect(_domainIndex, _index).options[1].text).toContain('Treatment'); + }); + + test('Selected container changes queries', async () => { + const _container1 = '/StudyVerifyProject/My Study'; + const _container2 = '/StudyVerifyProject'; + const _schema1 = 'exp'; + const _label = 'Lookup Field Options'; + const _index = 1; + const _domainIndex = 1; + + const field = DomainField.create({ + name: 'key', + rangeURI: INT_RANGE_URI, + propertyId: 1, + propertyURI: 'test', + }); + + const { rerender } = render( + + + + ); + + // Wait for initial query options (3 queries for exp in /StudyVerifyProject/My Study) + await waitFor(() => expect(getQuerySelect(_domainIndex, _index).options.length).toBe(3)); + + // Re-render with the new container and empty schema/query + rerender( + + + + ); + + // No schema selected → no queries; the select shows a disabled "(No tables)" option + await waitFor(() => + expect( + document.querySelector( + `#${createFormInputId(DOMAIN_FIELD_LOOKUP_QUERY, _domainIndex, _index)} option[disabled]` + ) + ).toHaveTextContent('(No tables)') + ); + }); + + test('lockType', async () => { + const base = { + field: new DomainField({ + original: {}, + dataType: PropDescType.fromName('string'), + lookupSchema: 'schema', + lookupQueryValue: 'query', + }), + lookupContainer: 'container', + onMultiChange: jest.fn, + onChange: jest.fn, + index: 0, + domainIndex: 0, + label: 'Foo', + }; + + async function validateDisabled(lockType: string, expectDisabled: boolean): Promise { + const { unmount } = render( + + + + ); + + if (expectDisabled) { + expect(getFolderSelect(0, 0)).toBeDisabled(); + expect(getSchemaSelect(0, 0)).toBeDisabled(); + expect(getQuerySelect(0, 0)).toBeDisabled(); + } else { + // Wait for async loading to complete before checking enabled state + await waitFor(() => expect(getFolderSelect(0, 0)).not.toBeDisabled()); + expect(getSchemaSelect(0, 0)).not.toBeDisabled(); + } + + unmount(); + } + + await validateDisabled(DOMAIN_FIELD_NOT_LOCKED, false); + await validateDisabled(DOMAIN_FIELD_PARTIALLY_LOCKED, true); + await validateDisabled(DOMAIN_FIELD_FULLY_LOCKED, true); + }); + + test('Invalid lookup', async () => { + const _index = 1; + const _domainIndex = 1; + const _invalidLookup = 'rangeURI|InvalidLookup'; + + const field = DomainField.create({ + name: 'key', + rangeURI: INT_RANGE_URI, + propertyId: 1, + propertyURI: 'test', + }); + + render( + + + + ); + + // Wait for queries to load: exp queries plus the invalid/unknown query prepended = 4 total + await waitFor(() => expect(getQuerySelect(_domainIndex, _index).options.length).toBe(4)); + + // The invalid lookup entry is prepended with 'Unknown' label + const firstOption = getQuerySelect(_domainIndex, _index).options[0].text; + expect(firstOption).toContain('InvalidLookup'); + expect(firstOption).toContain('Unknown'); + }); +}); diff --git a/packages/components/src/internal/components/domainproperties/TextFieldOptions.spec.tsx b/packages/components/src/internal/components/domainproperties/TextFieldOptions.spec.tsx deleted file mode 100644 index 5b36c5d217..0000000000 --- a/packages/components/src/internal/components/domainproperties/TextFieldOptions.spec.tsx +++ /dev/null @@ -1,167 +0,0 @@ -import { mount } from 'enzyme'; -import React from 'react'; - -import { createFormInputId } from './utils'; -import { - DOMAIN_FIELD_CUSTOM_LENGTH, - DOMAIN_FIELD_MAX_LENGTH, - DOMAIN_FIELD_NOT_LOCKED, - DOMAIN_FIELD_SCALE, - MAX_TEXT_LENGTH, -} from './constants'; - -import { TextFieldOptions, TextFieldState } from './TextFieldOptions'; - -const SCANNABLE_OPTION_CLASS = '.domain-text-option-scannable'; - -describe('TextFieldOptions', () => { - test('Text data type', () => { - const maxLengthRadio = { id: createFormInputId(DOMAIN_FIELD_MAX_LENGTH, 1, 1) }; - const customLengthRadio = { id: createFormInputId(DOMAIN_FIELD_CUSTOM_LENGTH, 1, 1) }; - const scaleInput = { - id: createFormInputId(DOMAIN_FIELD_SCALE, 1, 1), - className: 'form-control domain-text-length-field', - }; - - const _section = 'Text Field Options'; - const _scale0 = MAX_TEXT_LENGTH; - const _scale1 = 4001; // using a value larger then the max length of 4000, will revert back to unlimited - const _scale2 = 200; - - const props0 = { - index: 1, - domainIndex: 1, - label: _section, - scale: _scale0, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - }; - - let textField = mount(); - - // Verify label - const sectionLabel = textField.find({ className: 'domain-field-section-heading' }); - expect(sectionLabel.length).toEqual(1); - expect(sectionLabel.text()).toEqual(_section); - - // Verify max length is not set for scale 4000 - const maxLength = textField.find(maxLengthRadio).not({ bsClass: 'form-control' }); - expect(maxLength.length).toEqual(1); - expect(maxLength.props().checked).toEqual(false); - - // Custom length is checked for scale 4000 - const customLength = textField.find(customLengthRadio).not({ bsClass: 'form-control' }); - expect(customLength.length).toEqual(1); - expect(customLength.props().checked).toEqual(true); - - // Custom value - const lengthField0 = textField.find(scaleInput); - expect(lengthField0.length).toEqual(1); - expect(lengthField0.props().value).toEqual(MAX_TEXT_LENGTH); - - // Change scale to a value larger then max allowed and verify radio buttons - const props1 = { - index: 1, - domainIndex: 1, - label: _section, - scale: _scale1, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - }; - textField = mount(); - const radioState1 = textField.state() as TextFieldState; - expect(radioState1.radio).toEqual(DOMAIN_FIELD_MAX_LENGTH); - - // Custom value - const lengthField1 = textField.find(scaleInput); - expect(lengthField1.length).toEqual(1); - expect(lengthField1.props().value).toEqual(MAX_TEXT_LENGTH); - - // Change scale and verify radio buttons - const props2 = { - index: 1, - domainIndex: 1, - label: _section, - scale: _scale2, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - }; - textField = mount(); - const radioState2 = textField.state() as TextFieldState; - expect(radioState2.radio).toEqual(DOMAIN_FIELD_CUSTOM_LENGTH); - - // Custom value - const lengthField2 = textField.find(scaleInput); - expect(lengthField2.length).toEqual(1); - expect(lengthField2.props().value).toEqual(_scale2); - - expect(textField).toMatchSnapshot(); - textField.unmount(); - }); - - test('Scannable Option field not shown', () => { - const props = { - index: 1, - domainIndex: 1, - label: 'Text Field Options', - scale: 4000, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - }; - - // All cases below should not display the field - const textField = mount(); - expect(textField.find(SCANNABLE_OPTION_CLASS)).toHaveLength(0); - textField.unmount(); - - const textField2 = mount(); - expect(textField2.find(SCANNABLE_OPTION_CLASS)).toHaveLength(0); - textField2.unmount(); - - const textField3 = mount(); - expect(textField3.find(SCANNABLE_OPTION_CLASS)).toHaveLength(0); - textField3.unmount(); - }); - - test('Scannable Option field shown and default false', () => { - const props = { - index: 1, - domainIndex: 1, - label: 'Text Field Options', - scale: 4000, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - }; - - const textField = mount(); - const scannable = textField.find(SCANNABLE_OPTION_CLASS).not({ bsClass: 'form-control' }); - expect(scannable.length).toEqual(1); - expect(scannable.props().checked).toEqual(false); - textField.unmount(); - }); - - test('Scannable Option value', () => { - const props = { - index: 1, - domainIndex: 1, - label: 'Text Field Options', - scale: 4000, - onChange: jest.fn(), - lockType: DOMAIN_FIELD_NOT_LOCKED, - showScannableOption: true, - appPropertiesOnly: true, - }; - - const textField = mount(); - const scannable = textField.find(SCANNABLE_OPTION_CLASS).not({ bsClass: 'form-control' }); - expect(scannable.length).toEqual(1); - expect(scannable.props().checked).toEqual(true); - textField.unmount(); - - const textField2 = mount(); - const scannable2 = textField2.find(SCANNABLE_OPTION_CLASS).not({ bsClass: 'form-control' }); - expect(scannable2.length).toEqual(1); - expect(scannable2.props().checked).toEqual(false); - textField2.unmount(); - }); -}); diff --git a/packages/components/src/internal/components/domainproperties/TextFieldOptions.test.tsx b/packages/components/src/internal/components/domainproperties/TextFieldOptions.test.tsx new file mode 100644 index 0000000000..d9214dd337 --- /dev/null +++ b/packages/components/src/internal/components/domainproperties/TextFieldOptions.test.tsx @@ -0,0 +1,116 @@ +import React from 'react'; + +import { renderWithAppContext } from '../../test/reactTestLibraryHelpers'; +import { createFormInputId } from './utils'; +import { + DOMAIN_FIELD_CUSTOM_LENGTH, + DOMAIN_FIELD_MAX_LENGTH, + DOMAIN_FIELD_NOT_LOCKED, + DOMAIN_FIELD_SCALE, + MAX_TEXT_LENGTH, +} from './constants'; + +import { TextFieldOptions } from './TextFieldOptions'; + +const SCANNABLE_OPTION_SELECTOR = '.domain-text-option-scannable'; + +describe('TextFieldOptions', () => { + const DEFAULT_PROPS = { + index: 1, + domainIndex: 1, + label: 'Text Field Options', + scale: MAX_TEXT_LENGTH, + onChange: jest.fn(), + lockType: DOMAIN_FIELD_NOT_LOCKED, + }; + + const maxLengthId = `#${createFormInputId(DOMAIN_FIELD_MAX_LENGTH, 1, 1)}`; + const customLengthId = `#${createFormInputId(DOMAIN_FIELD_CUSTOM_LENGTH, 1, 1)}`; + const scaleId = `#${createFormInputId(DOMAIN_FIELD_SCALE, 1, 1)}`; + + test('Text data type - scale MAX_TEXT_LENGTH', () => { + renderWithAppContext(); + + // Verify label + expect(document.querySelector('.domain-field-section-heading')).toHaveTextContent('Text Field Options'); + + // Verify max length is not checked for scale 4000 + expect(document.querySelector(maxLengthId)).not.toBeChecked(); + + // Custom length is checked for scale 4000 + expect(document.querySelector(customLengthId)).toBeChecked(); + + // Custom value + expect(document.querySelector(scaleId)).toHaveValue(MAX_TEXT_LENGTH); + }); + + test('Text data type - scale > MAX_TEXT_LENGTH reverts to unlimited', () => { + // using a value larger than the max length of 4000, will revert back to unlimited + renderWithAppContext(); + + // max length radio should be checked (radio state = DOMAIN_FIELD_MAX_LENGTH) + expect(document.querySelector(maxLengthId)).toBeChecked(); + + // Scale input shows MAX_TEXT_LENGTH + expect(document.querySelector(scaleId)).toHaveValue(MAX_TEXT_LENGTH); + }); + + test('Text data type - custom scale', () => { + renderWithAppContext(); + + // custom length radio should be checked (radio state = DOMAIN_FIELD_CUSTOM_LENGTH) + expect(document.querySelector(customLengthId)).toBeChecked(); + + // Scale input shows 200 + expect(document.querySelector(scaleId)).toHaveValue(200); + }); + + test('Scannable Option field not shown - showScannableOption false, appPropertiesOnly false', () => { + renderWithAppContext( + + ); + expect(document.querySelectorAll(SCANNABLE_OPTION_SELECTOR)).toHaveLength(0); + }); + + test('Scannable Option field not shown - showScannableOption true, appPropertiesOnly false', () => { + renderWithAppContext( + + ); + expect(document.querySelectorAll(SCANNABLE_OPTION_SELECTOR)).toHaveLength(0); + }); + + test('Scannable Option field not shown - showScannableOption false, appPropertiesOnly true', () => { + renderWithAppContext( + + ); + expect(document.querySelectorAll(SCANNABLE_OPTION_SELECTOR)).toHaveLength(0); + }); + + test('Scannable Option field shown and default false', () => { + renderWithAppContext( + + ); + const scannable = document.querySelector(SCANNABLE_OPTION_SELECTOR); + expect(scannable).toBeInTheDocument(); + expect(scannable).not.toBeChecked(); + }); + + test('Scannable Option value - scannable true', () => { + renderWithAppContext( + + ); + expect(document.querySelector(SCANNABLE_OPTION_SELECTOR)).toBeChecked(); + }); + + test('Scannable Option value - scannable false', () => { + renderWithAppContext( + + ); + expect(document.querySelector(SCANNABLE_OPTION_SELECTOR)).not.toBeChecked(); + }); +}); diff --git a/packages/components/src/internal/components/domainproperties/__snapshots__/LookupFieldOptions.spec.tsx.snap b/packages/components/src/internal/components/domainproperties/__snapshots__/LookupFieldOptions.spec.tsx.snap deleted file mode 100644 index 47757e4302..0000000000 --- a/packages/components/src/internal/components/domainproperties/__snapshots__/LookupFieldOptions.spec.tsx.snap +++ /dev/null @@ -1,2301 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`LookupFieldOptions Lookup field options 1`] = ` - - -
-
-
-
- Lookup Field Options -
-
-
-
-
-
- Target Folder -
- - - - - -
-
-
- Target Schema -
- - - - - -
-
-
- Target Table -
- - - - - -
-
-
- Lookup Validator -
- -
- -
-
-
-
-
-
-
-`; - -exports[`LookupFieldOptions Selected container changes queries 1`] = ` - - -
-
-
-
- Lookup Field Options -
-
-
-
-
-
- Target Folder -
- - - - - -
-
-
- Target Schema -
- - - - - -
-
-
- Target Table -
- - - - - -
-
-
- Lookup Validator -
- -
- -
-
-
-
-
-
-
-`; - -exports[`LookupFieldOptions Selected container changes schemas 1`] = ` - - -
-
-
-
- Lookup Field Options -
-
-
-
-
-
- Target Folder -
- - - - - -
-
-
- Target Schema -
- - - - - -
-
-
- Target Table -
- - - - - -
-
-
- Lookup Validator -
- -
- -
-
-
-
-
-
-
-`; - -exports[`LookupFieldOptions Selected schema changes queries 1`] = ` - - -
-
-
-
- Lookup Field Options -
-
-
-
-
-
- Target Folder -
- - - - - -
-
-
- Target Schema -
- - - - - -
-
-
- Target Table -
- - - - - -
-
-
- Lookup Validator -
- -
- -
-
-
-
-
-
-
-`; diff --git a/packages/components/src/internal/components/domainproperties/__snapshots__/TextFieldOptions.spec.tsx.snap b/packages/components/src/internal/components/domainproperties/__snapshots__/TextFieldOptions.spec.tsx.snap deleted file mode 100644 index 0f733e80a1..0000000000 --- a/packages/components/src/internal/components/domainproperties/__snapshots__/TextFieldOptions.spec.tsx.snap +++ /dev/null @@ -1,160 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`TextFieldOptions Text data type 1`] = ` - -
-
-
- -
- Text Field Options -
-
-
-
-
-
-
- -

- Sets the maximum character count for a text field. -

-

- Anything over 4,000 characters will use the 'Unlimited' designation. -

- - } - label="Maximum Text Length" - > - Maximum Text - - Length - - - -

- Sets the maximum character count for a text field. -

-

- Anything over 4,000 characters will use the 'Unlimited' designation. -

-
- - } - > -
- - - -
-
-
-
-
-
-
-
-
-
- -
- Unlimited -
-
-
-
-
- - - No longer than - - characters - -
-
- -
-
-`; diff --git a/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.spec.tsx b/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.spec.tsx deleted file mode 100644 index 27c05fc77b..0000000000 --- a/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.spec.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from 'react'; -import { mount } from 'enzyme'; -import renderer from 'react-test-renderer'; - -import { SectionHeading } from '../SectionHeading'; - -import getDomainDetailsJSON from '../../../../test/data/list-getDomainDetails.json'; -import { DEFAULT_LIST_SETTINGS } from '../../../../test/data/constants'; - -import { - AllowableActions, - BasicPropertiesFields, - CheckBoxRow, - DescriptionInput, - NameInput, -} from './ListPropertiesPanelFormElements'; -import { ListModel } from './models'; - -const emptyNewModel = ListModel.create(null, DEFAULT_LIST_SETTINGS); -const populatedExistingModel = ListModel.create(getDomainDetailsJSON); - -describe('BasicPropertiesFields', () => { - test('new list, default properties', () => { - const basicPropertiesFields = ; - - const tree = renderer.create(basicPropertiesFields).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - test('existing list, existing properties', () => { - const basicPropertiesFields = ( - - ); - - const tree = renderer.create(basicPropertiesFields).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - test('visible basic properties', () => { - const basicPropertiesFields = mount( - - ); - - expect(basicPropertiesFields.find(SectionHeading)).toHaveLength(1); - expect(basicPropertiesFields.find(NameInput)).toHaveLength(1); - expect(basicPropertiesFields.find(DescriptionInput)).toHaveLength(1); - basicPropertiesFields.unmount(); - }); -}); - -describe('AllowableActions', () => { - test('new list, default properties', () => { - const allowableActions = ; - - const tree = renderer.create(allowableActions).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - test('existing list, existing properties', () => { - const allowableActions = ; - - const tree = renderer.create(allowableActions).toJSON(); - expect(tree).toMatchSnapshot(); - }); - - test('visible AllowableActions', () => { - const allowableActions = mount( - - ); - - expect(allowableActions.find(CheckBoxRow)).toHaveLength(3); - allowableActions.unmount(); - }); -}); diff --git a/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.test.tsx b/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.test.tsx new file mode 100644 index 0000000000..5df9f1ab26 --- /dev/null +++ b/packages/components/src/internal/components/domainproperties/list/ListPropertiesPanelFormElements.test.tsx @@ -0,0 +1,55 @@ +import React from 'react'; + +import getDomainDetailsJSON from '../../../../test/data/list-getDomainDetails.json'; +import { DEFAULT_LIST_SETTINGS } from '../../../../test/data/constants'; + +import { AllowableActions, BasicPropertiesFields } from './ListPropertiesPanelFormElements'; +import { ListModel } from './models'; +import { renderWithAppContext } from '../../../test/reactTestLibraryHelpers'; + +const emptyNewModel = ListModel.create(null, DEFAULT_LIST_SETTINGS); +const populatedExistingModel = ListModel.create(getDomainDetailsJSON); + +describe('BasicPropertiesFields', () => { + test('new list, default properties', () => { + const { asFragment } = renderWithAppContext( + + ); + expect(asFragment()).toMatchSnapshot(); + }); + + test('existing list, existing properties', () => { + const { asFragment } = renderWithAppContext( + + ); + expect(asFragment()).toMatchSnapshot(); + }); + + test('visible basic properties', () => { + renderWithAppContext(); + expect(document.querySelectorAll('.domain-field-section-heading')).toHaveLength(1); + expect(document.querySelectorAll('#name')).toHaveLength(1); + expect(document.querySelectorAll('#description')).toHaveLength(1); + }); +}); + +describe('AllowableActions', () => { + test('new list, default properties', () => { + const { asFragment } = renderWithAppContext( + + ); + expect(asFragment()).toMatchSnapshot(); + }); + + test('existing list, existing properties', () => { + const { asFragment } = renderWithAppContext( + + ); + expect(asFragment()).toMatchSnapshot(); + }); + + test('visible AllowableActions', () => { + renderWithAppContext(); + expect(document.querySelectorAll('.list__properties__checkbox-row')).toHaveLength(3); + }); +}); diff --git a/packages/components/src/internal/components/domainproperties/list/__snapshots__/ListPropertiesPanelFormElements.spec.tsx.snap b/packages/components/src/internal/components/domainproperties/list/__snapshots__/ListPropertiesPanelFormElements.spec.tsx.snap deleted file mode 100644 index ca73051f31..0000000000 --- a/packages/components/src/internal/components/domainproperties/list/__snapshots__/ListPropertiesPanelFormElements.spec.tsx.snap +++ /dev/null @@ -1,281 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AllowableActions existing list, existing properties 1`] = ` -
-
- Allow these Actions -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-`; - -exports[`AllowableActions new list, default properties 1`] = ` -
-
- Allow these Actions -
-
-
-
- -
-
-
-
- -
-
-
-
- -
-
-
-
-`; - -exports[`BasicPropertiesFields existing list, existing properties 1`] = ` -
-
- Basic Properties -
-
-
- - Name -
- - - -
- * -
-
-
- -
-
-
-
- - Description - - -
-
-