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

Spike on assertContent test helper #146

Merged

Conversation

ryanlabouve
Copy link
Contributor

@ryanlabouve ryanlabouve commented Dec 23, 2016

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)

@@ -139,3 +139,14 @@ export function assertTooltipSide(assert, options = {}) {
'Tooltip should be left of the target');
}
}

export function assertContent(assert, contentString, options = {}) {
Copy link
Owner

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.

Copy link
Owner

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'}}
Copy link
Owner

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.
Copy link
Owner

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.

@sir-dunxalot
Copy link
Owner

sir-dunxalot commented Dec 23, 2016

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 trim() might reveal others.

@sir-dunxalot sir-dunxalot mentioned this pull request Dec 23, 2016
3 tasks
@ryanlabouve
Copy link
Contributor Author

Cool! I made the changes to helper name and signature and added the block form helper.

One general improvement will be to use this test helper throughout the tooltip where we previously tested content with out.

Are you wanting this to happen in this PR or in the future?

@sir-dunxalot
Copy link
Owner

sir-dunxalot commented Dec 24, 2016

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:

@sir-dunxalot
Copy link
Owner

Once those updates are done we are good to merge this and it will be a great and widely-used addition to this library!

@ryanlabouve
Copy link
Contributor Author

I added the tests to the spots you mentioned.

Here are a few questions / possible changes that I would like to make pending your 👍:

  • allowing targetSelector to determine tooltip content via target (link to source)

  • Show assertion if contentString is not passed in as an argument. This gives users of this test selector direct feedback if they are missing this required arg.

  • Should we do something to enabled the test to work for lazyRendering? e.g. here

@a15n
Copy link
Contributor

a15n commented Dec 29, 2016

"Should we do something to enabled the test to work for lazyRendering?"

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?

@ryanlabouve
Copy link
Contributor Author

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.

@a15n
Copy link
Contributor

a15n commented Dec 30, 2016

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...

  1. initialize isShown=true
  2. initialize with enableLazyRendering=false
  3. triggerTooltipEvent($tooltipTarget, 'mouseenter')

@sir-dunxalot
Copy link
Owner

sir-dunxalot commented Dec 30, 2016

allowing targetSelector to determine tooltip content via target (link to source)

Could you expand on what capability you'd like to add?

Show assertion if contentString is not passed in as an argument. This gives users of this test selector direct feedback if they are missing this required arg.

All for this! 👍 To be consistent with existing tests, Ember.assert could be used (see example here).

@@ -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',
Copy link
Owner

@sir-dunxalot sir-dunxalot Dec 30, 2016

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.

@sir-dunxalot
Copy link
Owner

One comment left to resolve (see prior comment) - otherwise the code changes look good!

@sir-dunxalot
Copy link
Owner

@ryanlabouve Looks like the latest changes to master branch have created conflicts with this branch.

* Removed unneeded comment
* Added assertion for if contentString is undefined
@ryanlabouve
Copy link
Contributor Author

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.

@sir-dunxalot
Copy link
Owner

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).

@ryanlabouve
Copy link
Contributor Author

Cool. Just pushed the linting changes.

@sir-dunxalot
Copy link
Owner

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!

@a15n
Copy link
Contributor

a15n commented Jan 7, 2017

good work Ryan

@ryanlabouve
Copy link
Contributor Author

Thanks!

Copy link
Contributor

@a15n a15n left a 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.
Copy link
Contributor

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' }); .....

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

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(
Copy link
Contributor

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

Copy link
Contributor Author

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`
Copy link
Contributor

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"}}`);

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Owner

@sir-dunxalot sir-dunxalot Jan 7, 2017

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"}}`);

Copy link
Contributor Author

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`
Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

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

everywhere

</div>
`);

const stubbedAssert = {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Owner

@sir-dunxalot sir-dunxalot left a 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.

@ryanlabouve
Copy link
Contributor Author

Updates made! Please merge when you are able to confirm :-D

@a15n
Copy link
Contributor

a15n commented Jan 8, 2017

LGTM

@sir-dunxalot sir-dunxalot merged commit f683efc into sir-dunxalot:master Jan 8, 2017
@sir-dunxalot
Copy link
Owner

Merged! Release to come shortly.

@sir-dunxalot
Copy link
Owner

Released as 2.8.0. Thanks a lot @ryanlabouve!

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

Successfully merging this pull request may close these issues.

4 participants