How do I fix Init() error when unit testing a method that builds a new instance of a view, that contains a listview - unit-testing

I have a custom navigation method that builds a new instance of a view. Unit tests for this method fail with the error message
System.InvalidOperationException: You must call Xamarin.Forms.Forms.Init(); prior to using this property.
I know that the listview in the view is causing it as the unit tests succeed when the listview is removed.
I have seen in older posts and blogs that this is because platformServices needs to be set but this cannot be set externally and the solutions point to github repositories or nuget packages that no longer exist or don't go into detail.
Any advice would be appreciated.

Related

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

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?

Internal autolinking in Ember.js

I've tasked myself with implementing a twitter clone in Ember.js in order to get more familiar with the framework. I've hit a bit of a snag however when it comes to implementing autolinking in the tweet.
There is an existing plugin that does external links (ex. http://www.google.com) well but doesn't work well for internal links (like #handle or #hashtags) which should as it should be implemented as a LinkComponent but I can't figure out how to insert one from a helper.
source code: autolink helper (relevant unit test)
For now I have just had the helper insert a <a/> tag but this sucks as it unloads the page and fetches everything fresh from the server.
Anyone have any suggestions about how best to implement this part of my Ember app?
Figured it out myself - I converted the helper into a component and added a click listener for bubbled click events from the child links which then get passed to the router:
https://github.com/whoward/ember-twitter-clone/commit/93af68d9f504b8b8972487e6c09851d3523a3678

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

Ember "select" View deadlocks platform.js when content array provided by Controller?

I'm working on migrating a non-CLI Ember app to 1.10 with HTMLBars. In a View Template I have a select list rendered by Ember.Select View where it's content is obtained from an array property in the Controller (adultsSelect: (1).upto(4)). I changed 'Ember.Select' to '"select"' as the updated docs suggest. As soon as I setup the 'view select' with 'content=adultsSelect', the browser deadlocks, I'm prompted to stop, debug or continue line 13 in 'platform.js'. If I go into 'debug', I don't know what I'm debugging, but I see a sort of infinite recursion of calls or references to 'platform.js'. If I change the array assignment to just 'adultsSelect: ["1","2"]', there's no improvement. 'Platform.js' is a product of the Polymer project which has something to do with upcoming web components technologies which Ember is using in advance. However, Polymer now says that 'web components polyfills' were released in the past as 'platform.js' so seems I'm already out-of-date with this. It's funny that something as simple as a select list with 4 options can be so complex in Ember that when you go to migrate to a new version, your browser locks up, doesn't tell you why, there's no docs to say this will happen and what to do about it, but that an obsolete version of an upcoming technology being used in advance is somehow involved in it. Should I look for a bower dependency related to web components and update that so I get a compatible version?
For this, I simply removed 'platform.js' as a script linked into 'index.html' and now select lists work, at least in the development build running on node express.

how to do backbone.js UI testing

So I've created an require.js and backbone.js (actually marionette.js) application that basically is some sort of mobile app builder.
Now I want to create tests for it, basically testing this scenario:
Navigate to an existing project, e.g site.com/build/1234
Drag a component, check if it is added correctly.
Change properties of a component and see if they are updated correctly. I.e: I've a properties panel which lists the properties
of the selected component, than for example I've a property which
is a selectmenu and changes the size (small, medium, large). I
should be able to test this.
Now I've been searching on google, however since there are so many testing frameworks, i'm not sure which one to pick and which one provides the functionalities I need.
Potentially PhantomJS seems to be something I could use, however please advice me with some specific information.
Thanks.
if you want to actually simulate clicks, look into selenium (http://docs.seleniumhq.org/projects/webdriver/)
If you just want to test that your Backbone components(views, controllers, etc) and templates are working correctly, you can use a js test runner such as Karma (http://karma-runner.github.io/0.12/index.html) to run your tests. Sinon can mock out your ajax calls for you as well. It can use PhantomJs as a rendering engine, so you can actually render your views, and use view.$() style DOM inspection to verify the output of your views.