Parcourir la source

unit tests: add features and mocks

Olivier Massot il y a 4 ans
Parent
commit
ff5f6b261b

+ 25 - 4
tests/unit/component/Ui/Search/Address.spec.js

@@ -1,18 +1,39 @@
 import { mount } from '@vue/test-utils'
 import Vuetify from 'vuetify'
 import Address from '~/components/Ui/Search/Address'
+import response from '~/tests/unit/component/Ui/Search/fixtures/response'
+
+global.fetch = jest.fn(() =>
+  Promise.resolve({
+    json: () => Promise.resolve(
+      response
+    )
+  })
+)
 
 let wrapper
 let vuetify
+
 beforeEach(() => {
   vuetify = new Vuetify()
-  wrapper = mount(Address, {
-    vuetify
-  })
+  fetch.mockClear()
 })
 
 describe('components/ui/search/address', () => {
-  it('an input of 1+ cars shall display results', async () => {})
+  it('an input of 1+ cars shall display results', async () => {
+    wrapper = mount(Address, {
+      vuetify
+    })
+
+    const addressSearchBar = wrapper.find('.v-autocomplete')
+    // addressSearchBar.element.search = 'paris'
+    // await addressSearchBar.trigger('click')
+    addressSearchBar.find('input[type="text"]').setValue('paris')
+
+    const resultsList = wrapper.find('v-autocomplete__content')
+    expect(resultsList.exists()).toBeTruthy()
+    expect(resultsList.find('div:contains("Paris")').exists()).toBeTruthy()
+  })
   it('position shall be set when a result is clicked', async () => {})
   it('position shall be cleared when input is cleared', async () => {})
   it('first result shall be selected when enter key is pressed', async () => {})

+ 264 - 0
tests/unit/component/Ui/Search/fixtures/response.js

@@ -0,0 +1,264 @@
+
+export default {
+  type: 'FeatureCollection',
+  version: 'draft',
+  features: [
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.347,
+          48.859
+        ]
+      },
+      properties: {
+        label: 'Paris',
+        score: 0.9704590909090908,
+        id: '75056',
+        type: 'municipality',
+        name: 'Paris',
+        postcode: '75001',
+        citycode: '75056',
+        x: 652089.7,
+        y: 6862305.26,
+        population: 2190327,
+        city: 'Paris',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.67505
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.295289,
+          48.841959
+        ]
+      },
+      properties: {
+        label: 'Paris 15e Arrondissement',
+        score: 0.8693736363636363,
+        id: '75115',
+        type: 'municipality',
+        name: 'Paris 15e Arrondissement',
+        postcode: '75015',
+        citycode: '75115',
+        x: 648278.87,
+        y: 6860443.09,
+        population: 233484,
+        city: 'Paris 15e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.56311
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.397152,
+          48.863367
+        ]
+      },
+      properties: {
+        label: 'Paris 20e Arrondissement',
+        score: 0.8685690909090908,
+        id: '75120',
+        type: 'municipality',
+        name: 'Paris 20e Arrondissement',
+        postcode: '75020',
+        citycode: '75120',
+        x: 655772.96,
+        y: 6862761.58,
+        population: 195604,
+        city: 'Paris 20e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.55426
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.348679,
+          48.892045
+        ]
+      },
+      properties: {
+        label: 'Paris 18e Arrondissement',
+        score: 0.8685563636363636,
+        id: '75118',
+        type: 'municipality',
+        name: 'Paris 18e Arrondissement',
+        postcode: '75018',
+        citycode: '75118',
+        x: 652243.19,
+        y: 6865978.62,
+        population: 195060,
+        city: 'Paris 18e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.55412
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.387708,
+          48.887252
+        ]
+      },
+      properties: {
+        label: 'Paris 19e Arrondissement',
+        score: 0.86835,
+        id: '75119',
+        type: 'municipality',
+        name: 'Paris 19e Arrondissement',
+        postcode: '75019',
+        citycode: '75119',
+        x: 655100.72,
+        y: 6865422.77,
+        population: 186393,
+        city: 'Paris 19e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.55185
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.365001,
+          48.830193
+        ]
+      },
+      properties: {
+        label: 'Paris 13e Arrondissement',
+        score: 0.868230909090909,
+        id: '75113',
+        type: 'municipality',
+        name: 'Paris 13e Arrondissement',
+        postcode: '75013',
+        citycode: '75113',
+        x: 653384.64,
+        y: 6859091.43,
+        population: 181552,
+        city: 'Paris 13e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.55054
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.304844,
+          48.887702
+        ]
+      },
+      properties: {
+        label: 'Paris 17e Arrondissement',
+        score: 0.8678736363636362,
+        id: '75117',
+        type: 'municipality',
+        name: 'Paris 17e Arrondissement',
+        postcode: '75017',
+        citycode: '75117',
+        x: 649024.91,
+        y: 6865523.11,
+        population: 167835,
+        city: 'Paris 17e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.54661
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.267032,
+          48.856305
+        ]
+      },
+      properties: {
+        label: 'Paris 16e Arrondissement',
+        score: 0.8678081818181818,
+        id: '75116',
+        type: 'municipality',
+        name: 'Paris 16e Arrondissement',
+        postcode: '75016',
+        citycode: '75116',
+        x: 646219.86,
+        y: 6862057.09,
+        population: 165446,
+        city: 'Paris 16e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.54589
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.381844,
+          48.860162
+        ]
+      },
+      properties: {
+        label: 'Paris 11e Arrondissement',
+        score: 0.8672718181818182,
+        id: '75111',
+        type: 'municipality',
+        name: 'Paris 11e Arrondissement',
+        postcode: '75011',
+        citycode: '75111',
+        x: 654647.14,
+        y: 6862413.89,
+        population: 147017,
+        city: 'Paris 11e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.53999
+      }
+    },
+    {
+      type: 'Feature',
+      geometry: {
+        type: 'Point',
+        coordinates: [
+          2.415411,
+          48.833494
+        ]
+      },
+      properties: {
+        label: 'Paris 12e Arrondissement',
+        score: 0.8670972727272728,
+        id: '75112',
+        type: 'municipality',
+        name: 'Paris 12e Arrondissement',
+        postcode: '75012',
+        citycode: '75112',
+        x: 657087.89,
+        y: 6859429.89,
+        population: 141494,
+        city: 'Paris 12e Arrondissement',
+        context: '75, Paris, \u00CEle-de-France',
+        importance: 0.53807
+      }
+    }
+  ],
+  attribution: 'BAN',
+  licence: 'ETALAB-2.0',
+  query: 'paris',
+  filters: {
+    type: 'municipality'
+  },
+  limit: 10
+}