Skip to content

Commit cbc9ca0

Browse files
authored
feat(material-experimental/mdc-slider): implement some basic unit tests (#22072)
* feat(material-experimental/mdc-slider): implement some basic unit tests * implement unit tests for the standard slider, standard range slider, and for the slider ripple states * add mdc-slider theme to all-theme * use #waitForAsync to wait for foundation to finish initializing & layout * use forwardRef to avoid injection errors that only throw on ci * disable the mat ripple on the slider thumbs to prevent the automatic launch that happens on click/touch the problem is easily reproduced if you undo this change and test it out on a mobile device. * note: we use touch events instead of pointer events when testing on ios because pointerdown, pointerup, and pointermove are not supported
1 parent f2fdca9 commit cbc9ca0

File tree

7 files changed

+375
-15
lines changed

7 files changed

+375
-15
lines changed

src/cdk/testing/testbed/fake-events/dispatch-events.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function dispatchPointerEvent(node: Node, type: string, clientX = 0, clie
6565
* Shorthand to dispatch a touch event on the specified coordinates.
6666
* @docs-private
6767
*/
68-
export function dispatchTouchEvent(node: Node, type: string, x = 0, y = 0) {
69-
return dispatchEvent(node, createTouchEvent(type, x, y));
68+
export function dispatchTouchEvent(node: Node, type: string, pageX = 0, pageY = 0, clientX = 0,
69+
clientY = 0) {
70+
return dispatchEvent(node, createTouchEvent(type, pageX, pageY, clientX, clientY));
7071
}

src/cdk/testing/testbed/fake-events/event-objects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export function createPointerEvent(type: string, clientX = 0, clientY = 0,
7979
* Creates a browser TouchEvent with the specified pointer coordinates.
8080
* @docs-private
8181
*/
82-
export function createTouchEvent(type: string, pageX = 0, pageY = 0) {
82+
export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0, clientY = 0) {
8383
// In favor of creating events that work for most of the browsers, the event is created
8484
// as a basic UI Event. The necessary details for the event will be set manually.
8585
const event = document.createEvent('UIEvent');
86-
const touchDetails = {pageX, pageY};
86+
const touchDetails = {pageX, pageY, clientX, clientY};
8787

8888
// TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
8989
(event as any).initUIEvent(type, true, true, window, 0);

src/material-experimental/mdc-slider/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ ng_test_library(
7575
"//src/cdk/keycodes",
7676
"//src/cdk/platform",
7777
"//src/cdk/testing/private",
78+
"//src/material/core",
7879
"@npm//@angular/forms",
7980
"@npm//@angular/platform-browser",
81+
"@npm//@material/slider",
8082
],
8183
)
8284

src/material-experimental/mdc-slider/slider-thumb.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
</div>
55
</div>
66
<div class="mdc-slider__thumb-knob" #knob></div>
7-
<div matRipple></div>
7+
<div matRipple [matRippleDisabled]="true"></div>

0 commit comments

Comments
 (0)