Sha256: 5a3ba7580551e28d74a3cab5b7847502a65276486622157cd0d4a42d8358b313

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

/**
@module ember
*/
import { focus, fireEvent } from '../events';
import isFormControl from './-is-form-control';

/**
  Fills in an input element with some text.

  Example:

  ```javascript
  fillIn('#email', 'you@example.com').then(function() {
    // assert something
  });
  ```

  @method fillIn
  @param {String} selector jQuery selector finding an input element on the DOM
  to fill text with
  @param {String} text text to place inside the input element
  @return {RSVP.Promise<undefined>}
  @public
*/
export default function fillIn(app, selector, contextOrText, text) {
  let $el, el, context;
  if (text === undefined) {
    text = contextOrText;
  } else {
    context = contextOrText;
  }
  $el = app.testHelpers.findWithAssert(selector, context);
  el = $el[0];
  focus(el);

  if (isFormControl(el)) {
    el.value = text;
  } else {
    el.innerHTML = text;
  }

  fireEvent(el, 'input');
  fireEvent(el, 'change');

  return app.testHelpers.wait();
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/ember-testing/lib/helpers/fill_in.js
discourse-ember-source-3.5.1.1 dist/es/ember-testing/lib/helpers/fill_in.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-testing/lib/helpers/fill_in.js