|
| 1 | +import AuMainHeader from '@appuniversum/ember-appuniversum/components/au-main-header'; |
| 2 | +import { getRootElement } from '@ember/test-helpers'; |
| 3 | +import { click } from '@ember/test-helpers'; |
| 4 | +import { render } from '@ember/test-helpers'; |
| 5 | +import { queryByText } from '@testing-library/dom'; |
| 6 | +import { setupRenderingTest } from 'ember-qunit'; |
| 7 | +import { module, test } from 'qunit'; |
| 8 | + |
| 9 | +module('Integration | Component | au-main-header', function (hooks) { |
| 10 | + setupRenderingTest(hooks); |
| 11 | + |
| 12 | + test('it requires an `@appTitle`', async function (assert) { |
| 13 | + await render( |
| 14 | + <template> |
| 15 | + {{! @glint-expect-error: @appTitle is required }} |
| 16 | + <AuMainHeader /> |
| 17 | + </template>, |
| 18 | + ); |
| 19 | + |
| 20 | + await render( |
| 21 | + <template><AuMainHeader @appTitle="Appuniversum" /></template>, |
| 22 | + ); |
| 23 | + |
| 24 | + const testContainer = getRootElement() as HTMLElement; |
| 25 | + const title = queryByText(testContainer, 'Appuniversum'); |
| 26 | + assert.dom(title).exists(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('it can display the title as a link by setting the `@homeRoute` argument', async function (assert) { |
| 30 | + await render( |
| 31 | + <template> |
| 32 | + <AuMainHeader @appTitle="Appuniversum" @homeRoute="application" /> |
| 33 | + </template>, |
| 34 | + ); |
| 35 | + |
| 36 | + const testContainer = getRootElement() as HTMLElement; |
| 37 | + const title = queryByText(testContainer, 'Appuniversum'); |
| 38 | + assert |
| 39 | + .dom(title) |
| 40 | + .hasTagName('a', 'The title element is a link if `@homeRoute` is set'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('it focuses the #main element after clicking the title link', async function (assert) { |
| 44 | + await render( |
| 45 | + <template> |
| 46 | + <AuMainHeader @appTitle="Appuniversum" @homeRoute="application" /> |
| 47 | + <main id="main" tabindex="-1">Main content</main> |
| 48 | + </template>, |
| 49 | + ); |
| 50 | + |
| 51 | + const testContainer = getRootElement() as HTMLElement; |
| 52 | + const title = queryByText(testContainer, 'Appuniversum') as HTMLElement; |
| 53 | + |
| 54 | + assert.dom('#main').isNotFocused(); |
| 55 | + await click(title); |
| 56 | + assert.dom('#main').isFocused(); |
| 57 | + }); |
| 58 | + |
| 59 | + test('it supports showing a link to the contact route', async function (assert) { |
| 60 | + await render( |
| 61 | + <template><AuMainHeader @appTitle="Appuniversum" /></template>, |
| 62 | + ); |
| 63 | + |
| 64 | + const testContainer = getRootElement() as HTMLElement; |
| 65 | + let contactLink = queryByText(testContainer, 'Contacteer ons'); |
| 66 | + assert.notOk( |
| 67 | + contactLink, |
| 68 | + "The contact link isn't displayed without the `@contactRoute` argument", |
| 69 | + ); |
| 70 | + |
| 71 | + await render( |
| 72 | + <template> |
| 73 | + <AuMainHeader @appTitle="Appuniversum" @contactRoute="application" /> |
| 74 | + </template>, |
| 75 | + ); |
| 76 | + |
| 77 | + contactLink = queryByText(testContainer, 'Contacteer ons'); |
| 78 | + |
| 79 | + assert.dom(contactLink).hasTagName('a'); |
| 80 | + }); |
| 81 | + |
| 82 | + test('it accepts extra block contents', async function (assert) { |
| 83 | + await render( |
| 84 | + <template> |
| 85 | + <AuMainHeader @appTitle="Appuniversum" data-test-main-header> |
| 86 | + extra header content |
| 87 | + </AuMainHeader> |
| 88 | + </template>, |
| 89 | + ); |
| 90 | + |
| 91 | + const testContainer = getRootElement() as HTMLElement; |
| 92 | + const extraHeaderContent = queryByText( |
| 93 | + testContainer, |
| 94 | + 'extra header content', |
| 95 | + ); |
| 96 | + assert.ok(extraHeaderContent); |
| 97 | + }); |
| 98 | +}); |
0 commit comments