@@ -20,8 +20,8 @@ import {
2020} from '../common/controllers/key-bindings.js' ;
2121import { defineComponents } from '../common/definitions/defineComponents.js' ;
2222import {
23- FormAssociatedTestBed ,
2423 type ValidationContainerTestsParams ,
24+ createFormAssociatedTestBed ,
2525 isFocused ,
2626 runValidationContainerTests ,
2727 simulateClick ,
@@ -1238,51 +1238,44 @@ describe('Select', () => {
12381238 } ) ;
12391239
12401240 describe ( 'Form integration' , ( ) => {
1241- const spec = new FormAssociatedTestBed < IgcSelectComponent > (
1242- createBasicSelect ( )
1243- ) ;
1241+ const spec =
1242+ createFormAssociatedTestBed < IgcSelectComponent > ( createBasicSelect ( ) ) ;
12441243
12451244 beforeEach ( async ( ) => {
12461245 await spec . setup ( IgcSelectComponent . tagName ) ;
12471246 } ) ;
12481247
1249- it ( 'is form associated' , async ( ) => {
1248+ it ( 'is form associated' , ( ) => {
12501249 expect ( spec . element . form ) . to . equal ( spec . form ) ;
12511250 } ) ;
12521251
1253- it ( 'is not associated on submit if not value is present' , async ( ) => {
1254- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . be . null ;
1252+ it ( 'is not associated on submit if not value is present' , ( ) => {
1253+ spec . assertSubmitHasValue ( null ) ;
12551254 } ) ;
12561255
1257- it ( 'is associated on submit' , async ( ) => {
1258- spec . element . value = 'spec' ;
1259-
1260- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . equal (
1261- spec . element . value
1262- ) ;
1256+ it ( 'is associated on submit' , ( ) => {
1257+ spec . setProperties ( { value : 'spec' } ) ;
1258+ spec . assertSubmitHasValue ( spec . element . value ) ;
12631259 } ) ;
12641260
12651261 it ( 'is correctly reset on form reset' , ( ) => {
1266- spec . element . value = 'spec' ;
1267-
1262+ spec . setProperties ( { value : 'spec' } ) ;
12681263 spec . reset ( ) ;
1264+
12691265 expect ( spec . element . value ) . to . equal ( undefined ) ;
12701266 } ) ;
12711267
12721268 it ( 'is correctly reset on form reset after setAttribute() call' , ( ) => {
1273- spec . element . setAttribute ( 'value' , 'implementation' ) ;
1274- spec . element . value = 'spec' ;
1275-
1269+ spec . setAttributes ( { value : 'implementation' } ) ;
1270+ spec . setProperties ( { value : 'spec' } ) ;
12761271 spec . reset ( ) ;
12771272
12781273 expect ( spec . element . value ) . to . equal ( 'implementation' ) ;
1279- expect ( spec . submit ( ) ?. get ( spec . element . name ) ) . to . equal (
1280- spec . element . value
1281- ) ;
1274+ spec . assertSubmitHasValue ( spec . element . value ) ;
12821275 } ) ;
12831276
12841277 it ( 'is correctly reset of form reset with selection through attribute on item' , async ( ) => {
1285- const bed = new FormAssociatedTestBed < IgcSelectComponent > (
1278+ const bed = createFormAssociatedTestBed < IgcSelectComponent > (
12861279 html `< igc-select name ="with-item-selection ">
12871280 < igc-select-item value ="1 "> 1</ igc-select-item >
12881281 < igc-select-item value ="2 "> 2</ igc-select-item >
@@ -1291,40 +1284,95 @@ describe('Select', () => {
12911284 ) ;
12921285
12931286 await bed . setup ( IgcSelectComponent . tagName ) ;
1287+ expect ( bed . element . value ) . to . equal ( '3' ) ;
12941288
1295- expect ( bed . element . value ) . to . eq ( '3' ) ;
1296-
1297- bed . element . value = '1' ;
1298- expect ( bed . element . value ) . to . eq ( '1' ) ;
1289+ bed . setProperties ( { value : '1' } ) ;
1290+ expect ( bed . element . value ) . to . equal ( '1' ) ;
12991291
13001292 bed . reset ( ) ;
1301- expect ( bed . element . value ) . to . eq ( '3' ) ;
1293+ expect ( bed . element . value ) . to . equal ( '3' ) ;
13021294 } ) ;
13031295
1304- it ( 'reflects disabled ancestor state' , async ( ) => {
1296+ it ( 'reflects disabled ancestor state' , ( ) => {
13051297 spec . setAncestorDisabledState ( true ) ;
13061298 expect ( spec . element . disabled ) . to . be . true ;
13071299
13081300 spec . setAncestorDisabledState ( false ) ;
13091301 expect ( spec . element . disabled ) . to . be . false ;
13101302 } ) ;
13111303
1312- it ( 'fulfils required constraint' , async ( ) => {
1313- spec . element . required = true ;
1314- await elementUpdated ( spec . element ) ;
1315- spec . submitFails ( ) ;
1304+ it ( 'fulfils required constraint' , ( ) => {
1305+ spec . setProperties ( { required : true } ) ;
1306+ spec . assertSubmitFails ( ) ;
13161307
1317- spec . element . value = 'spec' ;
1318- await elementUpdated ( spec . element ) ;
1319- spec . submitValidates ( ) ;
1308+ spec . setProperties ( { value : 'spec' } ) ;
1309+ spec . assertSubmitPasses ( ) ;
13201310 } ) ;
13211311
1322- it ( 'fulfils custom constraint' , async ( ) => {
1312+ it ( 'fulfils custom constraint' , ( ) => {
13231313 spec . element . setCustomValidity ( 'invalid' ) ;
1324- spec . submitFails ( ) ;
1314+ spec . assertSubmitFails ( ) ;
13251315
13261316 spec . element . setCustomValidity ( '' ) ;
1327- spec . submitValidates ( ) ;
1317+ spec . assertSubmitPasses ( ) ;
1318+ } ) ;
1319+ } ) ;
1320+
1321+ describe ( 'defaultValue' , ( ) => {
1322+ describe ( 'Form integration' , ( ) => {
1323+ const spec = createFormAssociatedTestBed < IgcSelectComponent > ( html `
1324+ < igc-select name ="select " .defaultValue =${ '1' } >
1325+ < igc-select-item value ="1 "> 1</ igc-select-item >
1326+ < igc-select-item value ="2 "> 2</ igc-select-item >
1327+ < igc-select-item value ="3 "> 3</ igc-select-item >
1328+ </ igc-select >
1329+ ` ) ;
1330+
1331+ beforeEach ( async ( ) => {
1332+ await spec . setup ( IgcSelectComponent . tagName ) ;
1333+ } ) ;
1334+
1335+ it ( 'correct initial state' , ( ) => {
1336+ spec . assertIsPristine ( ) ;
1337+ expect ( spec . element . value ) . to . equal ( '1' ) ;
1338+ } ) ;
1339+
1340+ it ( 'is correctly submitted' , ( ) => {
1341+ spec . assertSubmitHasValue ( spec . element . value ) ;
1342+ } ) ;
1343+
1344+ it ( 'is correctly reset' , ( ) => {
1345+ spec . setProperties ( { value : '3' } ) ;
1346+ spec . reset ( ) ;
1347+
1348+ expect ( spec . element . value ) . to . equal ( '1' ) ;
1349+ } ) ;
1350+ } ) ;
1351+
1352+ describe ( 'Validation' , ( ) => {
1353+ const spec = createFormAssociatedTestBed < IgcSelectComponent > ( html `
1354+ < igc-select name ="select " required .defaultValue =${ undefined } >
1355+ < igc-select-item value ="1 "> 1</ igc-select-item >
1356+ < igc-select-item value ="2 "> 2</ igc-select-item >
1357+ < igc-select-item value ="3 "> 3</ igc-select-item >
1358+ </ igc-select >
1359+ ` ) ;
1360+
1361+ beforeEach ( async ( ) => {
1362+ await spec . setup ( IgcSelectComponent . tagName ) ;
1363+ } ) ;
1364+
1365+ it ( 'fails required validation' , ( ) => {
1366+ spec . assertIsPristine ( ) ;
1367+ spec . assertSubmitFails ( ) ;
1368+ } ) ;
1369+
1370+ it ( 'passes required validation' , ( ) => {
1371+ spec . setProperties ( { defaultValue : '1' } ) ;
1372+ spec . assertIsPristine ( ) ;
1373+
1374+ spec . assertSubmitPasses ( ) ;
1375+ } ) ;
13281376 } ) ;
13291377 } ) ;
13301378
0 commit comments