Skip to content

Commit

Permalink
add @OPEN event
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Jara committed Feb 24, 2018
1 parent 4cfa139 commit 17ee162
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
6 changes: 6 additions & 0 deletions documentation/_api/_events.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ h2.typo__h2#sub-events(data-section) Events
td.table__td
| Emitted after when #[kbd this.value] changes

tr.table__tr
td.table__td: strong @open
td.table__td: -
td.table__td
| Emitted when the popover is opened.

tr.table__tr
td.table__td: strong @close
td.table__td: kbd value
Expand Down
3 changes: 2 additions & 1 deletion src/Swatches.vue
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ export default {
// Called programmatically
showPopover () {
/* istanbul ignore if */
if (this.isOpen) return /* dont show */
if (this.isOpen || this.inline) return /* dont show */
this.internalIsOpen = true
this.$el.focus()
this.$emit('open')
},
togglePopover () {
this.isOpen ? this.hidePopover() : this.showPopover()
Expand Down
69 changes: 67 additions & 2 deletions test/unit/specs/Swatches.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,71 @@ describe('Events', () => {
})
})
})
describe('@open', () => {
test('should not be emited when Inline mode is activated', () => {
const componentWrapper = mount(Swatches, {
propsData: {
inline: true
}
})
componentWrapper.vm.showPopover()

return Vue.nextTick()
.then(() => {
expect(componentWrapper.emitted().open)
.not.toBeTruthy()
})
})
test('should be emited when Inline mode is not activated', () => {
const componentWrapper = mount(Swatches, {
propsData: {
inline: false
}
})
componentWrapper.vm.showPopover()

return Vue.nextTick()
.then(() => {
expect(componentWrapper.emitted().open.length).toEqual(1)
})
})
describe('When legacy trigger is used', () => {
test('should be emited whenever user clicks the trigger', () => {
const componentWrapper = mount(Swatches, {
propsData: {
inline: false
}
})
const trigger = componentWrapper.find({ ref: 'trigger-wrapper' })
trigger.trigger('click')

return Vue.nextTick()
.then(() => {
expect(componentWrapper.emitted().open.length).toEqual(1)
})
})
})
describe('When trigger slot is used', () => {
test('should be emited whenever user clicks the trigger', () => {
const buttonTest = '<button id="button-test">Hello World</button>'
const componentWrapper = mount(Swatches, {
slots: {
trigger: buttonTest
},
propsData: {
inline: false
}
})
const trigger = componentWrapper.find('#button-test')
trigger.trigger('click')

return Vue.nextTick()
.then(() => {
expect(componentWrapper.emitted().open.length).toEqual(1)
})
})
})
})
describe('@close', () => {
test('should not be emited when Inline mode is activated', () => {
const componentWrapper = mount(Swatches, {
Expand Down Expand Up @@ -1126,8 +1191,8 @@ describe('Events', () => {
}
})
const trigger = componentWrapper.find({ ref: 'trigger-wrapper' })
trigger.trigger('click')
trigger.trigger('click')
trigger.trigger('click') // one click to open the Popover
trigger.trigger('click') // and another to close the Popover

return Vue.nextTick()
.then(() => {
Expand Down

0 comments on commit 17ee162

Please sign in to comment.