jeudi 3 décembre 2015

Ember acceptance test for chosen-select

Chosen is working great for me but I cannot figure out how to get my acceptance test to send in the value on the form submit.

Handlebars template:

<form>
  {{#ember-chosen value=country}}
    {{#each countries as |country|}}
      <option value={{country}}>{{country}}</option>
    {{/each}}
  {{/ember-chosen}}
  {{#link-to 'countries.show' (query-params country=country) tagName='button' type='submit' replace=true class="submit__button"}}Search{{/link-to}}
</form>

Acceptance test:

test 'Searching for a country', (assert) ->
  visit '/search'
  find('.chosen-select').val('USA')
  find('.chosen-select').trigger('chosen:updated')
  click('.submit__button')
  andThen ->
    assert.equal find(".chosen-select :selected").text(), "USA"

This fails because on submit country is not even passed in as a query param, but only in the test.

The same thing happens if I do it in the console. If I open my console and do:

$('.chosen-select').val('USA')
$('.chosen-select').trigger('chosen:updated')

then the selection updates before my eyes! But then clicking submit produces the same results as the test, that is, the country is not passed into the query-params.

Clicking "USA" from the dropdown however, then clicking submit, works perfectly.




Aucun commentaire:

Enregistrer un commentaire