-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
100 deletions.
There are no files selected for viewing
100 changes: 0 additions & 100 deletions
100
projects/cdk/directives/zoom/test/zoom.directive.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import {Component} from '@angular/core'; | ||
import {tuiFloor, TuiZoom, TuiZoomModule} from '@taiga-ui/cdk'; | ||
import {TuiRootModule} from '@taiga-ui/core'; | ||
|
||
describe('TuiZoom', () => { | ||
let component: TestComponent; | ||
|
||
@Component({ | ||
template: ` | ||
<tui-root> | ||
<section (tuiZoom)="onZoom($event)"></section> | ||
</tui-root> | ||
`, | ||
}) | ||
class TestComponent { | ||
scale = 1; | ||
|
||
onZoom({delta}: TuiZoom): void { | ||
this.scale -= delta; | ||
} | ||
} | ||
|
||
beforeEach(() => | ||
cy | ||
.mount(TestComponent, { | ||
imports: [TuiRootModule, TuiZoomModule], | ||
}) | ||
.then(wrapper => { | ||
component = wrapper.component; | ||
}), | ||
); | ||
|
||
it('pinch', () => { | ||
cy.get('section') | ||
.then(query => { | ||
const element = query.get(0); | ||
|
||
sendTouchEvent([10, 10], [20, 20], element, 'touchstart'); | ||
sendTouchEvent([5, 5], [25, 25], element, 'touchmove'); | ||
sendTouchEvent([5, 5], [25, 25], element, 'touchend'); | ||
}) | ||
.then(() => expect(tuiFloor(component.scale, 2)).to.eql(0.85)); | ||
}); | ||
|
||
it('wheel', () => { | ||
cy.get('section') | ||
.then(query => { | ||
const element = query.get(0); | ||
const wheel = new WheelEvent('wheel', {deltaY: 1.1}); | ||
|
||
element.dispatchEvent(wheel); | ||
}) | ||
.then(() => expect(tuiFloor(component.scale, 2)).to.eql(1.01)); | ||
}); | ||
}); | ||
|
||
function sendTouchEvent( | ||
[x, y]: [number, number], | ||
[x2, y2]: [number, number], | ||
element: HTMLElement, | ||
eventType: 'touchend' | 'touchmove' | 'touchstart', | ||
): void { | ||
const touchObj1 = new Touch({ | ||
identifier: Date.now(), | ||
target: element, | ||
clientX: x, | ||
clientY: y, | ||
radiusX: 2.5, | ||
radiusY: 2.5, | ||
rotationAngle: 10, | ||
force: 0.5, | ||
}); | ||
|
||
const touchObj2 = new Touch({ | ||
identifier: Date.now(), | ||
target: element, | ||
clientX: x2, | ||
clientY: y2, | ||
radiusX: 2.5, | ||
radiusY: 2.5, | ||
rotationAngle: 10, | ||
force: 0.5, | ||
}); | ||
|
||
const touchEvent = new TouchEvent(eventType, { | ||
cancelable: true, | ||
bubbles: true, | ||
touches: [touchObj1, touchObj2], | ||
targetTouches: [], | ||
changedTouches: [touchObj1, touchObj2], | ||
shiftKey: true, | ||
}); | ||
|
||
element.dispatchEvent(touchEvent); | ||
} |