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

Add test for map action receiver (replaces old viewport store test) #180

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
44 changes: 44 additions & 0 deletions test/stores/MapActionReceiver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import MapActionReceiver from '@/stores/MapActionReceiver'
import { PathDetailsRangeSelected, RouteRequestSuccess, ZoomMapToPoint } from '@/actions/Actions'
import { createMap, getMap } from '@/map/map'

describe('MapActionReceiver', () => {
it('should update camera position correctly', () => {
const routeStore = {} as any
createMap()
const receiver = new MapActionReceiver(getMap(), routeStore, () => false)
{
// simply set to point
receiver.receive(new ZoomMapToPoint({ lng: 13, lat: 48 }, 11))
expect(getMap().getView().getCenter()![0]).toEqual(13)
expect(getMap().getView().getCenter()![1]).toEqual(13)
expect(getMap().getView().getZoom()).toEqual(13)
}
{
// set to route ...
const selectedPath = { bbox: [10.31, 50.73, 11.19, 51.31] }
routeStore.state = { selectedPath }
receiver.receive(
new RouteRequestSuccess(
null as any,
{
paths: [selectedPath],
} as any
)
)
expect(getMap().getView().getCenter()![0]).toBeCloseTo(10.5, 1)
expect(getMap().getView().getCenter()![1]).toBeCloseTo(50.9, 1)
expect(getMap().getView().getZoom()).toBeCloseTo(8.8, 1)
// ... select path details
receiver.receive(new PathDetailsRangeSelected([10.46, 50.88, 10.47, 50.9]))
expect(getMap().getView().getCenter()![0]).toBeCloseTo(10.46, 2)
expect(getMap().getView().getCenter()![1]).toBeCloseTo(50.89, 2)
expect(getMap().getView().getZoom()).toBeCloseTo(13.7, 1)
// ... deselect path details again -> we are back to the route bbox
receiver.receive(new PathDetailsRangeSelected(null))
expect(getMap().getView().getCenter()![0]).toBeCloseTo(10.5, 1)
expect(getMap().getView().getCenter()![1]).toBeCloseTo(50.9, 1)
expect(getMap().getView().getZoom()).toBeCloseTo(8.8, 1)
}
})
})