Skip to content

feat(material-experimental/mdc-slider): implement some basic unit tests #22072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cdk/testing/testbed/fake-events/dispatch-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function dispatchPointerEvent(node: Node, type: string, clientX = 0, clie
* Shorthand to dispatch a touch event on the specified coordinates.
* @docs-private
*/
export function dispatchTouchEvent(node: Node, type: string, x = 0, y = 0) {
return dispatchEvent(node, createTouchEvent(type, x, y));
export function dispatchTouchEvent(node: Node, type: string, pageX = 0, pageY = 0, clientX = 0,
clientY = 0) {
return dispatchEvent(node, createTouchEvent(type, pageX, pageY, clientX, clientY));
}
4 changes: 2 additions & 2 deletions src/cdk/testing/testbed/fake-events/event-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export function createPointerEvent(type: string, clientX = 0, clientY = 0,
* Creates a browser TouchEvent with the specified pointer coordinates.
* @docs-private
*/
export function createTouchEvent(type: string, pageX = 0, pageY = 0) {
export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0, clientY = 0) {
// In favor of creating events that work for most of the browsers, the event is created
// as a basic UI Event. The necessary details for the event will be set manually.
const event = document.createEvent('UIEvent');
const touchDetails = {pageX, pageY};
const touchDetails = {pageX, pageY, clientX, clientY};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mdc-slider checks the clientX and clientY of the targetTouches[0] when calculating the new value of the slider.

https://github.com/material-components/material-components-web/blob/master/packages/mdc-slider/foundation.ts#L372-L374


// TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
(event as any).initUIEvent(type, true, true, window, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/material-experimental/mdc-slider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ ng_test_library(
"//src/cdk/keycodes",
"//src/cdk/platform",
"//src/cdk/testing/private",
"//src/material/core",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
"@npm//@material/slider",
],
)

Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-slider/slider-thumb.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
</div>
</div>
<div class="mdc-slider__thumb-knob" #knob></div>
<div matRipple></div>
<div matRipple [matRippleDisabled]="true"></div>
Loading