Skip to content

Commit

Permalink
modernize input tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 28, 2024
1 parent b18531d commit de07242
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
moduleFor,
RenderingTestCase,
runDestroy,
runTask,
testUnless,
} from 'internal-test-helpers';
import { set } from '@ember/object';
import { DEPRECATIONS } from '../../../../deprecations';
import { moduleFor, RenderingTestCase, runDestroy, runTask } from 'internal-test-helpers';
import { action, set } from '@ember/object';

class InputRenderingTest extends RenderingTestCase {
$input() {
Expand Down Expand Up @@ -287,24 +280,16 @@ moduleFor(
// this.assertSelectionRange(8, 8); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
}

[`${testUnless(
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isRemoved
)} sends an action with \`<Input @enter={{action "foo"}} />\` when <enter> is pressed`](
[`@test sends an action with \`<Input @enter={{this.foo}} />\` when <enter> is pressed`](
assert
) {
assert.expect(3);
expectDeprecation(
/Usage of the `\(action\)` helper is deprecated./,
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isEnabled
);
assert.expect(2);

this.render(`<Input @enter={{action 'foo'}} />`, {
actions: {
foo(value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
},
},
this.render(`<Input @enter={{this.foo}} />`, {
foo: action(function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
}),
});

this.triggerEvent('keyup', {
Expand All @@ -327,24 +312,16 @@ moduleFor(
});
}

[`${testUnless(
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isRemoved
)} sends an action with \`<Input @escape-press={{action "foo"}} />\` when <escape> is pressed`](
['@test sends an action with `<Input @escape-press={{this.foo}} />` when <escape> is pressed'](
assert
) {
assert.expect(3);
expectDeprecation(
/Usage of the `\(action\)` helper is deprecated./,
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isEnabled
);
assert.expect(2);

this.render(`<Input @escape-press={{action 'foo'}} />`, {
actions: {
foo(value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
},
},
this.render(`<Input @escape-press={{this.foo}} />`, {
foo: action(function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
}),
});

this.triggerEvent('keyup', { key: 'Escape' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
RenderingTestCase,
moduleFor,
runDestroy,
runTask,
testUnless,
} from 'internal-test-helpers';
import { RenderingTestCase, moduleFor, runDestroy, runTask } from 'internal-test-helpers';

import { set } from '@ember/object';
import { DEPRECATIONS } from '../../../../deprecations';
import { action, set } from '@ember/object';

class InputRenderingTest extends RenderingTestCase {
$input() {
Expand Down Expand Up @@ -156,22 +149,14 @@ moduleFor(
// this.assertSelectionRange(8, 8); //NOTE: this fails in IE, the range is 0 -> 0 (TEST_SUITE=sauce)
}

[`${testUnless(
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isRemoved
)} sends an action with \`{{input enter=(action "foo")}}\` when <enter> is pressed`](assert) {
assert.expect(3);
expectDeprecation(
/Usage of the `\(action\)` helper is deprecated./,
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isEnabled
);

this.render(`{{input enter=(action 'foo')}}`, {
actions: {
foo(value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
},
},
['@test sends an action with `{{input enter=this.foo}}` when <enter> is pressed'](assert) {
assert.expect(2);

this.render(`{{input enter=this.foo}}`, {
foo: action(function (value, event) {
assert.ok(true, 'action was triggered');
assert.ok(event instanceof Event, 'Native event was passed');
}),
});

this.triggerEvent('keyup', {
Expand Down

0 comments on commit de07242

Please sign in to comment.