Skip to content

refactor: rename visible to isVisible #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* [text](api/wrapper/text.md)
* [trigger](api/wrapper/trigger.md)
* [update](api/wrapper/update.md)
* [visible](api/wrapper/visible.md)
* [isVisible](api/wrapper/isVisible.md)
* [WrapperArray](api/wrapper-array/README.md)
* [at](api/wrapper-array/at.md)
* [contains](api/wrapper-array/contains.md)
Expand All @@ -62,7 +62,7 @@
* [setProps](api/wrapper-array/setProps.md)
* [trigger](api/wrapper-array/trigger.md)
* [update](api/wrapper-array/update.md)
* [visible](api/wrapper-array/visible.md)
* [isVisible](api/wrapper-array/isVisible.md)
* [components](api/components/README.md)
* [TransitionStub](api/components/TransitionStub.md)
* [TransitionGroupStub](api/components/TransitionGroupStub.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { expect } from 'chai'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.findAll('.is-not-visible').visible()).toBe(false)
expect(wrapper.findAll('.is-visible').visible()).toBe(true)
expect(wrapper.isVisible()).toBe(true)
expect(wrapper.findAll('.is-not-visible').isVisible()).toBe(false)
expect(wrapper.findAll('.is-visible').isVisible()).toBe(true)
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# visible()
# isVisible()

Assert `Wrapper` is visible.

Expand All @@ -16,6 +16,6 @@ import { expect } from 'chai'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.find('.is-not-visible').visible()).toBe(false)
expect(wrapper.isVisible()).toBe(true)
expect(wrapper.find('.is-not-visible').isVisible()).toBe(false)
```
4 changes: 2 additions & 2 deletions docs/ja/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* [text](api/wrapper/text.md)
* [trigger](api/wrapper/trigger.md)
* [update](api/wrapper/update.md)
* [visible](api/wrapper/visible.md)
* [isVisible](api/wrapper/isVisible.md)
* [WrapperArray](api/wrapper-array/README.md)
* [at](api/wrapper-array/at.md)
* [contains](api/wrapper-array/contains.md)
Expand All @@ -61,7 +61,7 @@
* [setProps](api/wrapper-array/setProps.md)
* [trigger](api/wrapper-array/trigger.md)
* [update](api/wrapper-array/update.md)
* [visible](api/wrapper-array/visible.md)
* [isVisible](api/wrapper-array/isVisible.md)
* [コンポーネント](api/components/README.md)
* [TransitionStub](api/components/TransitionStub.md)
* [TransitionGroupStub](api/components/TransitionGroupStub.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# visible()
# isVisible()

`WrapperArray` 内のすべての `Wrapper` が表示されているかアサートします。

Expand All @@ -16,7 +16,7 @@ import { expect } from 'chai'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.findAll('.is-not-visible').visible()).toBe(false)
expect(wrapper.findAll('.is-visible').visible()).toBe(true)
expect(wrapper.isVisible()).toBe(true)
expect(wrapper.findAll('.is-not-visible').isVisible()).toBe(false)
expect(wrapper.findAll('.is-visible').isVisible()).toBe(true)
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# visible()
# isVisible()

`Wrapper` が表示されているかアサートします。

Expand All @@ -16,6 +16,6 @@ import { expect } from 'chai'
import Foo from './Foo.vue'

const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.find('.is-not-visible').visible()).toBe(false)
expect(wrapper.isVisible()).toBe(true)
expect(wrapper.find('.is-not-visible').isVisible()).toBe(false)
```
22 changes: 22 additions & 0 deletions src/wrappers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export default class Wrapper implements BaseWrapper {
* Utility to check wrapper is visible. Returns false if a parent element has display: none or visibility: hidden style.
*/
visible (): boolean {
warn('visible has been deprecated and will be removed in version 1, use isVisible instead')

let element = this.element

if (!element) {
Expand Down Expand Up @@ -328,6 +330,26 @@ export default class Wrapper implements BaseWrapper {
return this.vnode.children === undefined || this.vnode.children.length === 0
}

/**
* Checks if node is visible
*/
isVisible (): boolean {
let element = this.element

if (!element) {
return false
}

while (element) {
if (element.style && (element.style.visibility === 'hidden' || element.style.display === 'none')) {
return false
}
element = element.parentElement
}

return true
}

/**
* Checks if wrapper is a vue instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import ComponentWithVShow from '~resources/components/component-with-v-show.vue'
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
import { describeWithShallowAndMount } from '~resources/test-utils'

describeWithShallowAndMount('visible', (mountingMethod) => {
describeWithShallowAndMount('isVisible', (mountingMethod) => {
it('returns true if element has no inline style', () => {
const compiled = compileToFunctions('<div><div><span class="visible"></span></div></div>')
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.visible()).to.equal(true)
expect(element.isVisible()).to.equal(true)
})

it('returns false if element has inline style display: none', () => {
const compiled = compileToFunctions('<div><div><span style="display: none;" class="visible"></span></div></div>')
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.visible()).to.equal(false)
expect(element.isVisible()).to.equal(false)
})

it('returns false if element has inline style visibility: hidden', () => {
const compiled = compileToFunctions('<div><div><span style="visibility: hidden;" class="visible"></span></div></div>')
const wrapper = mountingMethod(compiled)
const element = wrapper.find('.visible')
expect(element.visible()).to.equal(false)
expect(element.isVisible()).to.equal(false)
})

it('returns true if element has v-show true', () => {
Expand All @@ -31,10 +31,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(false)
expect(notReadyElement.isVisible()).to.equal(false)

const readyElement = wrapper.find('.parent.ready')
expect(readyElement.visible()).to.equal(true)
expect(readyElement.isVisible()).to.equal(true)
})

it('returns false if element has v-show true', () => {
Expand All @@ -43,10 +43,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(false)
expect(notReadyElement.isVisible()).to.equal(false)

const readyElement = wrapper.find('.parent.ready')
expect(readyElement.visible()).to.equal(true)
expect(readyElement.isVisible()).to.equal(true)
})

it('returns true if parent element has v-show true', () => {
Expand All @@ -55,10 +55,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(false)
expect(notReadyElement.isVisible()).to.equal(false)

const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.visible()).to.equal(true)
expect(readyChildElement.isVisible()).to.equal(true)
})

it('returns false if parent element has v-show false', () => {
Expand All @@ -67,10 +67,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(false)
expect(notReadyElement.isVisible()).to.equal(false)

const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.visible()).to.equal(true)
expect(readyChildElement.isVisible()).to.equal(true)
})

it('returns false if root element has v-show false and parent has v-show true', () => {
Expand All @@ -80,10 +80,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(false)
expect(notReadyElement.isVisible()).to.equal(false)

const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.visible()).to.equal(false)
expect(readyChildElement.isVisible()).to.equal(false)
})

it('returns false if root element has v-show true and parent has v-show false', () => {
Expand All @@ -93,10 +93,10 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const notReadyElement = wrapper.find('.not-ready')
expect(notReadyElement.visible()).to.equal(true)
expect(notReadyElement.isVisible()).to.equal(true)

const readyChildElement = wrapper.find('.child.ready')
expect(readyChildElement.visible()).to.equal(false)
expect(readyChildElement.isVisible()).to.equal(false)
})

it('returns true if all elements are visible', () => {
Expand All @@ -106,7 +106,7 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const readyChildElement = wrapper.find('.ready')
expect(readyChildElement.visible()).to.equal(true)
expect(readyChildElement.isVisible()).to.equal(true)
})

it('returns false if one element is not visible', () => {
Expand All @@ -116,22 +116,22 @@ describeWithShallowAndMount('visible', (mountingMethod) => {
wrapper.update()

const readyChildElement = wrapper.find('.ready, .not-ready')
expect(readyChildElement.visible()).to.equal(false)
expect(readyChildElement.isVisible()).to.equal(false)
})

it('fails if one element is absent', () => {
const wrapper = mountingMethod(ComponentWithVIf)
wrapper.vm.$set(wrapper.vm, 'ready', false)
wrapper.update()

const fn = () => wrapper.find('.child.ready').visible()
const fn = () => wrapper.find('.child.ready').isVisible()
expect(fn).to.throw()
})

it('returns true if one element is present', () => {
const wrapper = mountingMethod(ComponentWithVIf)
wrapper.vm.$set(wrapper.vm, 'ready', true)
wrapper.update()
expect(wrapper.find('.child.ready').visible()).to.equal(true)
expect(wrapper.find('.child.ready').isVisible()).to.equal(true)
})
})