2021-07-08 15:21:10 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render, click } from '@ember/test-helpers';
|
|
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | read-more', function (hooks) {
|
2021-07-08 15:21:10 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders', async function (assert) {
|
2021-07-08 15:21:10 +00:00
|
|
|
await render(hbs`<ReadMore />`);
|
2021-12-17 03:44:29 +00:00
|
|
|
assert.dom(this.element).hasText('');
|
2021-07-08 15:21:10 +00:00
|
|
|
});
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it can toggle open and closed when text is longer than parent', async function (assert) {
|
2021-07-08 15:21:10 +00:00
|
|
|
this.set(
|
|
|
|
'description',
|
|
|
|
'My super long template block text dignissim dictum sem, ut varius ligula lacinia quis.'
|
|
|
|
);
|
|
|
|
await render(hbs`
|
|
|
|
<div style="width: 150px">
|
|
|
|
<ReadMore>
|
|
|
|
{{this.description}}
|
|
|
|
</ReadMore>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
assert.dom('[data-test-readmore-content]').includesText(this.description);
|
|
|
|
assert.dom('[data-test-readmore-toggle]').exists('toggle exists');
|
|
|
|
assert.dom('[data-test-readmore-toggle]').hasText('See More', 'Toggle should have text to see more');
|
|
|
|
assert
|
|
|
|
.dom('.overflow-ellipsis.is-closed')
|
|
|
|
.exists('Overflow div has is-closed class when more text to show');
|
|
|
|
await click('[data-test-readmore-toggle] button');
|
|
|
|
assert.dom('.overflow-ellipsis').exists('Div with overflow class still exists');
|
|
|
|
assert.dom('.overflow-ellipsis.is-closed').doesNotExist('Div with overflow class no longer is-closed');
|
|
|
|
assert.dom('[data-test-readmore-toggle]').hasText('See Less', 'Toggle should have text to see less');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it does not show show more button if parent is wider than content', async function (assert) {
|
2021-07-08 15:21:10 +00:00
|
|
|
this.set('description', 'Hello');
|
|
|
|
await render(hbs`
|
|
|
|
<div style="width: 150px">
|
|
|
|
<ReadMore>
|
|
|
|
{{this.description}}
|
|
|
|
</ReadMore>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
assert.dom('[data-test-readmore-content]').includesText(this.description);
|
|
|
|
assert.dom('[data-test-readmore-toggle]').doesNotExist('toggle exists');
|
|
|
|
assert.dom('.overflow-ellipsis').exists('Overflow div exists');
|
|
|
|
});
|
|
|
|
});
|