Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Update phrases test
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomka committed Dec 22, 2017
1 parent db2b5ea commit c056826
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 72 deletions.
43 changes: 0 additions & 43 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
import camelcase from 'camelcase'
import { createVM, Vue } from './utils'
import { nextTick } from './wait-for-update'

export function dataPropagationTest (Component) {
return function () {
const spy = sinon.spy()
const vm = createVM(this, function (h) {
return (
<Component staticClass='custom' onClick={spy}>Hello</Component>
)
})
spy.should.have.not.been.called
vm.$('.custom').should.exist
vm.$('.custom').click()
spy.should.have.been.calledOnce
}
}

export function attrTest (it, base, Component, attr) {
const attrs = Array.isArray(attr) ? attr : [attr]

attrs.forEach(attr => {
it(attr, function (done) {
const vm = createVM(this, function (h) {
const opts = {
props: {
[camelcase(attr)]: this.active
}
}
return (
<Component {...opts}>{attr}</Component>
)
}, {
data: { active: true }
})
vm.$(`.${base}`).should.have.class(`${base}--${attr}`)
vm.active = false
nextTick().then(() => {
vm.$(`.${base}`).should.not.have.class(`${base}--${attr}`)
vm.active = true
}).then(done)
})
})
}

export {
createVM,
Vue,
Expand Down
17 changes: 11 additions & 6 deletions test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Vue.prototype.$$ = function $$ (selector) {
const els = document.querySelectorAll(selector)
const vmEls = this.$el.querySelectorAll(selector)
const fn = vmEls.length
? el => Array.from(vmEls).find(vmEl => el === vmEl)
: el => this.$el === el
? el => Array.from(vmEls).find(vmEl => el === vmEl)
: el => this.$el === el
const found = Array.from(els).filter(fn)
return found.length
? found
Expand All @@ -37,18 +37,23 @@ Vue.prototype.$ = function $ (selector) {
const els = document.querySelectorAll(selector)
const vmEl = this.$el.querySelector(selector)
const fn = vmEl
? el => el === vmEl
: el => el === this.$el
? el => el === vmEl
: el => el === this.$el
// Allow should chaining for tests
return Array.from(els).find(fn) || emptyNodes
}

Vue.prototype.$findChild = function $ (selector) {
return this.$children.find(child => child.$el.matches(selector)) ||
this.$children.reduce((found, child) => found || child.$findChild(selector), null)
}

export function createKarmaTest (context, template, opts) {
const el = document.createElement('div')
document.getElementById('tests').appendChild(el)
const render = typeof template === 'string'
? { template: `<div>${template}</div>` }
: { render: template }
? { template: `<div>${template}</div>` }
: { render: template }
return new Vue({
el,
name: 'Test',
Expand Down
51 changes: 28 additions & 23 deletions test/specs/Datetime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,6 @@ describe('Datetime.vue', function () {
expect(vm.$('.vdatetime-input')).to.match('input')
})

it('input should render custom phrases', function () {
const vm = createVM(this,
`<Datetime :phrases="phrases"></Datetime>`,
{
components: { Datetime },
data () {
return {
phrases: {
cancel: 'Cancelar',
ok: 'Confirmar'
}
}
}
})

vm.$('.vdatetime-input').click()

vm.$nextTick(() => {
expect(vm.$('.vdatetime-popup__actions__button--confirm').innerText).to.be.equal('Confirmar')
expect(vm.$('.vdatetime-popup__actions__button--cancel').innerText).to.be.equal('Cancelar')
})
})

it('input should inherit attributes', function () {
const vm = createVM(this,
`<Datetime placeholder="Select date..."></Datetime>`,
Expand Down Expand Up @@ -75,6 +52,34 @@ describe('Datetime.vue', function () {
})
})

describe('pass props', function () {
it('should pass phrases to popup', function (done) {
const vm = createVM(this,
`<Datetime :phrases="phrases"></Datetime>`,
{
components: { Datetime },
data () {
return {
phrases: {
cancel: 'Cancelar',
ok: 'Confirmar'
}
}
}
})

vm.$('.vdatetime-input').click()

vm.$nextTick(() => {
expect(vm.$findChild('.vdatetime-popup').phrases).to.be.eql({
cancel: 'Cancelar',
ok: 'Confirmar'
})
done()
})
})
})

describe('types', function () {
it('should be date type by default', function () {
const vm = createVM(this,
Expand Down
20 changes: 20 additions & 0 deletions test/specs/DatetimePopup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ describe('DatetimePopup.vue', function () {
done()
})
})

it('should render custom phrases', function () {
const vm = createVM(this,
`<DatetimePopup :datetime="datetime" :phrases="phrases"></DatetimePopup>`,
{
components: { DatetimePopup },
data () {
return {
datetime: LuxonDatetime.local(),
phrases: {
cancel: 'Cancelar',
ok: 'Confirmar'
}
}
}
})

expect(vm.$('.vdatetime-popup__actions__button--confirm').innerText).to.be.equal('Confirmar')
expect(vm.$('.vdatetime-popup__actions__button--cancel').innerText).to.be.equal('Cancelar')
})
})

describe('events', function () {
Expand Down

0 comments on commit c056826

Please sign in to comment.