ember-cli-page-object icon indicating copy to clipboard operation
ember-cli-page-object copied to clipboard

Serialization of query params in visit not working quite as expected

Open benshine opened this issue 9 years ago • 1 comments

Query param serialization is just a tiny bit weird for a particular tricky query param I've got. I wouldn't quite call this a bug, but an example in the documentation would make it clearer how I should be doing it.

Page object is:

export default PageObject.create({
  visit: visitable('/students/:studentId/milestones'),
...

Then I try to visit it with a query param that is a rather nasty serialization. On the controller it's specified as

  subjects: Ember.A().pushObjects(['habits', 'mathematics', 'english-language-arts']),

which means that the URL in the browser ends up looking like this, for a normal successful page load. http://localhost:9000/students/someST/milestones?subjects=%5B%22mathematics%22%2C%22habits%22%5D

I tried to make that same visit using the query object; it used to work as a normal Ember test helper like this:

      // visit(`/students/${ALEC_BARGEN_STUDENT_ID}/milestones?subjects=%5B"mathematics"%2C"habits"%5D`);

To get the same result using ec-page-objects, I ended up doing this:

      overviewPageObject = MilestonesOverviewPageObject.visit({
        studentId: ALEC_BARGEN_STUDENT_ID,
        subjects: '["mathematics","habits"]'
      });

I would have expected I could do either the array:

        subjects: ["mathematics","habits"]

or the serialized string:

   subjects: '%5B"mathematics"%2C"habits"%5D'

But neither of those worked, giving various parse errors like this:

 SyntaxError: Unexpected token m in JSON at position 0
   at Object.parse (native)
   at Class.deserializeQueryParam (assets/vendor.js:39930:55)
SyntaxError: Unexpected token % in JSON at position 0
   at Object.parse (native)
   at Class.deserializeQueryParam (assets/vendor.js:39930:55)

benshine avatar Jul 05 '16 23:07 benshine

I think this is related to #202

san650 avatar Jul 06 '16 15:07 san650