import Vue from 'vue'
import injectStyles from './inject-styles'
import { isIE9 } from 'web/util/index'
import { nextFrame } from 'web/runtime/transition-util'
if (!isIE9) {
describe('Transition mode', () => {
const duration = injectStyles()
const components = {
one: { template: '
one
' },
two: { template: 'two
' }
}
let el
beforeEach(() => {
el = document.createElement('div')
document.body.appendChild(el)
})
it('dynamic components, simultaneous', done => {
const vm = new Vue({
template: `
`,
data: { view: 'one' },
components
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('dynamic components, out-in', done => {
let next
const vm = new Vue({
template: `
`,
data: { view: 'one' },
components,
methods: {
afterLeave () {
next()
}
}
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
'
)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe('')
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('dynamic components, in-out', done => {
let next
const vm = new Vue({
template: `
`,
data: { view: 'one' },
components,
methods: {
afterEnter () {
next()
}
}
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('dynamic components, in-out with early cancel', done => {
let next
const vm = new Vue({
template: `
`,
data: { view: 'one' },
components,
methods: {
afterEnter () {
next()
}
}
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
// switch again before enter finishes,
// this cancels both enter and leave.
vm.view = 'one'
}).then(() => {
// 1. the pending leaving "one" should be removed instantly.
// 2. the entering "two" should be placed into its final state instantly.
// 3. a new "one" is created and entering
expect(vm.$el.innerHTML).toBe(
'two
' +
'one
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
' +
'one
'
)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
' +
'one
'
)
}).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
' +
'one
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
' +
'one
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
'
)
}).then(done).then(done)
})
it('normal elements with different keys, simultaneous', done => {
const vm = new Vue({
template: ``,
data: { view: 'one' },
components
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('normal elements with different keys, out-in', done => {
let next
const vm = new Vue({
template: ``,
data: { view: 'one' },
components,
methods: {
afterLeave () {
next()
}
}
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
'
)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe('')
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('normal elements with different keys, in-out', done => {
let next
const vm = new Vue({
template: ``,
data: { view: 'one' },
components,
methods: {
afterEnter () {
next()
}
}
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(_next => { next = _next }).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(nextFrame).then(() => {
expect(vm.$el.innerHTML).toBe(
'one
' +
'two
'
)
}).thenWaitFor(duration + 10).then(() => {
expect(vm.$el.innerHTML).toBe(
'two
'
)
}).then(done)
})
it('warn invaid mode', () => {
new Vue({
template: '123
'
}).$mount()
expect('invalid mode: foo').toHaveBeenWarned()
})
it('warn usage on non element/component', () => {
new Vue({
template: 'foo'
}).$mount()
expect(' can only be used on elements or components, not text nodes.').toHaveBeenWarned()
})
})
}