-
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
97 deletions.
There are no files selected for viewing
97 changes: 0 additions & 97 deletions
97
projects/cdk/directives/swipe/test/swipe.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 {TuiSwipe, TuiSwipeModule} from '@taiga-ui/cdk'; | ||
import {TuiRootModule} from '@taiga-ui/core'; | ||
|
||
describe('TuiSwipe', () => { | ||
let component: TestComponent; | ||
|
||
@Component({ | ||
template: ` | ||
<tui-root> | ||
<section (tuiSwipe)="onSwipe($event)"></section> | ||
</tui-root> | ||
`, | ||
}) | ||
class TestComponent { | ||
swiped = ''; | ||
|
||
onSwipe(swipe: TuiSwipe): void { | ||
this.swiped = swipe.direction; | ||
} | ||
} | ||
|
||
beforeEach(() => | ||
cy | ||
.mount(TestComponent, { | ||
imports: [TuiRootModule, TuiSwipeModule], | ||
}) | ||
.then(wrapper => { | ||
component = wrapper.component; | ||
}), | ||
); | ||
|
||
it('emits events bottom', () => { | ||
cy.get('section') | ||
.then(query => { | ||
const element = query.get(0); | ||
|
||
sendTouchEvent(0, 0, element, 'touchstart', 1); | ||
sendTouchEvent(0, 100, element, 'touchend', 1); | ||
}) | ||
.then(() => expect(component.swiped).to.eql('bottom')); | ||
}); | ||
|
||
it('emits events right', () => { | ||
cy.get('section') | ||
.then(query => { | ||
const element = query.get(0); | ||
|
||
sendTouchEvent(0, 0, element, 'touchstart', 1); | ||
sendTouchEvent(100, 0, element, 'touchend', 1); | ||
}) | ||
.then(() => expect(component.swiped).to.eql('right')); | ||
}); | ||
|
||
it('does not emit events due to threshold', () => { | ||
cy.get('section') | ||
.then(query => { | ||
const element = query.get(0); | ||
|
||
sendTouchEvent(0, 0, element, 'touchstart', 1); | ||
sendTouchEvent(0, 20, element, 'touchend', 1); | ||
}) | ||
.then(() => expect(component.swiped).to.eql('')); | ||
}); | ||
}); | ||
|
||
function sendTouchEvent( | ||
x: number, | ||
y: number, | ||
element: HTMLElement, | ||
eventType: 'touchend' | 'touchstart', | ||
identifier: number, | ||
): void { | ||
const touchObj = new Touch({ | ||
identifier, | ||
target: element, | ||
clientX: x, | ||
clientY: y, | ||
radiusX: 2.5, | ||
radiusY: 2.5, | ||
rotationAngle: 10, | ||
force: 0.5, | ||
}); | ||
|
||
const touchEvent = new TouchEvent(eventType, { | ||
cancelable: true, | ||
bubbles: true, | ||
touches: [touchObj], | ||
targetTouches: [], | ||
changedTouches: [touchObj], | ||
shiftKey: true, | ||
}); | ||
|
||
element.dispatchEvent(touchEvent); | ||
} |