Skip to content

Commit

Permalink
test(share.spec.js): extend share component test
Browse files Browse the repository at this point in the history
  • Loading branch information
amoncaldas committed Dec 3, 2021
1 parent 61b5cd8 commit 8fbd0b3
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/integration/specs/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ import store from '@/store/store'
import '@babel/polyfill'

describe('Share', () => {
it('should open and close share modal', async (done) => {
let directionsUrl = `${constants.orsPublicHost}/#/directions/Mannheim,BW,Germany/Heidelberg,BW,Germany/data/%7B"coordinates":"8.492765,49.488789;8.692416,49.401247","options":%7B"zoom":8,"profile":"driving-car","preference":"recommended"%7D%7D`
var shareProps = {
url: directionsUrl
}

await new AppLoader().fetchApiInitialData()
const wrapper = mount(Share, {i18n: I18nBuilder.build(), store: store, propsData: shareProps })

expect(wrapper.contains('.share-container')).toBe(true)
expect(wrapper.findComponent(Share).exists()).toBe(true)
await wrapper.find('.open-share-btn').trigger('click')
let shareModal = document.querySelector('.share-modal')
expect(shareModal).toBeTruthy()
await wrapper.find('.share-modal .box-header button').trigger('click')
await wrapper.vm.$nextTick()
expect(document.querySelector('.share-modal')).not.toBeTruthy()
done()
})

it('should open and copy share url', async (done) => {
let directionsUrl = `${constants.orsPublicHost}/#/directions/Mannheim,BW,Germany/Heidelberg,BW,Germany/data/%7B"coordinates":"8.492765,49.488789;8.692416,49.401247","options":%7B"zoom":8,"profile":"driving-car","preference":"recommended"%7D%7D`
var shareProps = {
url: directionsUrl
}

await new AppLoader().fetchApiInitialData()
const wrapper = mount(Share, {i18n: I18nBuilder.build(), store: store, propsData: shareProps })

expect(wrapper.contains('.share-container')).toBe(true)
expect(wrapper.findComponent(Share).exists()).toBe(true)
await wrapper.find('.open-share-btn').trigger('click')
expect(document.querySelector('.share-modal')).toBeTruthy()

var shareModal = document.querySelector('.share-modal')
expect(shareModal).toBeTruthy()
shareModal.querySelector('input[type="text"]').click()
await new Promise(resolve => setTimeout(resolve, 200))
// let clipboard = await navigator.clipboard.readText()
// expect(clipboard).toBeTruthy()
done()
})

it('should render share component and toggle short url', async (done) => {
let directionsUrl = `${constants.orsPublicHost}/#/directions/Mannheim,BW,Germany/Heidelberg,BW,Germany/data/%7B"coordinates":"8.492765,49.488789;8.692416,49.401247","options":%7B"zoom":8,"profile":"driving-car","preference":"recommended"%7D%7D`
var shareProps = {
Expand All @@ -34,10 +77,16 @@ describe('Share', () => {
expect(shareUrlTextarea.value).toContain(iframeCode)
await wrapper.find('.toggle-short-url').trigger('click')

await shareModal.__vue__.$nextTick()
await wrapper.vm.$nextTick()
await new Promise(resolve => setTimeout(resolve, 1000))
shareUrlInput = shareModal.querySelector('input[type="text"]')
expect(shareUrlInput.value).toContain('https://bit.ly/')

await wrapper.find('.toggle-short-url').trigger('click')
await wrapper.vm.$nextTick()
// await new Promise(resolve => setTimeout(resolve, 1000))
shareUrlInput = shareModal.querySelector('input[type="text"]')
expect(shareUrlInput.value).not.toContain('https://bit.ly/')
done()
})
})

0 comments on commit 8fbd0b3

Please sign in to comment.