Skip to content

Commit

Permalink
debugging test
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed May 10, 2017
1 parent 02197b3 commit 27778ad
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/lib/core/ripple/ripple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ describe('MdRipple', () => {
rippleDirective = fixture.componentInstance.ripple;
});

it('sizes ripple to cover element', () => {
let elementRect = rippleTarget.getBoundingClientRect();

// Dispatch a ripple at the following relative coordinates (X: 50| Y: 75)
dispatchMouseEvent(rippleTarget, 'mousedown', 50, 75);
dispatchMouseEvent(rippleTarget, 'mouseup');

// Calculate distance from the click to farthest edge of the ripple target.
let maxDistanceX = TARGET_WIDTH - 50;
let maxDistanceY = TARGET_HEIGHT - 75;

// At this point the foreground ripple should be created with a div centered at the click
// location, and large enough to reach the furthest corner, which is 250px to the right
// and 125px down relative to the click position.
let expectedRadius = Math.sqrt(maxDistanceX * maxDistanceX + maxDistanceY * maxDistanceY);
let expectedLeft = elementRect.left + 50 - expectedRadius;
let expectedTop = elementRect.top + 75 - expectedRadius;

let ripple = rippleTarget.querySelector('.mat-ripple-element') as HTMLElement;

// Note: getBoundingClientRect won't work because there's a transform applied to make the
// ripple start out tiny.
expect(pxStringToFloat(ripple.style.left)).toBeCloseTo(expectedLeft, 1);
expect(pxStringToFloat(ripple.style.top)).toBeCloseTo(expectedTop, 1);
expect(pxStringToFloat(ripple.style.width)).toBeCloseTo(2 * expectedRadius, 1);
expect(pxStringToFloat(ripple.style.height)).toBeCloseTo(2 * expectedRadius, 1);
});

it('creates ripple on mousedown', () => {
dispatchMouseEvent(rippleTarget, 'mousedown');
dispatchMouseEvent(rippleTarget, 'mouseup');
Expand Down Expand Up @@ -137,35 +165,6 @@ describe('MdRipple', () => {
expect(parseFloat(rippleElement.style.top)).toBeCloseTo(TARGET_HEIGHT / 2 - radius, 1);
});

it('sizes ripple to cover element', () => {
let elementRect = rippleTarget.getBoundingClientRect();

// Dispatch a ripple at the following relative coordinates (X: 50| Y: 75)
dispatchMouseEvent(rippleTarget, 'mousedown', 50, 75);
dispatchMouseEvent(rippleTarget, 'mouseup');

// Calculate distance from the click to farthest edge of the ripple target.
let maxDistanceX = TARGET_WIDTH - 50;
let maxDistanceY = TARGET_HEIGHT - 75;

// At this point the foreground ripple should be created with a div centered at the click
// location, and large enough to reach the furthest corner, which is 250px to the right
// and 125px down relative to the click position.
let expectedRadius = Math.sqrt(maxDistanceX * maxDistanceX + maxDistanceY * maxDistanceY);
let expectedLeft = elementRect.left + 50 - expectedRadius;
let expectedTop = elementRect.top + 75 - expectedRadius;

let ripple = rippleTarget.querySelector('.mat-ripple-element') as HTMLElement;

// Note: getBoundingClientRect won't work because there's a transform applied to make the
// ripple start out tiny.
expect(pxStringToFloat(ripple.style.left)).toBeCloseTo(expectedLeft, 1);
expect(pxStringToFloat(ripple.style.top)).toBeCloseTo(expectedTop, 1);
expect(pxStringToFloat(ripple.style.width)).toBeCloseTo(2 * expectedRadius, 1);
expect(pxStringToFloat(ripple.style.height)).toBeCloseTo(2 * expectedRadius, 1);
});


it('cleans up the event handlers when the container gets destroyed', () => {
fixture = TestBed.createComponent(RippleContainerWithNgIf);
fixture.detectChanges();
Expand Down

0 comments on commit 27778ad

Please sign in to comment.