|
| 1 | +import AuHeading, { |
| 2 | + type AuHeadingSignature, |
| 3 | +} from '@appuniversum/ember-appuniversum/components/au-heading'; |
| 4 | +import { settled } from '@ember/test-helpers'; |
| 5 | +import { render } from '@ember/test-helpers'; |
| 6 | +import { tracked } from '@glimmer/tracking'; |
| 7 | +import { setupRenderingTest } from 'ember-qunit'; |
| 8 | +import { module, test } from 'qunit'; |
| 9 | + |
| 10 | +module('Integration | Component | au-heading', function (hooks) { |
| 11 | + setupRenderingTest(hooks); |
| 12 | + |
| 13 | + test('it accepts block content and extra attributes', async function (assert) { |
| 14 | + await render( |
| 15 | + <template> |
| 16 | + <AuHeading data-test-heading> |
| 17 | + Some title |
| 18 | + </AuHeading> |
| 19 | + </template>, |
| 20 | + ); |
| 21 | + |
| 22 | + assert.dom('[data-test-heading]').hasText('Some title'); |
| 23 | + }); |
| 24 | + |
| 25 | + test('it defaults to a h1 element', async function (assert) { |
| 26 | + await render( |
| 27 | + <template> |
| 28 | + <AuHeading> |
| 29 | + Some title |
| 30 | + </AuHeading> |
| 31 | + </template>, |
| 32 | + ); |
| 33 | + |
| 34 | + assert.dom('h1').exists('it defaults to h1'); |
| 35 | + }); |
| 36 | + |
| 37 | + test('it has a `@level` argument that can be used to set the h* element', async function (assert) { |
| 38 | + class TestState { |
| 39 | + @tracked level?: AuHeadingSignature['Args']['level']; |
| 40 | + } |
| 41 | + |
| 42 | + const state = new TestState(); |
| 43 | + state.level = '1'; |
| 44 | + |
| 45 | + await render( |
| 46 | + <template> |
| 47 | + <AuHeading @level={{state.level}}> |
| 48 | + Some title |
| 49 | + </AuHeading> |
| 50 | + </template>, |
| 51 | + ); |
| 52 | + |
| 53 | + assert.dom('h1').exists(); |
| 54 | + |
| 55 | + state.level = '2'; |
| 56 | + await settled(); |
| 57 | + assert.dom('h2').exists(); |
| 58 | + |
| 59 | + state.level = '3'; |
| 60 | + await settled(); |
| 61 | + assert.dom('h3').exists(); |
| 62 | + |
| 63 | + state.level = '4'; |
| 64 | + await settled(); |
| 65 | + assert.dom('h4').exists(); |
| 66 | + |
| 67 | + state.level = '5'; |
| 68 | + await settled(); |
| 69 | + assert.dom('h5').exists(); |
| 70 | + |
| 71 | + state.level = '6'; |
| 72 | + await settled(); |
| 73 | + assert.dom('h6').exists(); |
| 74 | + |
| 75 | + // @ts-expect-error: invalid level values are possible in projects that don't use Glint |
| 76 | + state.level = 'invalid level'; |
| 77 | + await settled(); |
| 78 | + assert |
| 79 | + .dom('h1') |
| 80 | + .exists('it falls back to h1 if the level value is invalid'); |
| 81 | + }); |
| 82 | +}); |
0 commit comments