diff --git a/floating-labels/package.json b/floating-labels/package.json index 8f0c812..98bf4b0 100644 --- a/floating-labels/package.json +++ b/floating-labels/package.json @@ -52,7 +52,6 @@ "@glint/core": "^0.9.2", "@glint/environment-ember-loose": "^0.9.2", "@rollup/plugin-babel": "^5.3.1", - "@types/ember-qunit": "^6.1.1", "@types/ember-resolver": "^5.0.11", "@types/ember__application": "^4.0.0", "@types/ember__array": "^4.0.1", diff --git a/floating-labels/src/components/fl-input/index.ts b/floating-labels/src/components/fl-input/index.ts index cfeb76d..530f821 100644 --- a/floating-labels/src/components/fl-input/index.ts +++ b/floating-labels/src/components/fl-input/index.ts @@ -41,7 +41,7 @@ export interface FlInputArgs { id?: string; name?: string; type?: HTMLInputType; - errors?: string[] | string; + errors?: string | string[] | (string | string[])[]; } interface BaseFloatingSignature { @@ -92,11 +92,19 @@ export abstract class BaseFloatingLabelClass< } get firstError(): string | null { - return Array.isArray(this.args.errors) - ? this.args.errors[0] - : typeof this.args.errors === 'string' - ? this.args.errors - : null; + const isArray = Array.isArray(this.args.errors); + + if (this.args.errors && isArray) { + if (Array.isArray(this.args.errors?.[0])) { + return this.args.errors[0][0]; + } else { + return this.args.errors[0]; + } + } else if (typeof this.args.errors === 'string') { + return this.args.errors; + } else { + return null; + } } get placeholder(): string | undefined { diff --git a/test-app/package.json b/test-app/package.json index 013b080..da04d74 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -28,7 +28,7 @@ "devDependencies": { "@ember/optional-features": "^2.0.0", "@ember/render-modifiers": "^2.0.4", - "@ember/test-helpers": "^2.9.1", + "@ember/test-helpers": "^2.9.3", "@embroider/compat": "^1.8.3", "@embroider/core": "^1.8.3", "@embroider/test-setup": "^1.7.1", @@ -39,7 +39,6 @@ "@glimmer/tracking": "^1.1.2", "@glint/core": "^0.9.2", "@glint/environment-ember-loose": "^0.9.2", - "@types/ember-qunit": "^6.1.1", "@types/ember-resolver": "^5.0.11", "@types/ember__application": "^4.0.0", "@types/ember__array": "^4.0.1", diff --git a/test-app/tests/integration/components/fl-input-test.ts b/test-app/tests/integration/components/fl-input-test.ts index 716dce9..9564e2e 100644 --- a/test-app/tests/integration/components/fl-input-test.ts +++ b/test-app/tests/integration/components/fl-input-test.ts @@ -12,13 +12,32 @@ module('Integration | Component | fl-input', function (hooks) { test('it renders', async function (assert) { await render(hbs``); await a11yAudit(); - assert.strictEqual(this.element.textContent?.trim(), 'test'); + assert.dom().hasText('test'); }); test('Type attribute is set on the when using ', async function (assert) { await render(hbs``); await a11yAudit(); - const inputElement = this.element.querySelector('input') as HTMLInputElement; - assert.strictEqual(inputElement.type, 'password'); + assert.dom('input').hasAttribute('type', 'password'); + }); + + test('Single error works', async function (assert) { + await render(hbs``); + await a11yAudit(); + assert.dom().hasText('test'); + }); + + test('Array error works', async function (assert) { + this.set('errors', ['test', 'test2']); + await render(hbs``); + await a11yAudit(); + assert.dom().hasText('test'); + }); + + test('Array of Arrays error works', async function (assert) { + this.set('errors', [['test', 'test2']]); + await render(hbs``); + await a11yAudit(); + assert.dom().hasText('test'); }); }); diff --git a/test-app/tests/integration/components/fl-select-test.ts b/test-app/tests/integration/components/fl-select-test.ts index 76439e7..f5641ed 100644 --- a/test-app/tests/integration/components/fl-select-test.ts +++ b/test-app/tests/integration/components/fl-select-test.ts @@ -15,6 +15,6 @@ module('Integration | Component | fl-select', function (hooks) { await render(hbs``); await a11yAudit(); - assert.strictEqual(this.element.textContent?.trim(), 'test'); + assert.dom().hasText('test'); }); }); diff --git a/test-app/tests/integration/components/fl-textarea-test.ts b/test-app/tests/integration/components/fl-textarea-test.ts index ab21636..8de7416 100644 --- a/test-app/tests/integration/components/fl-textarea-test.ts +++ b/test-app/tests/integration/components/fl-textarea-test.ts @@ -15,6 +15,6 @@ module('Integration | Component | fl-textarea', function (hooks) { await render(hbs``); await a11yAudit(); - assert.strictEqual(this.element.textContent?.trim(), 'test'); + assert.dom().hasText('test'); }); }); diff --git a/yarn.lock b/yarn.lock index 32df44a..4bbb9a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1170,7 +1170,7 @@ dependencies: ember-cli-babel "^7.26.6" -"@ember/test-helpers@^2.9.1": +"@ember/test-helpers@^2.9.3": version "2.9.3" resolved "https://registry.yarnpkg.com/@ember/test-helpers/-/test-helpers-2.9.3.tgz#c2a9d6ab1c367af92cf1a334f97eb19b8e06e6e1" integrity sha512-ejVg4Dj+G/6zyLvQsYOvmGiOLU6AS94tY4ClaO1E2oVvjjtVJIRmVLFN61I+DuyBg9hS3cFoPjQRTZB9MRIbxQ== @@ -2104,13 +2104,6 @@ resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080" integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw== -"@types/ember-qunit@^6.1.1": - version "6.1.1" - resolved "https://registry.yarnpkg.com/@types/ember-qunit/-/ember-qunit-6.1.1.tgz#8350944aced173024135d9ae2b7e55105c44564e" - integrity sha512-1g5A3vPKhvB/CuN/EP9rBLXYaJOjzKyLYWeBtNDEQNkTuG1dAo/Hg0CCixgbBgLlzaDP8mR/n1xpg8HqQ8SUKg== - dependencies: - ember-qunit "*" - "@types/ember-resolver@*", "@types/ember-resolver@^5.0.11": version "5.0.11" resolved "https://registry.yarnpkg.com/@types/ember-resolver/-/ember-resolver-5.0.11.tgz#db931fb5c2d6bda4e29adea132fb48c7ed17aa62" @@ -6267,7 +6260,7 @@ ember-page-title@^7.0.0: dependencies: ember-cli-babel "^7.26.6" -ember-qunit@*, ember-qunit@^6.1.1: +ember-qunit@^6.1.1: version "6.1.1" resolved "https://registry.yarnpkg.com/ember-qunit/-/ember-qunit-6.1.1.tgz#9e2b7835239e7ffd176e08e536975f66e59f75e5" integrity sha512-3/jCpoecltFV6vm7GCtSDNRxBzWx96nP+QrbereJAnioSaGeLe+slKL3l80mGzMYDTvn7ESobZ+Ba+OQ1vMMKQ==