Skip to content
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

[Jest] Migrate map_event.test.js #710

Merged
merged 5 commits into from
Dec 11, 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
96 changes: 96 additions & 0 deletions src/ui/handler/map_event.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import Map, {MapOptions} from '../map';
import DOM from '../../util/dom';
import simulate from '../../../test/util/simulate_interaction';
import {setMatchMedia, setPerformance, setWebGlContext} from '../../util/test/util';

function createMap() {
return new Map({interactive: false, container: DOM.create('div', '', window.document.body)} as any as MapOptions);
}

beforeEach(() => {
setPerformance();
setWebGlContext();
setMatchMedia();
});

describe('map events', () => {
test('MapEvent handler fires touch events with correct values', () => {
const map = createMap();
const target = map.getCanvas();

const touchstart = jest.fn();
const touchmove = jest.fn();
const touchend = jest.fn();

map.on('touchstart', touchstart);
map.on('touchmove', touchmove);
map.on('touchend', touchend);

const touchesStart = [{target, identifier: 1, clientX: 0, clientY: 50}];
const touchesMove = [{target, identifier: 1, clientX: 0, clientY: 60}];
const touchesEnd = [{target, identifier: 1, clientX: 0, clientY: 60}];

simulate.touchstart(map.getCanvas(), {touches: touchesStart, targetTouches: touchesStart});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchstart.mock.calls[0][0].point).toEqual({x: 0, y: 50});
expect(touchmove).toHaveBeenCalledTimes(0);
expect(touchend).toHaveBeenCalledTimes(0);

simulate.touchmove(map.getCanvas(), {touches: touchesMove, targetTouches: touchesMove});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchmove).toHaveBeenCalledTimes(1);
expect(touchmove.mock.calls[0][0].point).toEqual({x: 0, y: 60});
expect(touchend).toHaveBeenCalledTimes(0);

simulate.touchend(map.getCanvas(), {touches: [], targetTouches: [], changedTouches: touchesEnd});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchmove).toHaveBeenCalledTimes(1);
expect(touchend).toHaveBeenCalledTimes(1);
expect(touchend.mock.calls[0][0].point).toEqual({x: 0, y: 60});

map.remove();
});

test('MapEvent handler fires touchmove even while drag handler is active', () => {
const map = createMap();
const target = map.getCanvas();
map.dragPan.enable();

const touchstart = jest.fn();
const touchmove = jest.fn();
const touchend = jest.fn();
const drag = jest.fn();

map.on('touchstart', touchstart);
map.on('touchmove', touchmove);
map.on('touchend', touchend);
map.on('drag', drag);

const touchesStart = [{target, identifier: 1, clientX: 0, clientY: 50}];
const touchesMove = [{target, identifier: 1, clientX: 0, clientY: 60}];
const touchesEnd = [{target, identifier: 1, clientX: 0, clientY: 60}];

simulate.touchstart(map.getCanvas(), {touches: touchesStart, targetTouches: touchesStart});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchstart.mock.calls[0][0].point).toEqual({x: 0, y: 50});
expect(touchmove).toHaveBeenCalledTimes(0);
expect(touchend).toHaveBeenCalledTimes(0);

simulate.touchmove(map.getCanvas(), {touches: touchesMove, targetTouches: touchesMove});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchmove).toHaveBeenCalledTimes(1);
expect(touchmove.mock.calls[0][0].point).toEqual({x: 0, y: 60});
expect(touchend).toHaveBeenCalledTimes(0);

simulate.touchend(map.getCanvas(), {touches: [], targetTouches: [], changedTouches: touchesEnd});
expect(touchstart).toHaveBeenCalledTimes(1);
expect(touchmove).toHaveBeenCalledTimes(1);
expect(touchend).toHaveBeenCalledTimes(1);
expect(touchend.mock.calls[0][0].point).toEqual({x: 0, y: 60});

map._renderTaskQueue.run();
expect(drag).toHaveBeenCalledTimes(1);

map.remove();
});
});
91 changes: 0 additions & 91 deletions test/unit/ui/handler/map_event.test.js

This file was deleted.