|
1 |
| -import { module, test } from 'qunit'; |
2 |
| -import { setupRenderingTest } from 'ember-qunit'; |
3 |
| -import { render } from '@ember/test-helpers'; |
4 | 1 | import AuLoader from '@appuniversum/ember-appuniversum/components/au-loader';
|
| 2 | +import { getRootElement, render } from '@ember/test-helpers'; |
| 3 | +import { queryByText } from '@testing-library/dom'; |
| 4 | +import { hasDeprecationStartingWith } from 'dummy/tests/helpers/deprecations'; |
| 5 | +import { setupRenderingTest } from 'ember-qunit'; |
| 6 | +import { module, test } from 'qunit'; |
5 | 7 |
|
6 | 8 | module('Integration | Component | au-loader', function (hooks) {
|
7 | 9 | setupRenderingTest(hooks);
|
8 | 10 |
|
| 11 | + test('it uses the block contents as the loading message', async function (assert) { |
| 12 | + await render( |
| 13 | + <template> |
| 14 | + <AuLoader> |
| 15 | + Pagina is aan het laden |
| 16 | + </AuLoader> |
| 17 | + </template>, |
| 18 | + ); |
| 19 | + |
| 20 | + assert.dom().hasText('Pagina is aan het laden'); |
| 21 | + assert.false(hasDeprecationStartingWith('[AuLoader]')); |
| 22 | + }); |
| 23 | + |
| 24 | + test('it supports visually hiding the loading text', async function (assert) { |
| 25 | + await render( |
| 26 | + <template> |
| 27 | + <AuLoader @hideMessage={{true}}> |
| 28 | + Pagina is aan het laden |
| 29 | + </AuLoader> |
| 30 | + </template>, |
| 31 | + ); |
| 32 | + |
| 33 | + const root = getRootElement() as HTMLElement; |
| 34 | + const text = queryByText(root, 'Pagina is aan het laden') as HTMLElement; |
| 35 | + |
| 36 | + // Hacky way to test if the text is visible. |
| 37 | + // `assert.dom(text).isNotVisible()` doesn't work here because of the styles we use for the au-u-hidden-visually class. |
| 38 | + assert.true(text.offsetHeight <= 1); |
| 39 | + assert.true(text.offsetWidth <= 1); |
| 40 | + assert.false(hasDeprecationStartingWith('[AuLoader]')); |
| 41 | + }); |
| 42 | + |
9 | 43 | test('it renders a hidden loading text for screen readers', async function (assert) {
|
10 | 44 | await render(<template><AuLoader /></template>);
|
11 | 45 |
|
12 | 46 | assert.dom().hasText('Aan het laden');
|
| 47 | + assert.true(showsDeprecationMessage()); |
13 | 48 | });
|
14 | 49 |
|
15 | 50 | test('it supports rendering a custom hidden loading text', async function (assert) {
|
16 | 51 | await render(<template><AuLoader @message="Loading" /></template>);
|
17 | 52 |
|
18 | 53 | assert.dom().hasText('Loading');
|
| 54 | + assert.true(showsDeprecationMessage()); |
19 | 55 | });
|
20 | 56 |
|
21 | 57 | test('it supports disabling the hidden message', async function (assert) {
|
22 | 58 | await render(<template><AuLoader @disableMessage={{true}} /></template>);
|
23 | 59 |
|
24 | 60 | assert.dom().hasNoText();
|
| 61 | + assert.true(showsDeprecationMessage()); |
| 62 | + }); |
| 63 | + |
| 64 | + test('@padding shows a deprecation', async function (assert) { |
| 65 | + await render(<template><AuLoader @padding="small" /></template>); |
| 66 | + |
| 67 | + assert.true(showsDeprecationMessage()); |
25 | 68 | });
|
26 | 69 | });
|
| 70 | + |
| 71 | +function showsDeprecationMessage() { |
| 72 | + return hasDeprecationStartingWith( |
| 73 | + '[AuLoader] This version of the `AuLoader` component is deprecated', |
| 74 | + ); |
| 75 | +} |
0 commit comments