Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handleQuery not working as expected in acceptance test #174

Closed
dillonwelch opened this issue Feb 18, 2016 · 7 comments
Closed

handleQuery not working as expected in acceptance test #174

dillonwelch opened this issue Feb 18, 2016 · 7 comments

Comments

@dillonwelch
Copy link
Contributor

I have a dashboard with three tabs:

  • All data (default tab)
  • Data of type A
  • Data of type B

The default tab uses findAll and the filtered tabs use query on the type field.

I'm trying to write a test that does the following:

  • Visit the default view
  • Click on tab A
  • Assert that only data of type A shows
  • Click on tab B
  • Assert that only data on tybe B shows

I have a TestHelper.handleFindAll call that sets up 2 models for the main tab. I have two TestHelper.handleQuery calls (one for type 'A' and one for type 'B') that use withParams and returnsModels.

When I run the test and click on tab A, I get an error that there are 4 entries on the dashboard instead of 1.

I am using version 2.1.3 of ember-data-factory-guy.

@danielspaniel
Copy link
Collaborator

This is hard for me to fix/understand since I would have to check the route to see what the store.query is returning ( but you could? ) then I have to see a bit more of what is going on. are you on screenhero?

@dillonwelch
Copy link
Contributor Author

This is company code, so I can't show it to you directly unfortunately.

Can you point me to a resource where I can find out how to look at the data in store.query? I'm new to Ember :)

@danielspaniel
Copy link
Collaborator

are those models in A tab and B tab and default ( All ) .. basically all the same models? if so you don't need to query again. but for inspection in the route to see what your getting back

in the route where you have things like

return this.store.findAll('user');

or

 return this.store.query('user', {name:'Bob'});

you can do this:

let promise = this.store.findAll('user');
promise.then( (things)=> {
   console.log(things.mapBy('id'));
});
return promise;
let promise = this.store.query('user', {name:'Bob'});
promise.then( (things)=> {
   console.log(things.mapBy('id'));
});
return promise;

@jasononaquest
Copy link

@danielspaniel what it acts like is the store is being reset after the first click + andThen. The two models that get maked and then setup as the return values of the two querys seem to disappear after the first click of a tab + andThen. All of the models get setup, and all of the store functions stubbed, before the first visit. I've tried moving the setup around to different stages of the test but it hasn't completely solved the problem.

I used your code above to see the things, and it confirmed that the findAll works, but when it gets to the query (from clicking a tab which should filter the results), it's returning default factory objects.

@danielspaniel
Copy link
Collaborator

right, that is why i asked if they were the same models. what do the store.findAll and the store.query calls look like ( exactly )

@jasononaquest
Copy link

This is the entire file with proprietary internals modified.

import Ember from 'ember';

export default Ember.Route.extend({
  controllerName: 'my_controller',
  queryParams: {
    my_param: {
      refreshModel: true
    }
  },
  model(params) {
    if (params.my_param != null) {
      return this.store.query('my-model', {my_attribute: params.my_param});
    } else {
      return this.store.findAll('my-model');
    }
  }
});

@danielspaniel
Copy link
Collaborator

Looks like you need way more help than just about FactoryGuy.

I hope you see the irony that you are asking for help on your paid project. And I offer to get on screenhero and teach you stuff about ember ( because things look kinda whacky ) , and you say .. no no .. this code is proprietary .. you can't actually look at it. So instead we have to go back and forth on this email thread with me trying to figure it out ( for free ). Now, I don't mind helping out, but if you ask me to help and you can barely show me anything .. it's alittle bit foolish.
The code I have for work is pretty darn proprietary, and anyone is free to look at whatever they want if they offer to help me out for free. They are probably not looking to steal my stuff.

In any case, my hunch is that you don't need to do the store.query, all you have to do is apply filtering on the models in tab A and B. But without knowing more about what is going on, I just can't tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants