@@ -2,6 +2,13 @@ import { expect, test } from '../../test/playwright/index.js';
22import type { Slider } from './slider.js' ;
33import { SliderSize } from './slider.options.js' ;
44
5+ interface BoundingBox {
6+ x : number ;
7+ y : number ;
8+ width : number ;
9+ height : number ;
10+ }
11+
512test . describe ( 'Slider' , ( ) => {
613 test . use ( {
714 tagName : 'fluent-slider' ,
@@ -631,4 +638,78 @@ test.describe('Slider', () => {
631638 await expect ( wasChanged ) . resolves . toEqual ( true ) ;
632639 } ) ;
633640 } ) ;
641+
642+ test . describe ( 'thumb position' , ( ) => {
643+ test ( 'should follow pointer event coordinates in horizontal orientation' , async ( { fastPage, page } ) => {
644+ const { element } = fastPage ;
645+
646+ const track = element . locator ( '.track' ) ;
647+ const thumb = element . locator ( '.thumb-container' ) ;
648+ const trackBox = ( await track . boundingBox ( ) ) as BoundingBox ;
649+
650+ expect ( trackBox ) . not . toBeNull ( ) ;
651+
652+ let thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
653+ expect ( thumbBox ) . not . toBeNull ( ) ;
654+
655+ const thumbCenterX = thumbBox . x + thumbBox . width / 2 ;
656+ const thumbCenterY = thumbBox . y + thumbBox . height / 2 ;
657+ const thumbMoveToX = thumbCenterX - trackBox . width * 0.1 ;
658+ await page . mouse . move ( thumbCenterX , thumbCenterY ) ;
659+ await page . mouse . down ( ) ;
660+
661+ thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
662+ expect ( thumbBox ) . not . toBeNull ( ) ;
663+ expect ( thumbBox . x + thumbBox . width / 2 ) . toBeCloseTo ( thumbCenterX ) ;
664+ expect ( thumbBox . y + thumbBox . height / 2 ) . toBeCloseTo ( thumbCenterY ) ;
665+
666+ await page . mouse . move ( thumbMoveToX , thumbCenterY ) ;
667+ await page . mouse . up ( ) ;
668+ const thumbHandle = await thumb . elementHandle ( ) ;
669+ await thumbHandle ?. waitForElementState ( 'stable' ) ;
670+
671+ thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
672+ expect ( thumbBox ) . not . toBeNull ( ) ;
673+ expect ( thumbBox . x + thumbBox . width / 2 ) . toBeCloseTo ( thumbMoveToX ) ;
674+ expect ( thumbBox . y + thumbBox . height / 2 ) . toBeCloseTo ( thumbCenterY ) ;
675+ } ) ;
676+
677+ test ( 'should follow pointer event coordinates in vertical orientation' , async ( { fastPage, page } ) => {
678+ const { element } = fastPage ;
679+ await fastPage . setTemplate ( { attributes : { orientation : 'vertical' } } ) ;
680+ const elementBox = ( await element . boundingBox ( ) ) as BoundingBox ;
681+
682+ expect ( elementBox . width ) . toBeLessThan ( elementBox . height ) ;
683+
684+ const track = element . locator ( '.track' ) ;
685+ const thumb = element . locator ( '.thumb-container' ) ;
686+ const trackBox = ( await track . boundingBox ( ) ) as BoundingBox ;
687+
688+ expect ( trackBox ) . not . toBeNull ( ) ;
689+
690+ let thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
691+ expect ( thumbBox ) . not . toBeNull ( ) ;
692+
693+ const thumbCenterX = thumbBox . x + thumbBox . width / 2 ;
694+ const thumbCenterY = thumbBox . y + thumbBox . height / 2 ;
695+ const thumbMoveToY = thumbCenterY - trackBox . height * 0.3 ;
696+ await page . mouse . move ( thumbCenterX , thumbCenterY ) ;
697+ await page . mouse . down ( ) ;
698+
699+ thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
700+ expect ( thumbBox ) . not . toBeNull ( ) ;
701+ expect ( thumbBox . x + thumbBox . width / 2 ) . toBeCloseTo ( thumbCenterX ) ;
702+ expect ( thumbBox . y + thumbBox . height / 2 ) . toBeCloseTo ( thumbCenterY ) ;
703+
704+ await page . mouse . move ( thumbCenterX , thumbMoveToY ) ;
705+ await page . mouse . up ( ) ;
706+ const thumbHandle = await thumb . elementHandle ( ) ;
707+ await thumbHandle ?. waitForElementState ( 'stable' ) ;
708+
709+ thumbBox = ( await thumb . boundingBox ( ) ) as BoundingBox ;
710+ expect ( thumbBox ) . not . toBeNull ( ) ;
711+ expect ( thumbBox . x + thumbBox . width / 2 ) . toBeCloseTo ( thumbCenterX ) ;
712+ expect ( thumbBox . y + thumbBox . height / 2 ) . toBeCloseTo ( thumbMoveToY ) ;
713+ } ) ;
714+ } ) ;
634715} ) ;
0 commit comments