File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
packages/blueprint-component-mapper/src Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,13 @@ export const FormGroupInternal = ({
2222} ) => {
2323 const { required } = useContext ( BlueprintContext ) ;
2424
25- const { error, touched } = meta ;
25+ const { error, touched, warning } = meta ;
2626 const showError = ( validateOnMount || touched ) && error ;
27+ const showWarning = ( validateOnMount || touched ) && warning ;
2728
28- const text = showError ? error : helperText || description ;
29+ const text = showError || showWarning || helperText || description ;
2930
30- const intent = showError && error && { intent : Intent . DANGER } ;
31+ const intent = ( showError && { intent : Intent . DANGER } ) || ( showWarning && { intent : Intent . WARNING } ) ;
3132 const labelInfo = ! hideLabel && isRequired && { labelInfo : required } ;
3233
3334 return (
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { mount } from 'enzyme' ;
3+ import { act } from 'react-dom/test-utils' ;
34
45import FormRenderer , { componentTypes } from '@data-driven-forms/react-form-renderer' ;
56import FormTemplate from '../files/form-template' ;
@@ -107,6 +108,29 @@ describe('formFields generated tests', () => {
107108 expect ( wrapper . find ( '.bp3-intent-danger' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
108109 } ) ;
109110
111+ it ( 'renders with warning' , async ( ) => {
112+ const errorField = {
113+ ...field ,
114+ validate : [ { type : validatorTypes . REQUIRED , warning : true } ] ,
115+ useWarnings : true ,
116+ validateOnMount : true
117+ } ;
118+ let wrapper ;
119+
120+ await act ( async ( ) => {
121+ wrapper = mount ( < RendererWrapper schema = { { fields : [ errorField ] } } /> ) ;
122+ } ) ;
123+ wrapper . update ( ) ;
124+
125+ expect (
126+ wrapper
127+ . find ( '.bp3-form-helper-text' )
128+ . last ( )
129+ . text ( )
130+ ) . toEqual ( errorText ) ;
131+ expect ( wrapper . find ( '.bp3-intent-warning' ) . length ) . toBeGreaterThanOrEqual ( 1 ) ;
132+ } ) ;
133+
110134 it ( 'renders with helperText' , ( ) => {
111135 const helpertextField = {
112136 ...field ,
You can’t perform that action at this time.
0 commit comments