@@ -8,11 +8,6 @@ import {
88import { nothing } from 'lit' ;
99import { spy } from 'sinon' ;
1010
11- import {
12- IgcRatingComponent ,
13- type IgcRatingSymbolComponent ,
14- defineComponents ,
15- } from '../../index.js' ;
1611import {
1712 arrowDown ,
1813 arrowLeft ,
@@ -21,34 +16,38 @@ import {
2116 endKey ,
2217 homeKey ,
2318} from '../common/controllers/key-bindings.js' ;
19+ import { defineComponents } from '../common/definitions/defineComponents.js' ;
2420import {
2521 FormAssociatedTestBed ,
22+ simulateClick ,
2623 simulateKeyboard ,
24+ simulatePointerMove ,
2725} from '../common/utils.spec.js' ;
26+ import IgcRatingSymbolComponent from './rating-symbol.js' ;
27+ import IgcRatingComponent from './rating.js' ;
2828
2929describe ( 'Rating component' , ( ) => {
3030 before ( ( ) => {
3131 defineComponents ( IgcRatingComponent ) ;
3232 } ) ;
3333
34+ let el : IgcRatingComponent ;
35+
3436 const getRatingSymbols = ( el : IgcRatingComponent ) =>
35- el . shadowRoot ! . querySelectorAll (
36- 'igc-rating-symbol'
37- ) as NodeListOf < IgcRatingSymbolComponent > ;
38- const getProjectedSymbols = ( el : IgcRatingComponent ) => {
39- const slot = el . shadowRoot ! . querySelector (
40- 'slot[name="symbol"]'
41- ) as HTMLSlotElement ;
42- return slot
43- . assignedElements ( )
44- . filter ( ( el ) => el . matches ( 'igc-rating-symbol' ) ) ;
45- } ;
37+ el . renderRoot . querySelectorAll ( IgcRatingSymbolComponent . tagName ) ;
38+
39+ const getProjectedSymbols = ( el : IgcRatingComponent ) =>
40+ el . renderRoot
41+ . querySelector < HTMLSlotElement > ( 'slot[name="symbol"]' )
42+ ?. assignedElements ( )
43+ . filter ( ( each ) =>
44+ each . matches ( IgcRatingSymbolComponent . tagName )
45+ ) as IgcRatingSymbolComponent [ ] ;
46+
4647 const getRatingWrapper = ( el : IgcRatingComponent ) =>
47- el . shadowRoot ! . querySelector ( `[part='base']` ) as HTMLElement ;
48- const fireMouseEvent = ( type : string , opts : MouseEventInit ) =>
49- new MouseEvent ( type , opts ) ;
48+ el . renderRoot . querySelector < HTMLElement > ( '[part="base"]' ) ! ;
49+
5050 const getBoundingRect = ( el : Element ) => el . getBoundingClientRect ( ) ;
51- let el : IgcRatingComponent ;
5251
5352 describe ( '' , ( ) => {
5453 beforeEach ( async ( ) => {
@@ -280,13 +279,8 @@ describe('Rating component', () => {
280279 const eventSpy = spy ( el , 'emitEvent' ) ;
281280 const symbol = getRatingSymbols ( el ) . item ( 2 ) ;
282281 const { x, width } = getBoundingRect ( symbol ) ;
283- symbol . dispatchEvent (
284- fireMouseEvent ( 'click' , {
285- bubbles : true ,
286- composed : true ,
287- clientX : x + width / 2 ,
288- } )
289- ) ;
282+ simulateClick ( symbol , { clientX : x + width / 2 } ) ;
283+
290284 expect ( eventSpy ) . calledOnceWithExactly ( 'igcChange' , { detail : 3 } ) ;
291285 expect ( el . value ) . to . equal ( 3 ) ;
292286 } ) ;
@@ -298,13 +292,8 @@ describe('Rating component', () => {
298292
299293 const symbol = getRatingSymbols ( el ) . item ( 2 ) ;
300294 const { x, width } = getBoundingRect ( symbol ) ;
301- symbol . dispatchEvent (
302- fireMouseEvent ( 'click' , {
303- bubbles : true ,
304- composed : true ,
305- clientX : x + width / 4 ,
306- } )
307- ) ;
295+ simulateClick ( symbol , { clientX : x + width / 4 } ) ;
296+
308297 expect ( eventSpy ) . calledOnceWithExactly ( 'igcChange' , { detail : 2.5 } ) ;
309298 expect ( el . value ) . to . equal ( 2.5 ) ;
310299 } ) ;
@@ -316,14 +305,8 @@ describe('Rating component', () => {
316305 await elementUpdated ( el ) ;
317306 const symbol = getRatingSymbols ( el ) . item ( 2 ) ;
318307 const { x, width } = getBoundingRect ( symbol ) ;
308+ simulatePointerMove ( symbol , { clientX : x + width / 2 } ) ;
319309
320- symbol . dispatchEvent (
321- fireMouseEvent ( 'mousemove' , {
322- bubbles : true ,
323- composed : true ,
324- clientX : x + width / 2 ,
325- } )
326- ) ;
327310 expect ( eventSpy ) . calledOnceWithExactly ( 'igcHover' , { detail : 3 } ) ;
328311 expect ( el . value ) . to . equal ( 2 ) ;
329312 } ) ;
@@ -335,14 +318,7 @@ describe('Rating component', () => {
335318
336319 el . value = 5 ;
337320 await elementUpdated ( el ) ;
338-
339- symbol . dispatchEvent (
340- fireMouseEvent ( 'click' , {
341- bubbles : true ,
342- composed : true ,
343- clientX : x + width / 2 ,
344- } )
345- ) ;
321+ simulateClick ( symbol , { clientX : x + width / 2 } ) ;
346322
347323 expect ( el . value ) . to . equal ( 5 ) ;
348324 expect ( eventSpy ) . not . to . be . called ;
@@ -357,13 +333,7 @@ describe('Rating component', () => {
357333 el . allowReset = true ;
358334 await elementUpdated ( el ) ;
359335
360- symbol . dispatchEvent (
361- fireMouseEvent ( 'click' , {
362- bubbles : true ,
363- composed : true ,
364- clientX : x + width / 2 ,
365- } )
366- ) ;
336+ simulateClick ( symbol , { clientX : x + width / 2 } ) ;
367337
368338 expect ( el . value ) . to . equal ( 0 ) ;
369339 expect ( eventSpy ) . to . have . been . calledOnceWith ( 'igcChange' , { detail : 0 } ) ;
0 commit comments