From 6e47874be458450297746358594f45054f79ef59 Mon Sep 17 00:00:00 2001 From: Vincent Scavinner Date: Fri, 19 Jan 2024 10:17:53 +0100 Subject: [PATCH] feat: export constant for default selector --- .../src/modifiers/autofocus.ts | 4 +++- .../integration/modifiers/autofocus-test.ts | 23 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ember-autofocus-modifier/src/modifiers/autofocus.ts b/ember-autofocus-modifier/src/modifiers/autofocus.ts index 413ccf51..727cdcdb 100644 --- a/ember-autofocus-modifier/src/modifiers/autofocus.ts +++ b/ember-autofocus-modifier/src/modifiers/autofocus.ts @@ -23,7 +23,7 @@ interface ModifierArgs { }; } -export default modifier(function autofocus( +const autofocus = modifier(function autofocus( element: HTMLElement, [selector] = [DEFAULT_SELECTOR], { disabled } = { disabled: false }, @@ -78,3 +78,5 @@ export default modifier(function autofocus( } }; }); + +export { autofocus as default, DEFAULT_SELECTOR as defaultSelector }; diff --git a/test-app/tests/integration/modifiers/autofocus-test.ts b/test-app/tests/integration/modifiers/autofocus-test.ts index e53ed3dd..06725a5d 100644 --- a/test-app/tests/integration/modifiers/autofocus-test.ts +++ b/test-app/tests/integration/modifiers/autofocus-test.ts @@ -1,8 +1,13 @@ import { find, render, tab } from '@ember/test-helpers'; import { setupRenderingTest } from 'ember-qunit'; import { module, test } from 'qunit'; - import { hbs } from 'ember-cli-htmlbars'; +import type { TestContext as TestContextBase } from '@ember/test-helpers'; +import { defaultSelector } from 'ember-autofocus-modifier/modifiers/autofocus'; + +interface TestContext extends TestContextBase { + defaultSelector: string; +} module('Integration | Modifier | autofocus', function (hooks) { setupRenderingTest(hooks); @@ -179,9 +184,11 @@ module('Integration | Modifier | autofocus', function (hooks) { .isNotFocused('The third non related input are not focused'); }); - test('should not focus due to disabled parameter set to true without providing a selector', async function (assert) { - await render(hbs` -
+ test('should not focus due to disabled parameter set to true without providing a selector', async function (this: TestContext, assert) { + this.defaultSelector = defaultSelector; + + await render(hbs` +
this is not a focusable element @@ -204,9 +211,11 @@ module('Integration | Modifier | autofocus', function (hooks) { .isNotFocused('The third non related input are not focused'); }); - test('should focus due to disabled parameter set to false', async function (assert) { - await render(hbs` -
+ test('should focus due to disabled parameter set to false', async function (this: TestContext, assert) { + this.defaultSelector = defaultSelector; + + await render(hbs` +
this is not a focusable element