Add app unit tests using vitest (#14583)

* Install / bootstrap vitest

* Install c8

* Add tests for add-query-to-path

* Don't set global maplibre token on individual style

This feels wrong to me. We have a single global access token that should be used for these things. Overriding that with a token that's found for individual styles on top of the same global object in order of configured maps feels weird, as the latter tokens will override the earlier ones. Needs more research though

* Install testing libraries

* Use happy-dom as env in vitest

* Enable ts checking in tests

* Remove unused jest config

* Organize store imports

* Remove types from TSDoc in add-query-to-path

* Improve check in add-related-primary-key-to-fields

* Add reusable stub for anything touching nanoid

* Add tests for add-related-primary-key-to-fields

* Move adjust date to shared

* Remove arraysAreEqual util in favor of relying on lodash

* Fix add-related-primary-key-to-fields test

* Add test coverage for capitlize-first

* Add TSDoc/tests for extract-field-from-function

* Add test coverage for formatFieldFunction

* Add test coverage for format-filesize

* Add test coverage for get-groups

* Add tests for get-root-path

* cleanup imports

* Move tests to live next to source files

* Add tests for user-name

* Update type to match function behavior

* Add test coverage for point-on-line

* Add tests for is-empty

* Add test coverage for is-hex

* Remove getSetting util

Bit pointless to have a util function to just read a value from a store

* Add test coverage for get-related-collection

* Add test coverage for get-theme

* Add test coverage for get-with-arrays

* Add test coverage for hide-drag-image

* Add test coverage for is-permission-empty

* Remove unused import

* Add test for jwt-payload

* Add snapshot rendering test for v-sheet

* Add whitespace

* Rename __test_utils__ -> __utils__

* Add composable test

* Update app/tsconfig.json

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Rijk van Zanten
2022-07-25 16:23:45 -04:00
committed by GitHub
parent 515ea4e4d2
commit 88c5edf7a3
64 changed files with 1309 additions and 374 deletions

View File

@@ -62,38 +62,39 @@
</template>
<script lang="ts">
import 'maplibre-gl/dist/maplibre-gl.css';
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
import { defineComponent, onMounted, onUnmounted, PropType, ref, watch, toRefs, computed } from 'vue';
import maplibre, {
LngLatLike,
LngLatBoundsLike,
AnimationOptions,
AttributionControl,
CameraOptions,
GeolocateControl,
LngLatBoundsLike,
LngLatLike,
Map,
NavigationControl,
GeolocateControl,
AttributionControl,
} from 'maplibre-gl';
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import 'maplibre-gl/dist/maplibre-gl.css';
import { computed, defineComponent, onMounted, onUnmounted, PropType, ref, toRefs, watch } from 'vue';
import { useSettingsStore } from '@/stores/settings';
import { flatten, getBBox, getGeometryFormatForType, getParser, getSerializer } from '@/utils/geometry';
import { ButtonControl } from '@/utils/geometry/controls';
import {
Field,
GeoJSONParser,
GeoJSONSerializer,
GeometryType,
MultiGeometry,
SimpleGeometry,
} from '@directus/shared/types';
// @ts-ignore
import StaticMode from '@mapbox/mapbox-gl-draw-static-mode';
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';
import '@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css';
import { ButtonControl } from '@/utils/geometry/controls';
import { Geometry } from 'geojson';
import { flatten, getBBox, getParser, getSerializer, getGeometryFormatForType } from '@/utils/geometry';
import {
Field,
GeometryType,
GeoJSONParser,
GeoJSONSerializer,
SimpleGeometry,
MultiGeometry,
} from '@directus/shared/types';
import { getSetting } from '@/utils/get-setting';
import { snakeCase, isEqual, debounce } from 'lodash';
import { debounce, isEqual, snakeCase } from 'lodash';
import { getMapStyle } from './style';
const activeLayers = [
'directus-point',
'directus-line',
@@ -103,9 +104,8 @@ const activeLayers = [
'directus-polygon-and-line-vertex',
].flatMap((name) => [name + '.hot', name + '.cold']);
import { useI18n } from 'vue-i18n';
import { TranslateResult } from 'vue-i18n';
import { useAppStore } from '@/stores/app';
import { TranslateResult, useI18n } from 'vue-i18n';
import { getBasemapSources, getStyleFromBasemapSource } from '@/utils/geometry/basemap';
@@ -154,7 +154,9 @@ export default defineComponent({
const geometryType = props.geometryType || (props.fieldData?.type.split('.')[1] as GeometryType);
const geometryFormat = getGeometryFormatForType(props.type)!;
const mapboxKey = getSetting('mapbox_key');
const settingsStore = useSettingsStore();
const mapboxKey = settingsStore.settings?.mapbox_key;
const basemaps = getBasemapSources();
const appStore = useAppStore();
const { basemap } = toRefs(appStore);

View File

@@ -25,7 +25,7 @@ import { getBasemapSources, getStyleFromBasemapSource } from '@/utils/geometry/b
import 'maplibre-gl/dist/maplibre-gl.css';
import { Map, CameraOptions } from 'maplibre-gl';
import { useAppStore } from '@/stores/app';
import { getSetting } from '@/utils/get-setting';
import { useSettingsStore } from '@/stores/settings';
export default defineComponent({
props: {
@@ -50,6 +50,8 @@ export default defineComponent({
const geometryType = ref<GeometryType>(nativeGeometryType.value ?? props.value?.geometryType ?? 'Point');
const defaultView = ref<CameraOptions | undefined>(props.value?.defaultView);
const settingsStore = useSettingsStore();
watch(() => props.field?.type, watchType);
watch(nativeGeometryType, watchNativeType);
watch([geometryType, defaultView], input, { immediate: true });
@@ -72,7 +74,7 @@ export default defineComponent({
const mapContainer = ref<HTMLElement | null>(null);
let map: Map;
const mapboxKey = getSetting('mapbox_key');
const mapboxKey = settingsStore.settings?.mapbox_key;
const basemaps = getBasemapSources();
const appStore = useAppStore();
const { basemap } = toRefs(appStore);