-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import { describe, it, expect, beforeEach, vi } from 'vitest' | ||
import { TeritorioCluster } from '../src/teritorio-cluster' | ||
import { Map as MapGL } from 'maplibre-gl' | ||
import { getFeatureId } from '../src/utils/get-feature-id'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import { TeritorioCluster } from '../src/teritorio-cluster' | ||
import { getFeatureId } from '../src/utils/get-feature-id' | ||
|
||
vi.mock('../src/utils/get-feature-id', () => ({ | ||
getFeatureId: vi.fn(), | ||
})); | ||
})) | ||
|
||
describe('setSelectedFeature', () => { | ||
let map: MapGL | ||
let teritorioCluster: TeritorioCluster | ||
|
||
beforeEach(() => { | ||
map = new MapGL({ container: 'map'}) | ||
map = new MapGL({ container: 'map' }) | ||
teritorioCluster = new TeritorioCluster(map, 'sourceId') | ||
}) | ||
|
||
it('should render pin marker when feature is not found and is a Point', () => { | ||
const feature = { | ||
type: 'Feature', | ||
geometry: { type: 'Point', coordinates: [10, 20] }, | ||
properties: null | ||
properties: null, | ||
} satisfies GeoJSON.Feature | ||
|
||
vi.mocked(getFeatureId).mockReturnValue('some-unique-id') | ||
|
||
teritorioCluster.setSelectedFeature(feature); | ||
teritorioCluster.setSelectedFeature(feature) | ||
|
||
expect(teritorioCluster.selectedFeatureId).toBe('some-unique-id'); | ||
expect(teritorioCluster.pinMarker?.setLngLat).toHaveBeenCalledWith([10, 20]); | ||
expect(teritorioCluster.pinMarker?.addTo).toHaveBeenCalledWith(map); | ||
}); | ||
expect(teritorioCluster.selectedFeatureId).toBe('some-unique-id') | ||
expect(teritorioCluster.pinMarker?.setLngLat).toHaveBeenCalledWith([10, 20]) | ||
expect(teritorioCluster.pinMarker?.addTo).toHaveBeenCalledWith(map) | ||
}) | ||
|
||
it('should log an error if feature is not a Point and not found', () => { | ||
const feature = { | ||
type: 'Feature', | ||
geometry: { type: 'Polygon', coordinates: [[[]]] }, | ||
properties: null | ||
properties: null, | ||
} satisfies GeoJSON.Feature | ||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
vi.mocked(getFeatureId).mockReturnValue('some-unique-id') | ||
|
||
teritorioCluster.setSelectedFeature(feature); | ||
teritorioCluster.setSelectedFeature(feature) | ||
|
||
expect(consoleErrorSpy).toHaveBeenCalledWith('Feature some-unique-id is not of type \'Point\', and is not supported.'); | ||
}); | ||
}) | ||
expect(consoleErrorSpy).toHaveBeenCalledWith('Feature some-unique-id is not of type \'Point\', and is not supported.') | ||
}) | ||
}) |