Skip to content

Commit

Permalink
Merge pull request #532 from qonto/export-default-selector-const
Browse files Browse the repository at this point in the history
feat: export constant for default selector
  • Loading branch information
vscav authored Jan 19, 2024
2 parents 177c78a + 6e47874 commit 15a54ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion ember-autofocus-modifier/src/modifiers/autofocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ModifierArgs {
};
}

export default modifier<ModifierArgs>(function autofocus(
const autofocus = modifier<ModifierArgs>(function autofocus(
element: HTMLElement,
[selector] = [DEFAULT_SELECTOR],
{ disabled } = { disabled: false },
Expand Down Expand Up @@ -78,3 +78,5 @@ export default modifier<ModifierArgs>(function autofocus(
}
};
});

export { autofocus as default, DEFAULT_SELECTOR as defaultSelector };
23 changes: 16 additions & 7 deletions test-app/tests/integration/modifiers/autofocus-test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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`
<div {{autofocus "input" disabled=true}}>
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<TestContext>(hbs`
<div {{autofocus this.defaultSelector disabled=true}}>
<span>this is not a focusable element</span>
<button type="button" data-test-button>this is a button</button>
<input id="1" data-test-input-1 />
Expand All @@ -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`
<div {{autofocus "input" disabled=false}}>
test('should focus due to disabled parameter set to false', async function (this: TestContext, assert) {
this.defaultSelector = defaultSelector;

await render<TestContext>(hbs`
<div {{autofocus this.defaultSelector disabled=false}}>
<span>this is not a focusable element</span>
<button type="button" data-test-button>this is a button</button>
<input id="1" data-test-input-1 />
Expand Down

0 comments on commit 15a54ee

Please sign in to comment.