@@ -118,17 +118,6 @@ module('Integration | Component | form field', function (hooks) {
118
118
assert . ok ( spy . calledWith ( 'foo' , 'bar' ) , 'onChange called with correct args' ) ;
119
119
} ) ;
120
120
121
- test ( 'it renders: boolean' , async function ( assert ) {
122
- const [ model , spy ] = await setup . call ( this , createAttr ( 'foo' , 'boolean' , { defaultValue : false } ) ) ;
123
- assert . strictEqual ( component . fields . objectAt ( 0 ) . labelValue , 'Foo' , 'renders a label' ) ;
124
- assert . notOk ( component . fields . objectAt ( 0 ) . inputChecked , 'renders default value' ) ;
125
- assert . ok ( component . hasCheckbox , 'renders a checkbox for boolean' ) ;
126
- await component . fields . objectAt ( 0 ) . clickLabel ( ) ;
127
-
128
- assert . true ( model . get ( 'foo' ) ) ;
129
- assert . ok ( spy . calledWith ( 'foo' , true ) , 'onChange called with correct args' ) ;
130
- } ) ;
131
-
132
121
test ( 'it renders: number' , async function ( assert ) {
133
122
const [ model , spy ] = await setup . call ( this , createAttr ( 'foo' , 'number' , { defaultValue : 5 } ) ) ;
134
123
assert . strictEqual ( component . fields . objectAt ( 0 ) . labelValue , 'Foo' , 'renders a label' ) ;
@@ -1049,4 +1038,106 @@ module('Integration | Component | form field', function (hooks) {
1049
1038
. exists ( 'Validation warning renders' )
1050
1039
. hasText ( 'Warning message #1 Warning message #2' , 'Validation warnings are combined' ) ;
1051
1040
} ) ;
1041
+
1042
+ // ––––– type/editType === 'boolean' –––––
1043
+
1044
+ test ( 'it renders: type=boolean - as Hds::Form::Checkbox' , async function ( assert ) {
1045
+ await setup . call ( this , createAttr ( 'myfield' , 'boolean' , { defaultValue : 'false' } ) ) ;
1046
+ assert
1047
+ . dom ( '.field [class^="hds-form-field"] input[type="checkbox"].hds-form-checkbox' )
1048
+ . exists ( 'renders as Hds::Form::Checkbox::Field' ) ;
1049
+ assert
1050
+ . dom ( `input[type=checkbox]` )
1051
+ . exists ( 'renders input[type="checkbox"]' )
1052
+ . hasAttribute (
1053
+ 'data-test-input' ,
1054
+ 'myfield' ,
1055
+ 'input[type="checkbox"] has correct `data-test-input` attribute'
1056
+ ) ;
1057
+ assert . dom ( GENERAL . fieldLabel ( ) ) . hasText ( 'Myfield' , 'renders the input[type="checkbox"] label' ) ;
1058
+ } ) ;
1059
+
1060
+ test ( 'it renders: editType=boolean - as Hds::Form::Checkbox' , async function ( assert ) {
1061
+ await setup . call ( this , createAttr ( 'myfield' , '-' , { editType : 'boolean' , defaultValue : 'false' } ) ) ;
1062
+ assert
1063
+ . dom ( '.field [class^="hds-form-field"] input[type="checkbox"].hds-form-checkbox' )
1064
+ . exists ( 'renders as Hds::Form::Checkbox::Field' ) ;
1065
+ assert
1066
+ . dom ( `input[type=checkbox]` )
1067
+ . exists ( 'renders input[type="checkbox"]' )
1068
+ . hasAttribute (
1069
+ 'data-test-input' ,
1070
+ 'myfield' ,
1071
+ 'input[type="checkbox"] has correct `data-test-input` attribute'
1072
+ ) ;
1073
+ assert . dom ( GENERAL . fieldLabel ( ) ) . hasText ( 'Myfield' , 'renders the input[type="checkbox"] label' ) ;
1074
+ } ) ;
1075
+
1076
+ test ( 'it renders: editType=boolean - unselected by default' , async function ( assert ) {
1077
+ await setup . call ( this , createAttr ( 'myfield' , '-' , { editType : 'boolean' } ) ) ;
1078
+ assert . dom ( GENERAL . inputByAttr ( 'myfield' ) ) . isNotChecked ( 'input[type="checkbox"] is not checked' ) ;
1079
+ } ) ;
1080
+
1081
+ test ( 'it renders: editType=boolean - selected and changes it' , async function ( assert ) {
1082
+ const [ model , spy ] = await setup . call (
1083
+ this ,
1084
+ createAttr ( 'myfield' , '-' , { editType : 'boolean' , defaultValue : 'true' } )
1085
+ ) ;
1086
+ assert . dom ( GENERAL . inputByAttr ( 'myfield' ) ) . isChecked ( 'input[type="checkbox"] is checked' ) ;
1087
+ await click ( GENERAL . inputByAttr ( 'myfield' ) ) ;
1088
+ assert . false ( model . get ( 'myfield' ) ) ;
1089
+ assert . ok ( spy . calledWith ( 'myfield' , false ) , 'onChange called with correct args' ) ;
1090
+ } ) ;
1091
+
1092
+ test ( 'it renders: editType=boolean - with passed label, subtext, helptext, doclink' , async function ( assert ) {
1093
+ await setup . call (
1094
+ this ,
1095
+ createAttr ( 'myfield' , '-' , {
1096
+ editType : 'boolean' ,
1097
+ label : 'Custom label' ,
1098
+ subText : 'Some subtext' ,
1099
+ helpText : 'Some helptext' ,
1100
+ docLink : '/docs' ,
1101
+ } )
1102
+ ) ;
1103
+ assert . dom ( GENERAL . fieldLabel ( ) ) . hasText ( 'Custom label' , 'renders the custom label from options' ) ;
1104
+ assert
1105
+ . dom ( GENERAL . helpTextByAttr ( 'Some subtext' ) )
1106
+ . exists ( 'renders `subText` option as HelperText' )
1107
+ . hasText ( 'Some subtext Learn more here.' , 'renders the right subtext string from options' ) ;
1108
+ assert
1109
+ . dom ( `${ GENERAL . helpTextByAttr ( 'Some subtext' ) } ${ GENERAL . docLinkByAttr ( '/docs' ) } ` )
1110
+ . exists ( 'renders `docLink` option as as link inside the subtext' ) ;
1111
+ assert
1112
+ . dom ( GENERAL . helpTextByAttr ( 'Some helptext' ) )
1113
+ . exists ( 'renders `helptext` option as HelperText' )
1114
+ . hasText ( 'Some helptext' , 'renders the right help text string from options' ) ;
1115
+ } ) ;
1116
+
1117
+ test ( 'it renders: editType=boolean - with validation errors and warnings' , async function ( assert ) {
1118
+ this . setProperties ( {
1119
+ attr : createAttr ( 'myfield' , '-' , { editType : 'boolean' } ) ,
1120
+ model : { myfield : false } ,
1121
+ modelValidations : {
1122
+ myfield : {
1123
+ isValid : false ,
1124
+ errors : [ 'Error message #1' , 'Error message #2' ] ,
1125
+ warnings : [ 'Warning message #1' , 'Warning message #2' ] ,
1126
+ } ,
1127
+ } ,
1128
+ onChange : ( ) => { } ,
1129
+ } ) ;
1130
+
1131
+ await render (
1132
+ hbs `<FormField @attr={{this.attr}} @model={{this.model}} @modelValidations={{this.modelValidations}} @onChange={{this.onChange}} />`
1133
+ ) ;
1134
+ assert
1135
+ . dom ( GENERAL . validationErrorByAttr ( 'myfield' ) )
1136
+ . exists ( 'Validation error renders' )
1137
+ . hasText ( 'Error message #1 Error message #2' , 'Validation errors are combined' ) ;
1138
+ assert
1139
+ . dom ( GENERAL . validationWarningByAttr ( 'myfield' ) )
1140
+ . exists ( 'Validation warning renders' )
1141
+ . hasText ( 'Warning message #1 Warning message #2' , 'Validation warnings are combined' ) ;
1142
+ } ) ;
1052
1143
} ) ;
0 commit comments