Skip to content

Commit

Permalink
Spike on assertContent test helper
Browse files Browse the repository at this point in the history
This relates to sir-dunxalot#128
  • Loading branch information
ryanlabouve committed Jan 6, 2017
1 parent 3e8d9a4 commit a8426dd
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* `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.
Expand Down
11 changes: 11 additions & 0 deletions test-support/helpers/ember-tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,14 @@ 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 assertContent(assert, contentString, options = {}) {
const $tooltip = getTooltipFromBody(options.selector);
const tooltipContent = $tooltip.text().trim();

assert.equal(
tooltipContent,
contentString,
`Content of tooltip (${tooltipContent}) matched expected (${contentString})`
);
}
51 changes: 51 additions & 0 deletions tests/integration/components/content-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { assertContent } from '../../helpers/ember-tooltips';

moduleForComponent('tooltip-on-element', 'Integration | Option | content ryanlabouve', {
integration: true
});

test('assertContent correctly matches expected content', function(assert) {

assert.expect(1);

this.render(hbs`
<div>
:)
{{tooltip-on-element text='Smiley face'}}
</div>
`);

assertContent(assert, 'Smiley face');
});

test('assertContent correctly compares expected and discovered content of tooltip', function(assert) {

assert.expect(2);

this.render(hbs`
<div>
:)
{{tooltip-on-element text='Smiley face'}}
</div>
`);

const stubbedAssert = {
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'
);
}
};

assertContent(stubbedAssert, 'Frowning face');
});

0 comments on commit a8426dd

Please sign in to comment.