Skip to content

Commit

Permalink
test(place-input.spec.js): extend place-input test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
amoncaldas committed Jan 18, 2022
1 parent f437d18 commit f8c2cce
Showing 1 changed file with 75 additions and 17 deletions.
92 changes: 75 additions & 17 deletions tests/integration/specs/place-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ describe('Place-input', () => {
height: 30,
mb: 0,
disabled: false
}

it('should render place-input component with `find a place` label', async (done) => {
await new AppLoader().fetchApiInitialData()
const wrapper = await render(PlaceInput, {propsData: placeInputProps, i18n: i18n, store: store })
expect(wrapper.text()).toContain(i18n.messages[i18n.locale].placeInput.findAPlace)
done()
})
}

it('should render place-input component with `startingPlace`', async (done) => {
await new AppLoader().fetchApiInitialData()
Expand All @@ -60,14 +53,79 @@ describe('Place-input', () => {
await textInput.setValue('heidelberg')
await textInput.trigger('keyup')

// When the input has completed the autocomplete task
wrapper.vm.$on('autocompleted', async () => {
// Wait a bit so that suggestions are rendered
await new Promise(resolve => setTimeout(resolve, 200))
expect(wrapper.findAll('.place-suggestion').length).toBeGreaterThan(2)
expect(wrapper.vm.localModel.suggestions.length).toBeGreaterThan(2)
expect(wrapper.vm.placeSuggestions.length).toBeGreaterThan(2)
done()
})
await new Promise(resolve => setTimeout(resolve, 5000))
expect(wrapper.findAll('.place-suggestion').length).toBeGreaterThan(2)
expect(wrapper.vm.localModel.suggestions.length).toBeGreaterThan(2)
expect(wrapper.vm.placeSuggestions.length).toBeGreaterThan(2)
done()
})

it('should show suggestions when coordinates are inputted', async (done) => {
placeInputProps.isLast = false
await new AppLoader().fetchApiInitialData()
const wrapper = mount(PlaceInput, {propsData: placeInputProps, i18n: i18n, store: store })

expect(wrapper.contains('.place-input')).toBe(true)
expect(wrapper.findComponent(PlaceInput).exists()).toBe(true)

const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('-37.97321319580079,-12.489208068615273')
await textInput.trigger('keyup')

await new Promise(resolve => setTimeout(resolve, 4000))
expect(wrapper.findAll('.place-suggestion').length).toBeGreaterThan(2)
let rawCoordinates = wrapper.findAll('.place-suggestion').wrappers[0].find('.raw-coord .v-list__tile__title button strong')
expect(rawCoordinates.element.innerText).toBe('-37.97321319580079,-12.489208068615273')
expect(wrapper.vm.localModel.suggestions.length).toBeGreaterThan(2)
expect(wrapper.vm.placeSuggestions.length).toBeGreaterThan(2)

await wrapper.findAll('.switch-coords').trigger('click')
await new Promise(resolve => setTimeout(resolve, 3000))
rawCoordinates = wrapper.findAll('.place-suggestion').wrappers[0].find('.raw-coord .v-list__tile__title button strong')
expect(rawCoordinates.element.innerText).toBe('-12.489208068615273,-37.97321319580079')
expect(wrapper.emitted().autocompleted).toBeTruthy()

let switchCoords = wrapper.find('.switch-coords')
await switchCoords.trigger('click')
await new Promise(resolve => setTimeout(resolve, 2000))
let suggestions = wrapper.findAll('.place-suggestion')
expect(suggestions.length).toBe(2)
done()
})

it('should not show suggestions when no text is inputted', async (done) => {
placeInputProps.isLast = false
await new AppLoader().fetchApiInitialData()
const wrapper = mount(PlaceInput, {propsData: placeInputProps, i18n: i18n, store: store })

expect(wrapper.contains('.place-input')).toBe(true)
expect(wrapper.findComponent(PlaceInput).exists()).toBe(true)

const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('')
await wrapper.trigger('keydown.enter')

await new Promise(resolve => setTimeout(resolve, 5000))
expect(wrapper.findAll('.place-suggestion').length).toBe(0)
done()
})

it('should switch to search mode on search action', async (done) => {
placeInputProps.isLast = false
placeInputProps.supportSearch = true
await new AppLoader().fetchApiInitialData()
const wrapper = mount(PlaceInput, {propsData: placeInputProps, i18n: i18n, store: store })

expect(wrapper.contains('.place-input')).toBe(true)
expect(wrapper.findComponent(PlaceInput).exists()).toBe(true)

const textInput = wrapper.find('input[type="text"]')
await textInput.setValue('heidelberg')
await wrapper.findAll('.place-input .search').trigger('click')

wrapper.vm.$nextTick()
expect(wrapper.findAll('.place-suggestion').length).toBe(0)
expect(wrapper.emitted().switchedToSearchMode).toBeTruthy()
done()
})
})

0 comments on commit f8c2cce

Please sign in to comment.