-
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
Changes from 6 commits
a8426dd
19b8b67
706ccde
7262d71
220db86
d3cca68
d72bc25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be updated...
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
* `triggerTooltipTargetEvent($targetElement, eventName)`: triggers an event on the passed element. The event will be triggered within an Ember.run so that the tooltip's asynchronicity is accounted for. eventName can be mouseenter, mouseleave, click, focus, focusin, and blur. | ||
|
||
Each test helper also accepts an `options` object as a final parameter. If a `selector` property is provided the assertions and actions will be run against the single element found from that selector. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,3 +222,20 @@ export function assertTooltipSpacing(assert, options) { | |
- Tooltip should be on the ${side} side of the target: ${isSideCorrect}. | ||
- On the ${side} side of the target, the tooltip should be ${spacing}px from the target but it was ${actualSpacing}px`); | ||
} | ||
|
||
export function assertTooltipContent(assert, options = {}) { | ||
const { contentString } = options; | ||
|
||
if (contentString === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. If we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah I meant 'isNone' |
||
Ember.assert('You must specify a contentString property in the options parameter'); | ||
} | ||
|
||
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 commentThe 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...
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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
tooltipContent, | ||
contentString, | ||
`Content of tooltip (${tooltipContent}) matched expected (${contentString})` | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { assertTooltipContent } from '../../helpers/ember-tooltips'; | ||
|
||
moduleForComponent('tooltip-on-element', 'Integration | Option | content', { | ||
integration: true, | ||
}); | ||
|
||
test('assertTooltipContent correctly matches expected tootltip content', function(assert) { | ||
|
||
assert.expect(2); | ||
|
||
this.render(hbs` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the div is unnecessary. Could be written like...
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 this.render(hbs`{{tooltip-on-element test="foo"}}`); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You got it. Updating now. |
||
<div> | ||
:) | ||
{{tooltip-on-element text='Smiley face'}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
`); | ||
|
||
assertTooltipContent(assert, { | ||
contentString: 'Smiley face', | ||
}); | ||
|
||
this.render(hbs` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be simplified too (no div) |
||
<div> | ||
:( | ||
{{#tooltip-on-element}} | ||
Frowning face | ||
{{/tooltip-on-element}} | ||
</div> | ||
`); | ||
|
||
assertTooltipContent(assert, { | ||
contentString: 'Frowning face', | ||
}); | ||
}); | ||
|
||
test('assertTooltipContent correctly compares expected and discovered tooltip content of tooltip', function(assert) { | ||
|
||
assert.expect(2); | ||
|
||
this.render(hbs` | ||
<div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everywhere |
||
:) | ||
{{tooltip-on-element text='Smiley face'}} | ||
</div> | ||
`); | ||
|
||
const stubbedAssert = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This just stubs the |
||
equal(arg1, arg2/* , msg */) { | ||
assert.equal( | ||
arg1, | ||
'Smiley face', | ||
'Helper correctly finds actual content of tooltip' | ||
); | ||
|
||
assert.equal( | ||
arg2, | ||
'Frowning face', | ||
'Helper correctly intends to compare to string we provide' | ||
); | ||
}, | ||
}; | ||
|
||
assertTooltipContent(stubbedAssert, { | ||
contentString: 'Frowning 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.
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.