11import React from 'react' ;
22import { mount } from 'enzyme' ;
33import isEqual from 'lodash/isEqual' ;
4+ import FormRenderer , { componentTypes } from '@data-driven-forms/react-form-renderer' ;
45
56import Select from '../../common/select/select' ;
67import { act } from 'react-dom/test-utils' ;
8+ import ValueContainer from '../../common/select/value-container' ;
9+ import FormTemplate from '../../files/form-template' ;
10+ import componentMapper from '../../files/component-mapper' ;
711
812describe ( '<Select />' , ( ) => {
913 let initialProps ;
@@ -30,6 +34,47 @@ describe('<Select />', () => {
3034 onChange . mockReset ( ) ;
3135 } ) ;
3236
37+ it ( 'should render translated option in value container' , async ( ) => {
38+ const wrapper = mount (
39+ < FormRenderer
40+ onSubmit = { jest . fn }
41+ FormTemplate = { FormTemplate }
42+ componentMapper = { componentMapper }
43+ schema = { {
44+ fields : [
45+ {
46+ component : componentTypes . SELECT ,
47+ name : 'select' ,
48+ options : [
49+ {
50+ label : < h1 > Translated</ h1 > ,
51+ value : 'translated'
52+ }
53+ ]
54+ }
55+ ]
56+ } }
57+ />
58+ ) ;
59+
60+ expect ( wrapper . find ( ValueContainer ) . find ( 'h1' ) ) . toHaveLength ( 0 ) ;
61+
62+ wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
63+ const option = wrapper . find ( 'button.pf-c-select__menu-item' ) . first ( ) ;
64+
65+ await act ( async ( ) => {
66+ option . simulate ( 'click' ) ;
67+ } ) ;
68+ wrapper . update ( ) ;
69+
70+ expect (
71+ wrapper
72+ . find ( ValueContainer )
73+ . find ( 'h1' )
74+ . text ( )
75+ ) . toEqual ( 'Translated' ) ;
76+ } ) ;
77+
3378 it ( 'should return single simple value' , async ( ) => {
3479 const wrapper = mount ( < Select { ...initialProps } /> ) ;
3580 wrapper . find ( '.pf-c-select__toggle' ) . simulate ( 'click' ) ;
0 commit comments