Hey guys,
I have been struggling to setup unit tests for my application controller and I was wondering if you could give me some guidance.
In case your wondering, yes I have spent countless hours reading different posts describing how to do this. But I haven’t been able to crack it and I was wondering if you kind folks might be able to give me some hints.
I am using the Nuget Ember Asp.Net Todo items application template as starter code.
In a nutshell: I am using Ember data and WebApi Restful adapter for data plumbing, therefore my backend application returns the following POJSO array: [{“$id”:“1”,“userId”:2,“userName”:“hp\NewtonT2”,“resourceManager”:true,“projectManager”:false}]
For url: http://dev_server:1234/api/user/ (Get)
I am stumped because I can never get window.App.ApplicationRoute.setupController to fire off…?!
So I tried this:
Ember.run(function () {
var myModel = new Ember.Object();
var user = new Ember.Object();
user.set('resourceManager', true);
myModel.set('content', Ember.A([user]));
var t = App.ApplicationController.create({
model: myModel
});
var test = t.get('model');
console.log(test.get('content')[0].get('resourceManager'));
console.log(t.canEdit)
});
Oddly t.canEdit is always undefined…
In my controller I have defined canEdit as:
window.App.ApplicationController = Ember.Controller.extend({
//
// Logged in user's user name
loginUserName: function () {
return (this.get('model').get('content'))[0].get('userName');
}.property(),
//
// Can current user edit the data?
canEdit: function () {
return (this.get('model').get('content'))[0].get('resourceManager');
}.property()
});
How can I adequately test the ApplicationController and retrieve its two properties using mocks/stubs to isolate the dependencies?
Thanks in advance.