Skip to content

Commit

Permalink
chore: add pan.cy.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jan 31, 2024
1 parent d6a3720 commit 56d9976
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 80 deletions.
80 changes: 0 additions & 80 deletions projects/cdk/directives/pan/test/pan.directive.spec.ts

This file was deleted.

74 changes: 74 additions & 0 deletions projects/demo-cypress/src/tests/pan.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {Component} from '@angular/core';
import {TuiPanModule} from '@taiga-ui/cdk';
import {TuiRootModule} from '@taiga-ui/core';

describe('TuiPan', () => {
let component: TestComponent;

@Component({
template: `
<tui-root>
<section (tuiPan)="pan($event)"></section>
</tui-root>
`,
})
class TestComponent {
coords: readonly number[] = [0, 0];

pan(delta: readonly [number, number]): void {
this.coords = delta;
}
}

beforeEach(() =>
cy
.mount(TestComponent, {
imports: [TuiRootModule, TuiPanModule],
})
.then(wrapper => {
component = wrapper.component;
}),
);

it('emits delta', () => {
cy.get('section')
.then(query => {
const element = query.get(0);

sendTouchEvent(0, 0, element, 'touchstart');
sendTouchEvent(0, 0, element, 'touchmove');
sendTouchEvent(0, 20, element, 'touchmove');
sendTouchEvent(0, 20, element, 'touchend');
})
.then(() => expect(component.coords).to.include.members([0, 20]));
});
});

function sendTouchEvent(
x: number,
y: number,
element: HTMLElement,
eventType: 'touchend' | 'touchmove' | 'touchstart',
): void {
const touchObj = new Touch({
identifier: Date.now(),
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);
}

0 comments on commit 56d9976

Please sign in to comment.