-
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
1 parent
87fb5e9
commit ea01eac
Showing
20 changed files
with
1,772 additions
and
1,037 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
1,022 changes: 0 additions & 1,022 deletions
1,022
src/components/common/graph/d3-graph-elevation.fixtures.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { describe, it, expect } from 'vitest' | ||
import ElevationProfile from './elevation-profile.vue' | ||
import D3GraphElevation from './d3-graph-elevation.vue' | ||
import { ProfileData } from './elevation-profile' | ||
|
||
describe('ElevationProfile', () => { | ||
it('Display an image when profileData is empty', () => { | ||
const wrapper = mount(ElevationProfile, { | ||
props: { | ||
profileData: undefined, | ||
}, | ||
}) | ||
|
||
expect(wrapper.find('img').exists()).toBe(true) | ||
expect(wrapper.findComponent(D3GraphElevation).exists()).toBe(false) | ||
}) | ||
|
||
it('Display the graph when profileData has values', () => { | ||
const profileData = <ProfileData>[ | ||
{ | ||
cumulativeElevation: 42, | ||
elevationGain: 58, | ||
elevationLoss: 2, | ||
}, | ||
{ | ||
cumulativeElevation: 250, | ||
elevationGain: 22, | ||
elevationLoss: 42, | ||
}, | ||
] | ||
const wrapper = mount(ElevationProfile, { | ||
props: { | ||
profileData, | ||
highlightDistance: 10, | ||
}, | ||
}) | ||
|
||
expect(wrapper.findComponent(D3GraphElevation).exists()).toBe(true) | ||
expect(wrapper.find('img').exists()).toBe(false) | ||
}) | ||
}) |
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
144 changes: 144 additions & 0 deletions
144
src/components/feature-elevation-profile/feature-elevation-profil.spec.ts
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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { nextTick } from 'vue' | ||
import { mount, shallowMount } from '@vue/test-utils' | ||
import { GlobalMountOptions } from '@vue/test-utils/dist/types' | ||
import { createTestingPinia } from '@pinia/testing' | ||
import { describe, it, expect, vi } from 'vitest' | ||
import { Coordinate } from 'ol/coordinate' | ||
|
||
import { dataset as datasetFixtures } from '@/__fixtures__/d3-graph-elevation.fixtures' | ||
import formatMeasureDirective from '@/directives/format-measure.directive' | ||
import { DrawnFeature } from '@/services/draw/drawn-feature' | ||
import FeatureElevationProfile from './feature-elevation-profile.vue' | ||
import { exportFeatureService } from '@/services/export-feature/export-feature.service' | ||
import { useProfilePositionStore } from '@/stores/profile-position.store' | ||
import ElevationProfile from '../common/graph/elevation-profile.vue' | ||
|
||
const global: GlobalMountOptions | undefined = { | ||
plugins: [formatMeasureDirective], | ||
} | ||
|
||
const mockedFeatureWithData = <DrawnFeature>(<unknown>{ | ||
getProfile: vi.fn(() => Promise.resolve(datasetFixtures)), | ||
profileData: undefined, | ||
map: { getView: () => ({ getProjection: () => 'EPSG:4326' }) }, | ||
label: 'Feature Label with data', | ||
}) | ||
|
||
const mockedFeatureNoData = <DrawnFeature>(<unknown>{ | ||
getProfile: vi.fn(() => new Promise(() => undefined)), | ||
profileData: undefined, | ||
map: {}, | ||
label: 'Feature Label with NO data', | ||
}) | ||
|
||
vi.mock('ol/proj', () => ({ | ||
transform: (coords: Coordinate) => coords, | ||
})) | ||
|
||
vi.mock('@/services/export-feature/export-feature.service', () => ({ | ||
exportFeatureService: { | ||
export: vi.fn(), | ||
}, | ||
})) | ||
|
||
vi.mock('@/composables/map/map.composable', () => ({ | ||
default: () => ({ | ||
getOlMap: () => ({ | ||
addLayer: vi.fn(), | ||
addFeatureLayer: vi.fn(), | ||
getView: () => ({ getProjection: vi.fn() }), | ||
}), | ||
}), | ||
PROJECTION_LUX: 'EPSG:2169', | ||
})) | ||
|
||
vi.mock('@/composables/map/profile-position.composable', () => ({ | ||
default: () => ({ | ||
constructProfileLine: vi.fn(), | ||
profileData: { value: undefined }, | ||
highlightDistance: { value: undefined }, | ||
}), | ||
})) | ||
|
||
describe('FeatureElevationProfile', () => { | ||
createTestingPinia({ | ||
createSpy: vi.fn, | ||
stubActions: false, | ||
initialState: { | ||
'profile-position': { | ||
x: 1, | ||
y: 2, | ||
}, | ||
}, | ||
}) | ||
|
||
it('Display elevation ,cumulation gain and loss according to profileData', async () => { | ||
const wrapper = shallowMount(FeatureElevationProfile, { | ||
props: { feature: mockedFeatureWithData }, | ||
global, | ||
}) | ||
|
||
await nextTick() // wait for execution of `onMounted` | ||
await nextTick() | ||
|
||
expect(wrapper.text()).toContain('Δ+699') | ||
expect(wrapper.text()).toContain('Δ-814') | ||
expect(wrapper.text()).toContain('-115') | ||
}) | ||
|
||
it('Display a waiting message when profileData is still loading', async () => { | ||
const wrapper = mount(FeatureElevationProfile, { | ||
props: { feature: mockedFeatureNoData }, | ||
global, | ||
}) | ||
|
||
expect(wrapper.text()).toContain('Please wait, the profile is loading.') | ||
}) | ||
|
||
it('Does not display a close button if there is no listerner for "onClose"', () => { | ||
const wrapper = mount(FeatureElevationProfile, { | ||
global, | ||
}) | ||
|
||
expect(wrapper.find('[aria-label="Close"]').exists()).toBe(false) | ||
}) | ||
|
||
it('Display a close button if there is a listerner for "onClose"', () => { | ||
const wrapper = mount(FeatureElevationProfile, { | ||
props: { | ||
onClose: () => alert('My listener on close'), | ||
feature: mockedFeatureNoData, | ||
}, | ||
global, | ||
}) | ||
|
||
expect(wrapper.find('[aria-label="Close"]').exists()).toBe(true) | ||
}) | ||
|
||
it("Call 'exportFeatureService.export' when on click export csv button", async () => { | ||
const wrapper = shallowMount(FeatureElevationProfile, { | ||
props: { feature: mockedFeatureWithData }, | ||
global, | ||
}) | ||
|
||
await nextTick() | ||
await wrapper.find('[data-cy="featItemProfileCSV"]').trigger('click') | ||
|
||
expect(exportFeatureService.export).toHaveBeenCalled() | ||
}) | ||
|
||
it("Update 'profilePositionStore' when hovering the graph", async () => { | ||
const profilePositionStore = useProfilePositionStore() | ||
const wrapper = mount(FeatureElevationProfile, { | ||
props: { feature: mockedFeatureWithData }, | ||
global, | ||
}) | ||
|
||
await nextTick() | ||
|
||
const elevationProfile = wrapper.findComponent(ElevationProfile) | ||
elevationProfile.vm.$emit('hover:profile', { x: 10, y: 20 }) | ||
|
||
expect(profilePositionStore.setPosition).toHaveBeenCalledWith(10, 20) | ||
}) | ||
}) |
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
Oops, something went wrong.