-
Notifications
You must be signed in to change notification settings - Fork 141
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
Spike on assertContent test helper #146
Spike on assertContent test helper #146
Conversation
@@ -139,3 +139,14 @@ export function assertTooltipSide(assert, options = {}) { | |||
'Tooltip should be left of the target'); | |||
} | |||
} | |||
|
|||
export function assertContent(assert, contentString, options = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To match existing test helper conventions, we should name this helper assertTooltipContent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I wonder if contentString
should be a part of options
. For the spacing and side helpers I worked on, I passed all the options via the options
block to standardize the params going to each helper.
this.render(hbs` | ||
<div> | ||
:) | ||
{{tooltip-on-element text='Smiley face'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good addition to this test will be a test for the block form:
<div>
:)
{{#tooltip-on-element}}
Smiley face
{{/tooltip-on-element}}
</div>
@@ -420,6 +420,7 @@ This addon exposes testing helpers which can be used inside of the consuming app | |||
* `assertTooltipRendered(assert)`: asserts if the tooltip has been rendered. When enableLazyRendering is true the tooltip will only be rendered after the user has interacted with the $target element. A tooltip can be rendered but not visible. | |||
* `assertTooltipNotRendered(assert)`: asserts if the tooltip has not been rendered. When enableLazyRendering is true the tooltip will only be rendered after the user has interacted with the $target element. | |||
* `assertTooltipSide(assert, { side: 'right' }): asserts that the tooltip is shown on the correct side of the target. Additional options that can be passed are `selector` and `targetSelector`. | |||
* `assertContent(assert, contentString): asserts that the content of the tooltip matches a given string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good enough of a description for now. I'm going to be revamping the test helper documentation (#144) to give each test helpers its own heading and section in the readme.
Great timing! This looks like a great start and it may well be this simple. One general improvement will be to use this test helper throughout the tooltip where we previously tested content with out. I found tooltip-on-element-test, tooltip-on-component-test, and popover-on-component-test that should all be updated to use this new test helper. A quick search for |
Cool! I made the changes to helper name and signature and added the block form helper.
Are you wanting this to happen in this PR or in the future? |
This PR please. It shouldn't be a big fix but will make sure our test suite is up-to-date with this new addition and that will also help to 'test' the test helper. I believe this is the complete list of tests to update: |
Once those updates are done we are good to merge this and it will be a great and widely-used addition to this library! |
I added the tests to the spots you mentioned. Here are a few questions / possible changes that I would like to make pending your 👍:
|
If a tooltip is not rendered then there will be no tooltip or tooltipText. I don't see how this test would work in that scenario. Am I understanding the question correctly? |
Perhaps I am misunderstanding, but lazy rendering is just waiting to stick the tooltips in the DOM until they are needed? If so, if I was doing an acceptance test I initially thought I would want to check their content regardless if they were rendered or not. But now that I'm thinking about it I guess that's a leaky abstraction. |
You're correct about how lazy rendering works. There is no way to check their content unless they are rendered. So if you wanted to check their content in your acceptance test you'd need to do one of these things...
|
Could you expand on what capability you'd like to add?
All for this! 👍 To be consistent with existing tests, |
@@ -41,7 +42,11 @@ test('tooltip-on-element has the proper aria-describedby tag', function(assert) | |||
const $tooltipTarget = this.$('.target'); | |||
const describedBy = $tooltipTarget.attr('aria-describedby'); | |||
|
|||
assert.equal(this.$(`#${describedBy}`).text().trim(), 'Some info in a tooltip.'); | |||
assertTooltipContent(assert, { | |||
// targetSelector: '.target', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discussion about this line needs to be resolve in the comments.
One comment left to resolve (see prior comment) - otherwise the code changes look good! |
@ryanlabouve Looks like the latest changes to master branch have created conflicts with this branch. |
5e1693b
to
7262d71
Compare
* Removed unneeded comment * Added assertion for if contentString is undefined
Rebased off of master and fixed conflicts! Also added the assertion we talked about and removed an unneeded comment. Would you like me to fix the new ESLint errors as well? They are not related to this PR but it looks like they are causing the tests to fail. |
Yes pleas, Ryan. Sorry for asking you to make unrelated changes. This is in part due to this PR being opened before a couple of bigger sweeping PRs were merged (addon linting being one of them). |
Cool. Just pushed the linting changes. |
Great! I'll make a final review and should be able to approve changes before the end of this weekend. This will be an awesome addition! |
good work Ryan |
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall it looks good. I left a few comments that will be easy to fix. Thanks again for doing this.
@@ -421,6 +421,7 @@ This addon exposes testing helpers which can be used inside of the consuming app | |||
* `assertTooltipNotRendered(assert)`: asserts if the tooltip has not been rendered. When enableLazyRendering is true the tooltip will only be rendered after the user has interacted with the $target element. | |||
* `assertTooltipSide(assert, { side: 'right' }): asserts that the tooltip is shown on the correct side of the target. Additional options that can be passed are `selector` and `targetSelector`. | |||
* `assertTooltipSpacing(assert, { side: 'right', spacing: 10 }): asserts that the tooltip is a given distance from the target (on a given side). `side` and `spacing` must be passed. Additional options that can be passed are `selector` and `targetSelector`. | |||
* `assertContent(assert, contentString): asserts that the content of the tooltip matches a given string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be updated...
assertTooltipContent(assert, { contentString: 'hello' }); .....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
export function assertTooltipContent(assert, options = {}) { | ||
const { contentString } = options; | ||
|
||
if (contentString === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use http://emberjs.com/api/#method_isEmpty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use isEmpty
then a user would not be able to test the case where contentString
is an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I meant 'isNone'
const $tooltip = getTooltipFromBody(options.selector); | ||
const tooltipContent = $tooltip.text().trim(); | ||
|
||
assert.equal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not blocking, could you follow the syntax we did elsewhere in this file...
assert.equal(a, b, 'some description');
PS: I like that you added the tooltipContent and contentString in the description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
assert.expect(2); | ||
|
||
this.render(hbs` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the div is unnecessary. Could be written like...
this.render(hbs`{{tooltip-on-element test="foo"}}`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes the tests harder to read, but would be happy to change. My reasoning is that the surrounding div gives someone reading the test more context.
Again, happy to change, please just confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To stay consistent with our other tests I think we should remove the <div>
and use:
this.render(hbs`{{tooltip-on-element test="foo"}}`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You got it. Updating now.
contentString: 'Smiley face', | ||
}); | ||
|
||
this.render(hbs` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be simplified too (no div)
assert.expect(2); | ||
|
||
this.render(hbs` | ||
<div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everywhere
</div> | ||
`); | ||
|
||
const stubbedAssert = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain what stubbedAssert does? I'm confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just stubs the equal
on assert.equal
that is passed in to our helper. The value this adds is testing that our helper calls what we think it will with the values it should have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any blocking requests in the PR review though @a15n brings up some good points in his review. @ryanlabouve please let me know when this is ready for merge given @a15n's comments.
Updates made! Please merge when you are able to confirm :-D |
LGTM |
Merged! Release to come shortly. |
Released as |
This PR adds an
assertContent(assert, contentString, options)
test helper to allow assertion on the content of a tooltip.This may be a basic implementation, but would love feedback on how to improve.
Also, I feel like I should add additional tests to cover passing in at least the selector options.
Is this heading in the right direction?
(This relates to #128)