Skip to content
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

feat(visible): Add visible() method on Wrapper (#327) #335

Merged
merged 1 commit into from
Jan 20, 2018

Conversation

Toilal
Copy link
Contributor

@Toilal Toilal commented Jan 8, 2018

Ready ! :)

@eddyerburgh
Copy link
Member

eddyerburgh commented Jan 8, 2018

Thanks for the PR 😀

I don't think we should add a parent method as part of this PR, or at all —#65

You should use the element parentNode/parentElement properties to traverse the parent tree.

Like you found, most vnodes have an undefined parent. Functional vnodes use the parent property.

@Toilal
Copy link
Contributor Author

Toilal commented Jan 9, 2018

I just removed parent(), implement visible() using HTMLElement, and added tests. It seems to work now :p.

visible() is also consistent with exists() (if exists() == false then visible() == false)

@Toilal Toilal force-pushed the visible branch 3 times, most recently from 387c59e to e7ee4da Compare January 9, 2018 08:46
@@ -10,7 +10,7 @@
],
"scripts": {
"build": "node build/build.js",
"build:test": "NODE_ENV=test node build/build.js",
"build:test": "cross-env NODE_ENV=test node build/build.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good spot

*/
visible (): boolean {
if (!this.exists()) {
console.log('NOT EXISTS')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw an error here using the throwError function:
throwError('cannot call visible on a wrapper without an element')

* Utility to check wrapper is visible. Returns false if a parent element has display: none or visibility: hidden style.
*/
visible (): boolean {
if (!this.exists()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check for an element here instead of exists—if(!this.element). That's how we check for an element in other tests (I think this might solve the flow error)

}
element = element.parentElement
}
console.log('no parent')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove these console logs

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple of changes. Also we need the flow error to be fixed

@eddyerburgh
Copy link
Member

Are you able to make these changes @Toilal ?

@Toilal
Copy link
Contributor Author

Toilal commented Jan 12, 2018

Oops, I just forget this one, i'll do ASAP

@Toilal
Copy link
Contributor Author

Toilal commented Jan 12, 2018

Done

@Toilal Toilal changed the title feat(visible): Add visible() and parent() methods on Wrapper (#327) feat(visible): Add visible() method on Wrapper (#327) Jan 13, 2018
@38elements
Copy link
Contributor

I think it is necessary to add this to the document.

@eddyerburgh
Copy link
Member

eddyerburgh commented Jan 14, 2018 via email

@eddyerburgh
Copy link
Member

@Toilal Can you add a page on visible to docs/en/wrapper/api/visible.md, docs/en/api/wrapper-array/visible.md, and add a links to both pages in docs/en/SUMMARY.

@Toilal
Copy link
Contributor Author

Toilal commented Jan 15, 2018

Rebased and docs added.

@Toilal
Copy link
Contributor Author

Toilal commented Jan 16, 2018

Can you restard the build ?

@@ -0,0 +1,21 @@
# exists()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title missed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -63,6 +64,7 @@
* [setProps](api/wrapper-array/setProps.md)
* [trigger](api/wrapper-array/trigger.md)
* [update](api/wrapper-array/update.md)
* [visible](api/wrapper/visible.md)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapper-array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the same as exists() with use the same page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize exists uses the same page, this is an error with the exists page.

The wrapper-array pages have different examples that use a wrapper-array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I fix exists page too ? Or another pull request ?

Assert `Wrapper` or `WrapperArray` is visible.

Returns false if an ancestor element has `display: none` or `visibility: hidden` style.

Copy link
Member

@eddyerburgh eddyerburgh Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add that this is useful for testing whether v-show is working correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.find('is-not-visible').visible()).toBe(false)
Copy link
Member

@eddyerburgh eddyerburgh Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is-not-visible should be a class selector, not a tag selector

@@ -36,6 +36,10 @@ export default class ErrorWrapper implements BaseWrapper {
return false
}

visible (): boolean {
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw an error, like the other methods.

Only exists returns false, everything else throws an error to indicate that find was not succesful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think it should match the behavior of exists() method ? Having this return an error would make assertions on non-visible elements more verbose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it should throw an error. exists checks if find is successful, so it makes sense to return false. If find('div') is not successful, exists should return false.

Every other method checks something on the Wrapper element/ instance.

We need to make a distinction between a node being visible and a node being present.

wrapper.update()
expect(wrapper.find('.child.ready').visible()).to.equal(true)
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests 👌

@Toilal Toilal force-pushed the visible branch 2 times, most recently from dbce8b6 to d214733 Compare January 16, 2018 15:04
@Toilal
Copy link
Contributor Author

Toilal commented Jan 16, 2018

I just squashed everything and make visible() method fails for non-existent elements. I think it's know OK :p

@Toilal Toilal force-pushed the visible branch 2 times, most recently from 42a153a to 113aff8 Compare January 16, 2018 15:40
const wrapper = mount(Foo)
expect(wrapper.visible()).toBe(true)
expect(wrapper.find('.is-not-visible').visible()).toBe(false)
expect(wrapper.findAll('div').visible()).toBe(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the findAll examples please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@eddyerburgh eddyerburgh merged commit 445a72d into vuejs:dev Jan 20, 2018
@eddyerburgh
Copy link
Member

Thanks @Toilal 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants