浏览代码

minor fixes and tests skeletton

Olivier Massot 4 年之前
父节点
当前提交
f02ca7420f
共有 5 个文件被更改,包括 41 次插入46 次删除
  1. 24 1
      components/Ui/Search/Address.vue
  2. 0 33
      components/Ui/Search/Text.vue
  3. 3 1
      jest.config.js
  4. 14 2
      pages/structures_adherentes/index.vue
  5. 0 9
      test/NuxtLogo.spec.js

+ 24 - 1
components/Ui/Search/Address.vue

@@ -34,6 +34,24 @@ export default {
       type: String,
       required: false,
       default: ''
+    },
+    type: {
+      type: String,
+      required: false,
+      default: 'housenumber',
+      validator (value) {
+        return ['housenumber', 'street', 'locality', 'municipality'].includes(value)
+      }
+    },
+    limit: {
+      type: Number,
+      required: false,
+      default: 5
+    },
+    autocomplete: {
+      type: Boolean,
+      required: false,
+      default: true
     }
   },
   data () {
@@ -66,7 +84,12 @@ export default {
       this.loading = true
 
       // Lazily load input items
-      fetch('https://api-adresse.data.gouv.fr/search/?type=municipality&autocomplete=1&limit=5&q=' + val)
+      const apiUrl = 'https://api-adresse.data.gouv.fr/search/' +
+                     `?type=${this.type}` +
+                     `&autocomplete=${this.autocomplete ? 1 : 0}` +
+                     `&limit=${this.limit}` +
+                     `&q=${val}`
+      fetch(encodeURI(apiUrl))
         .then(res => res.json())
         .then(({ features }) => {
           this.features = features

+ 0 - 33
components/Ui/Search/Text.vue

@@ -1,33 +0,0 @@
-<template>
-  <v-text-field
-    v-model="value"
-    type="text"
-    outlined
-    append-icon="mdi-magnify"
-    :label="$t('what') + ' ?'"
-    @click:append="$emit('change', value)"
-  />
-</template>
-
-<script>
-export default {
-  props: {
-    value: {
-      type: String,
-      required: false,
-      default: ''
-    }
-  },
-  watch: {
-    value () {
-      this.$emit('input', this.value)
-    }
-  }
-}
-</script>
-
-<style>
-.v-input__control {
-  height: 56px;
-}
-</style>

+ 3 - 1
jest.config.js

@@ -1,4 +1,5 @@
 module.exports = {
+  preset: '@nuxt/test-utils',
   moduleNameMapper: {
     '^@/(.*)$': '<rootDir>/$1',
     '^~/(.*)$': '<rootDir>/$1',
@@ -20,5 +21,6 @@ module.exports = {
     '<rootDir>/components/**/*.vue',
     '<rootDir>/pages/**/*.vue'
   ],
-  testEnvironment: 'jsdom'
+  testEnvironment: 'jsdom',
+  setupFiles: ['<rootDir>/tests/unit/index.ts']
 }

+ 14 - 2
pages/structures_adherentes/index.vue

@@ -36,11 +36,23 @@
           <v-form method="get" class="mt-8 w100">
             <v-row>
               <v-col cols="6" class="py-2 px-1">
-                <UiSearchText v-model="textFilter" />
+                <v-text-field
+                  v-model="textFilter"
+                  type="text"
+                  outlined
+                  clearable
+                  append-icon="mdi-magnify"
+                  :label="$t('what') + ' ?'"
+                  @click:append="$emit('change', value)"
+                />
               </v-col>
 
               <v-col cols="6" class="py-2 px-1">
-                <UiSearchAddress ref="addressSearch" @change="locationFilterChanged" />
+                <UiSearchAddress
+                  ref="addressSearch"
+                  type="municipality"
+                  @change="locationFilterChanged"
+                />
               </v-col>
             </v-row>
 

+ 0 - 9
test/NuxtLogo.spec.js

@@ -1,9 +0,0 @@
-import { mount } from '@vue/test-utils'
-import NuxtLogo from '@/components/NuxtLogo.vue'
-
-describe('NuxtLogo', () => {
-  test('is a Vue instance', () => {
-    const wrapper = mount(NuxtLogo)
-    expect(wrapper.vm).toBeTruthy()
-  })
-})