import { useStateManager } from '@fluentui/react-bindings'; import { createManager, ManagerFactory } from '@fluentui/state'; import { mount, shallow } from 'enzyme'; import * as React from 'react'; import * as ReactTestUtils from 'react-dom/test-utils'; type TestState = { open: boolean; value: string }; type TestActions = { change: (value: string) => void; toggle: () => void }; const createTestManager: ManagerFactory = config => createManager({ ...config, actions: { change: (value: string) => () => ({ value }), toggle: () => state => ({ open: !state.open }), }, state: { open: false, value: '', ...config.state, }, }); type TestComponentProps = Partial & { color?: string; onChange?: (value: string) => void; defaultOpen?: boolean; open?: boolean; defaultValue?: string; value?: string; }; const TestComponent: React.FunctionComponent = props => { const { state, actions } = useStateManager(createTestManager, { mapPropsToInitialState: () => ({ open: props.defaultOpen, value: props.defaultValue, }), mapPropsToState: () => ({ open: props.open, value: props.value, }), }); return ( <>
{ // Is used in UTs to check that state values is not changed if (props.onChange) props.onChange(state.value); actions.change(e.target.value); if (props.onChange) props.onChange(state.value); }} value={state.value} />