diff --git a/addon/components/au-form-row.gjs b/addon/components/au-form-row.gts similarity index 67% rename from addon/components/au-form-row.gjs rename to addon/components/au-form-row.gts index c7ba929d2..a4ab8dc4d 100644 --- a/addon/components/au-form-row.gjs +++ b/addon/components/au-form-row.gts @@ -1,6 +1,16 @@ import Component from '@glimmer/component'; -export default class AuFormRow extends Component { +export interface AuFormRowSignature { + Args: { + alignment?: 'inline' | 'pre' | 'post'; + }; + Blocks: { + default: []; + }; + Element: HTMLDivElement; +} + +export default class AuFormRow extends Component { get alignment() { if (this.args.alignment == 'inline') return 'au-c-form-row--inline'; if (this.args.alignment == 'pre') diff --git a/addon/components/au-heading.gjs b/addon/components/au-heading.gts similarity index 83% rename from addon/components/au-heading.gjs rename to addon/components/au-heading.gts index 81c59426d..1c7dbe4c8 100644 --- a/addon/components/au-heading.gjs +++ b/addon/components/au-heading.gts @@ -3,7 +3,18 @@ import Component from '@glimmer/component'; // TODO: replace these with the named imports from ember-truth-helpers v4 once our dependencies support that version import eq from 'ember-truth-helpers/helpers/eq'; -export default class AuHeading extends Component { +export interface AuHeadingSignature { + Args: { + level?: '1' | '2' | '3' | '4' | '5' | '6'; + skin?: '1' | '2' | '3' | '4' | '5' | '6' | 'functional'; + }; + Blocks: { + default: []; + }; + Element: HTMLHeadingElement; +} + +export default class AuHeading extends Component { get skin() { if (this.args.skin == '1') return 'au-c-heading--1'; if (this.args.skin == '2') return 'au-c-heading--2'; diff --git a/addon/components/au-help-text.gjs b/addon/components/au-help-text.gts similarity index 73% rename from addon/components/au-help-text.gjs rename to addon/components/au-help-text.gts index d82df44d8..199ebad76 100644 --- a/addon/components/au-help-text.gjs +++ b/addon/components/au-help-text.gts @@ -1,6 +1,19 @@ import Component from '@glimmer/component'; -export default class AuHelpText extends Component { +export interface AuHelpTextSignature { + Args: { + skin?: 'secondary' | 'tertiary'; + size?: 'normal' | 'large'; + error?: boolean; + warning?: boolean; + }; + Blocks: { + default: []; + }; + Element: HTMLSpanElement; +} + +export default class AuHelpText extends Component { get skin() { if (this.args.skin == 'secondary') return 'au-c-help-text--secondary'; if (this.args.skin == 'tertiary') return 'au-c-help-text--tertiary'; diff --git a/addon/template-registry.ts b/addon/template-registry.ts index cb2c377d4..93edd2135 100644 --- a/addon/template-registry.ts +++ b/addon/template-registry.ts @@ -13,6 +13,9 @@ import type AuCheckboxGroup from '@appuniversum/ember-appuniversum/components/au import type AuContentHeader from '@appuniversum/ember-appuniversum/components/au-content-header'; import type AuContent from '@appuniversum/ember-appuniversum/components/au-content'; import type AuDateInput from '@appuniversum/ember-appuniversum/components/au-date-input'; +import type AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row'; +import type AuHeading from '@appuniversum/ember-appuniversum/components/au-heading'; +import type AuHelpText from '@appuniversum/ember-appuniversum/components/au-help-text'; import type AuHr from '@appuniversum/ember-appuniversum/components/au-hr'; import type AuIcon from '@appuniversum/ember-appuniversum/components/au-icon'; import type AuInput from '@appuniversum/ember-appuniversum/components/au-input'; @@ -41,6 +44,9 @@ export default interface AppuniversumRegistry { AuContentHeader: typeof AuContentHeader; AuContent: typeof AuContent; AuDateInput: typeof AuDateInput; + AuFormRow: typeof AuFormRow; + AuHeading: typeof AuHeading; + AuHelpText: typeof AuHelpText; AuHr: typeof AuHr; AuIcon: typeof AuIcon; AuInput: typeof AuInput; diff --git a/tests/integration/components/au-form-row-test.gts b/tests/integration/components/au-form-row-test.gts new file mode 100644 index 000000000..c04392790 --- /dev/null +++ b/tests/integration/components/au-form-row-test.gts @@ -0,0 +1,18 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row'; + +module('Integration | Component | au-form-row', function (hooks) { + setupRenderingTest(hooks); + + test('it accepts block content', async function (assert) { + await render( + , + ); + + assert.dom('[data-test-form-row]').hasText('Form row'); + }); +}); diff --git a/tests/integration/components/au-heading-test.gts b/tests/integration/components/au-heading-test.gts new file mode 100644 index 000000000..6ce67c875 --- /dev/null +++ b/tests/integration/components/au-heading-test.gts @@ -0,0 +1,82 @@ +import AuHeading, { + type AuHeadingSignature, +} from '@appuniversum/ember-appuniversum/components/au-heading'; +import { settled } from '@ember/test-helpers'; +import { render } from '@ember/test-helpers'; +import { tracked } from '@glimmer/tracking'; +import { setupRenderingTest } from 'ember-qunit'; +import { module, test } from 'qunit'; + +module('Integration | Component | au-heading', function (hooks) { + setupRenderingTest(hooks); + + test('it accepts block content and extra attributes', async function (assert) { + await render( + , + ); + + assert.dom('[data-test-heading]').hasText('Some title'); + }); + + test('it defaults to a h1 element', async function (assert) { + await render( + , + ); + + assert.dom('h1').exists('it defaults to h1'); + }); + + test('it has a `@level` argument that can be used to set the h* element', async function (assert) { + class TestState { + @tracked level?: AuHeadingSignature['Args']['level']; + } + + const state = new TestState(); + state.level = '1'; + + await render( + , + ); + + assert.dom('h1').exists(); + + state.level = '2'; + await settled(); + assert.dom('h2').exists(); + + state.level = '3'; + await settled(); + assert.dom('h3').exists(); + + state.level = '4'; + await settled(); + assert.dom('h4').exists(); + + state.level = '5'; + await settled(); + assert.dom('h5').exists(); + + state.level = '6'; + await settled(); + assert.dom('h6').exists(); + + // @ts-expect-error: invalid level values are possible in projects that don't use Glint + state.level = 'invalid level'; + await settled(); + assert + .dom('h1') + .exists('it falls back to h1 if the level value is invalid'); + }); +}); diff --git a/tests/integration/components/au-heading-test.js b/tests/integration/components/au-heading-test.js deleted file mode 100644 index 7e7b3b11f..000000000 --- a/tests/integration/components/au-heading-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Component | au-heading', function (hooks) { - setupRenderingTest(hooks); - - test('it renders', async function (assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); - - await render(hbs``); - - assert.dom(this.element).hasText(''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.dom(this.element).hasText('template block text'); - }); -}); diff --git a/tests/integration/components/au-help-text-test.gts b/tests/integration/components/au-help-text-test.gts new file mode 100644 index 000000000..bb63b4246 --- /dev/null +++ b/tests/integration/components/au-help-text-test.gts @@ -0,0 +1,20 @@ +import AuHelpText from '@appuniversum/ember-appuniversum/components/au-help-text'; +import { render } from '@ember/test-helpers'; +import { setupRenderingTest } from 'ember-qunit'; +import { module, test } from 'qunit'; + +module('Integration | Component | au-help-text', function (hooks) { + setupRenderingTest(hooks); + + test('it accepts block content and extra attributes', async function (assert) { + await render( + , + ); + + assert.dom('[data-test-help-text]').hasText('Some help text'); + }); +}); diff --git a/tests/integration/components/au-help-text-test.js b/tests/integration/components/au-help-text-test.js deleted file mode 100644 index d8377561d..000000000 --- a/tests/integration/components/au-help-text-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import { module, test } from 'qunit'; -import { setupRenderingTest } from 'ember-qunit'; -import { render } from '@ember/test-helpers'; -import { hbs } from 'ember-cli-htmlbars'; - -module('Integration | Component | au-help-text', function (hooks) { - setupRenderingTest(hooks); - - test('it renders', async function (assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); - - await render(hbs``); - - assert.dom(this.element).hasText(''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.dom(this.element).hasText('template block text'); - }); -}); diff --git a/tests/integration/components/loose-mode-test.ts b/tests/integration/components/loose-mode-test.ts index a778aa075..7ab7ecf8c 100644 --- a/tests/integration/components/loose-mode-test.ts +++ b/tests/integration/components/loose-mode-test.ts @@ -107,6 +107,26 @@ module('Integration | Component | Loose mode', function (hooks) { assert.dom('[data-test-date-input]').exists(); }); + test('`` resolves in loose mode', async function (assert) { + await render(hbs``); + + assert.dom('[data-test-form-row]').exists(); + }); + + test('`` resolves in loose mode', async function (assert) { + await render(hbs`Some title`); + + assert.dom('[data-test-heading]').exists(); + }); + + test('`` resolves in loose mode', async function (assert) { + await render( + hbs`Some help text`, + ); + + assert.dom('[data-test-help-text]').exists(); + }); + test('`` resolves in loose mode', async function (assert) { await render(hbs``);