Skip to content

Commit

Permalink
Disallow edit readonly form controls
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0gr committed Mar 9, 2020
1 parent 6c063ff commit 85bf11d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addon-test-support/@ember/test-helpers/dom/fill-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export default function fillIn(target: Target, text: string): Promise<void> {
throw new Error(`Can not \`fillIn\` disabled ${element}`);
}

if ('readOnly' in element && element.readOnly) {
throw new Error(`Can not \`fillIn\` readonly ${element}`);
}

__focus__(element);

element.value = text;
Expand Down
4 changes: 4 additions & 0 deletions addon-test-support/@ember/test-helpers/dom/type-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default function typeIn(target: Target, text: string, options: Options =
throw new Error(`Can not \`typeIn\` disabled ${element}`);
}

if ('readOnly' in element && element.readOnly) {
throw new Error(`Can not \`typeIn\` readonly ${element}`);
}

__focus__(element);

let { delay = 50 } = options;
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/dom/fill-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ module('DOM Helper: fillIn', function(hooks) {
);
});

test('filling in a readonly element', async function(assert) {
element = buildInstrumentedElement('input');
element.setAttribute('readonly', true);

await setupContext(context);
assert.rejects(
fillIn(`#${element.id}`, 'foo'),
new Error('Can not `fillIn` readonly [object HTMLInputElement]')
);
});

test('rejects if selector is not found', async function(assert) {
element = buildInstrumentedElement('div');

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/dom/type-in-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ module('DOM Helper: typeIn', function(hooks) {
);
});

test('typing in a readonly element', async function(assert) {
element = buildInstrumentedElement('input');
element.setAttribute('readonly', '');

await setupContext(context);
assert.rejects(
typeIn(`#${element.id}`, 'foo'),
new Error('Can not `typeIn` readonly [object HTMLInputElement]')
);
});

test('rejects if selector is not found', async function(assert) {
element = buildInstrumentedElement('div');

Expand Down

0 comments on commit 85bf11d

Please sign in to comment.