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 mouse_rotate.test.js #711

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
64 changes: 64 additions & 0 deletions src/ui/handler/mouse_rotate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {extend} from '../../util/util';
import Map from '../../ui/map';
import DOM from '../../util/dom';
import simulate from '../../../test/util/simulate_interaction';
import browser from '../../util/browser';
import {setMatchMedia, setPerformance, setWebGlContext} from '../../util/test/util';

function createMap(options?) {
return new Map(extend({container: DOM.create('div', '', window.document.body)}, options));
}

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

describe('mouse rotate', () => {
test('MouseRotateHandler#isActive', () => {
const map = createMap();
const mouseRotate = map.handlers._handlersById.mouseRotate;

// Prevent inertial rotation.
jest.spyOn(browser, 'now').mockReturnValue(0);
expect(mouseRotate.isActive()).toBe(false);

simulate.mousedown(map.getCanvas(), {buttons: 2, button: 2});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(false);

simulate.mousemove(map.getCanvas(), {buttons: 2, clientX: 10, clientY: 10});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(true);

simulate.mouseup(map.getCanvas(), {buttons: 0, button: 2});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(false);

map.remove();
});

test('MouseRotateHandler#isActive #4622 regression test', () => {
const map = createMap();
const mouseRotate = map.handlers._handlersById.mouseRotate;

// Prevent inertial rotation.
simulate.mousedown(map.getCanvas(), {buttons: 2, button: 2});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(false);

simulate.mousemove(map.getCanvas(), {buttons: 2, clientX: 10, clientY: 10});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(true);

// Some browsers don't fire mouseup when it happens outside the window.
// Make the handler in active when it encounters a mousemove without the button pressed.

simulate.mousemove(map.getCanvas(), {buttons: 0, clientX: 10, clientY: 10});
map._renderTaskQueue.run();
expect(mouseRotate.isActive()).toBe(false);

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

This file was deleted.