|
| 1 | +// eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 2 | +// @ts-nocheck |
| 3 | +import {test, expect, vi, describe, createMap} from '../../../util/vitest'; |
| 4 | +import NavigationControl from '../../../../src/ui/control/navigation_control'; |
| 5 | +import simulate from '../../../util/simulate_interaction'; |
| 6 | + |
| 7 | +describe('NavigationControl', () => { |
| 8 | + describe('compass drag', () => { |
| 9 | + test('mouse drag on compass updates bearing', () => { |
| 10 | + const map = createMap({interactive: true}); |
| 11 | + const nav = new NavigationControl({showCompass: true}); |
| 12 | + map.addControl(nav); |
| 13 | + |
| 14 | + const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass'); |
| 15 | + expect(compass).toBeTruthy(); |
| 16 | + |
| 17 | + const setBearingSpy = vi.spyOn(map, 'setBearing'); |
| 18 | + |
| 19 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 20 | + simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0}); |
| 21 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 22 | + simulate.mousemove(window.document, {buttons: 1, clientX: 10, clientY: 0}); |
| 23 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 24 | + simulate.mouseup(window.document, {button: 0, buttons: 0}); |
| 25 | + |
| 26 | + expect(setBearingSpy).toHaveBeenCalled(); |
| 27 | + |
| 28 | + map.remove(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('mouse drag on compass updates pitch when visualizePitch is enabled', () => { |
| 32 | + const map = createMap({interactive: true}); |
| 33 | + const nav = new NavigationControl({showCompass: true, visualizePitch: true}); |
| 34 | + map.addControl(nav); |
| 35 | + |
| 36 | + const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass'); |
| 37 | + expect(compass).toBeTruthy(); |
| 38 | + |
| 39 | + const setPitchSpy = vi.spyOn(map, 'setPitch'); |
| 40 | + |
| 41 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 42 | + simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0}); |
| 43 | + // Vertical movement to change pitch |
| 44 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 45 | + simulate.mousemove(window.document, {buttons: 1, clientX: 0, clientY: -10}); |
| 46 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 47 | + simulate.mouseup(window.document, {button: 0, buttons: 0}); |
| 48 | + |
| 49 | + expect(setPitchSpy).toHaveBeenCalled(); |
| 50 | + |
| 51 | + map.remove(); |
| 52 | + }); |
| 53 | + |
| 54 | + test('mouse drag on compass does not update pitch when visualizePitch is disabled', () => { |
| 55 | + const map = createMap({interactive: true}); |
| 56 | + const nav = new NavigationControl({showCompass: true, visualizePitch: false}); |
| 57 | + map.addControl(nav); |
| 58 | + |
| 59 | + const compass = map.getContainer().querySelector('.mapboxgl-ctrl-compass'); |
| 60 | + expect(compass).toBeTruthy(); |
| 61 | + |
| 62 | + const setPitchSpy = vi.spyOn(map, 'setPitch'); |
| 63 | + |
| 64 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 65 | + simulate.mousedown(compass, {button: 0, buttons: 1, clientX: 0, clientY: 0}); |
| 66 | + // Vertical movement |
| 67 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 68 | + simulate.mousemove(window.document, {buttons: 1, clientX: 0, clientY: -10}); |
| 69 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-call |
| 70 | + simulate.mouseup(window.document, {button: 0, buttons: 0}); |
| 71 | + |
| 72 | + expect(setPitchSpy).not.toHaveBeenCalled(); |
| 73 | + |
| 74 | + map.remove(); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments