How do I handle injectables in tests for an Aurelia CLI project using Karma and Jasmine - unit-testing

My project is organized as such:
App (Creates a router from 'aurelia-router')
Wizard (Routed component; injects the router - along with some custom stuff)
Steps (Collection of Step objects in Wizard; each Step has a reference to parent Wizard)
Questions (Collection of Question objects in Step; each Question has a reference to parent Step and parent Wizard)
I'm trying to test functionality of a Question object, but in order to do so I need a Step and a Wizard so references don't break.
Creating an instance of the Wizard object means I need to provide the injectables to the constructor, which is easy for my custom stuff and nice for providing a mock. But creating the Router from scratch seems wrong and I don't know how or if it's even possible to get Router from App within a test.
So, my question is, is there a way to get access to my instance of Router within App from a test so I can provide it to my Wizard constructor? Or am I barking up the wrong tree?

Related

How do I set model variables within an acceptance test?

In Ember.js, I currently want to test a UI feature present. Essentially, once a model variable changes, I expect to see a UI element appear (a checkmark). I have tried creating a model within the acceptance test but this unfortunately did not work as I did.
I just wanted to know which function to use to set model variables.
A model typically would involve unit tests, but like you've said you're testing the visual result of something being set on a model. I would recommend an integration test. If you are able to refactor (or maybe this is the case already), the part of the template into a component then you can create an ember test for the component and pass in the model set up perfectly how you would like.
If this test really does depend on the model being setup a specific way I would look at how your application sets up that model to begin with and try to replicate those actions with click and fillIn helpers. Another way is say, your application wants to setup a user but relies on a network request to do this, then you could use pretender.js and fake the response to that request so that the application's inputs are setup from the network in the way you're after.
I would really try to do this an acceptance test though, the composable nature of components allows them to be tested in stricter isolation, these tests will run faster, and you're worrying less about side effects.

Zend Framework, Architecture with Doctrine

im learning Zend Framework (3) ... I installed Doctrine because i do not want to write sql queries to learn all other stuff faster....
First Question:
So know i configured a factory that loads me the doctrine entity manager to my Controllers (with DI).
So its really simple to get my entities to my controller ... e.g in my Project Controller createAction i can easy get my user entities to show them in my project form (project <--> user many-to-many).
But know im struggling, would it be better to create repository classes and inject this to my controllers instead of the doctrine entity manager, so i can filtering etc all my entities?
Second question:
When i want to filter my projects (e.g by user)
where should i do this ... in simpler slim projects i created Collection classes and injected them all of my entities and after that i called a filter method in my collection ... but the problem there is, i just loaded all entities from my database to the collection. In larger application i think there are to many entities loaded from the Database?
Third Question (Conclusion):
When i want to load data from the db to my Controllers whats best Practice here?
Load it from the entity manager ?
Load it from a Repository (the Repository load it from the entity manager)?
Load it from a Collection (the Collection loads data from the repository class and the repository loads data from the entity manager)?
I did not thought about Pagination #all... thats what i have to do next ... but there are many questions similar to my other questions.
(I know there is a zend module for this .. but have no idea how this works.. have too learn this too)
Im thankful for every hint, meaning etc.
Answers to this question are possibly all opinion based. I would say it is all about personal preference. There is no such thing as best practice here it all depends on what you will do in your controller. On top of that you can easily get a repository from your entity-manager if you need it:
$userRepository = $entityManager->getRepository('Application\Entity\User');
A more common might be to make a custom UserService (a wrapper class) around your repository/entity-manager that you populate with the custom methods you would like to use with your User resources.
I hope this helps you a bit...

ember.js: prepare code to move from ember 1.x to ember 2.0

My question is: Can someone direct me in moving from controller based application to component base application?
I am building a map application for my dog training club. We are specialized in helping finding missing people.
In order to organize our training, we need an application to draw trails and add items on them etc.
I've started an app using Ember-Cli and OpenLayers-3. The application is working nicely, but I would like to move the code from controller based to component base approach.
I would like also to use more routing as at the moment, I have only one route and all user interactions are handled using actions.
I've setup a repository on github for those who would be kind enough to help me:
https://github.com/mylen/mantrailling
if you want to checkout the code and test the app localy, you'll need to modify the referer using a header mod in your navigator to use http://demo.melard.fr
You can see a beta of the website at that page :
http://recherche.utilitaire.melard.fr/beta/map
Thank you in advance,
First, we should clarify the intended uses of components, controllers and routes in ember.js.
Components are similar to Views, but they are isolated and therefore used to create reusable pieces of code, that handle the visual representation of your models.
Controllers are mainly used to decorate your models, but also to hold application state.
Routes represent you current application state. They are responsible for loading your models and to initialize your controllers.
To solve your first problem (controllers -> components), you only need to move all view related stuff, and only this, into components. Your code that decorate your model, for example the active flag of a way-point, remains in the controller. You only need to bind the data of your models/controllers to the components, via embers data binding. (http://guides.emberjs.com/v1.11.0/components/passing-properties-to-a-component)
Your second problem (use routes) is a bit harder to solve, I think. First you need to find all of the states your app currently have. After that, you should move your model loading and saving stuff into this routes.
Edit
Some references describing the problem.
https://github.com/ef4/rfcs/blob/routeable-components/active/0000-routeable-components.md
https://www.youtube.com/watch?v=QgycDZjOnIg
Edit 2
Your question is highly related to How to move ember from 1.x to 2.0, because the changes you mentioned will come along with ember 2.0.
Here are some additional links that describe how to prepare best for this upgrade.
https://gist.github.com/samselikoff/1d7300ce59d216fdaf97
https://speakerdeck.com/tomdale/ember-2-dot-0-in-practice
http://discuss.emberjs.com/t/what-is-a-good-way-to-do-this-in-ember-2-0-no-itemcontroller-no-arraycontroller/6649
You can find a lot of resources if you search for ember 2.0.
Edit 3
Here is I think the most informative source for keeping up with new Ember releases:
https://www.youtube.com/watch?v=wsydQzQF4Ww

emberjs get automatic controller

I'm trying to test my app with qunit and sinon. I want to test some behaviour of the controller including its setup on a transition. For example in 'setupController' in a given route.
However the problem is that the controller is automatically created and I only know that you can get it with a 'controllerFor' call in the route. How can I get at the auto generated controller(s) for a given page from the outside, e.g. App.xxxxx
Note that I tried doing a 'transitionTo' passing the controller as the second argument but this means that 'setupController' never gets called so I can't test the scenario I wanted to. If there were a way to force setupController to be called even when you pass the second argument this would do the job
Thanks for any help

why emberjs creates all controllers on Application initialization?

On application initialization , all the controllers are initialized by Ember.
After working with any of the controllers, it retains its values, that becomes a problem while reusing the controller.
I would wanna know :
the benefit of initializing all controller at application initialization?
Is there any way to solve my problem of reusing controllers such that all the variables are reset ?
PS : Please don't misunderstand "reusing controllers". All I want is to use the same controller without the previously entered values from any previous task.
Controllers are intended to be long-lived and hold application state even as their views may blink in and out of existence. In a typical Ember app, controllers are created once and live for the life of the app, hence the reasoning for initializing them all at app initialization time.
For an easy way to "reset" a controller, you could use an Ember.ObjectController, that proxies gets and sets of properties not defined on the controller the object you set as the content property. To reset the controller, just set content to a fresh object.