Skip to content

Instantly share code, notes, and snippets.

@darthdeus
Forked from joachimhs/gist:5303131
Last active December 15, 2015 18:28
Show Gist options
  • Save darthdeus/5303646 to your computer and use it in GitHub Desktop.
Save darthdeus/5303646 to your computer and use it in GitHub Desktop.
var alertAdminController;
module("EurekaJ.AdministrationAlertsController", {
setup: function() {
this.server = sinon.fakeServer.create();
Ember.run(function() {
alertAdminController = EurekaJ.__container__.lookup("controller:administrationAlerts");
});
},
teardown: function() {
this.server.restore();
delete this.server;
}
});
var thing = {
verifyContentLength: function() {
console.log('content.length');
console.log('later: ' + alertAdminController.get('content.length'));
if (alertAdminController.get('content.length') > 0 ) {
strictEqual(1, alertAdminController.get('content.length'), "Expecting one alert. Got: " + alertAdminController.get('content.length'));
start();
}
}
};
asyncTest("Create a new Alert and verify that it is shown", 3, function() {
EurekaJ.reset();
ok(alertAdminController, "Exepcting a non-null AdministrationAlertsController");
console.log(alertAdminController.get('content.length'));
Ember.addObserver(alertAdminController.get('content'), 'length', thing, 'verifyContentLength');
console.log(alertAdminController.get('content.length'));
alertAdminController.set('newAlertName', 'New Alert');
alertAdminController.createNewAlert();
var newAlert = alertAdminController.get('newAlert');
newAlert.one('didCreate', function() {
console.log('didCreate: ' + alertAdminController.get('content.length'));
});
console.log('committing');
EurekaJ.store.commit();
//Set up the response
this.server.respondWith("POST", "/alert_models",
[200, { "Content-Type": "text/json" },
'{"alert_model":{"alert_source":"null","id":"New Alert","alert_delay":0,"alert_plugin_ids":[],"alert_notifications":"","alert_activated":false,"alert_type":"greater_than"}}']);
console.log('responding');
this.server.respond();
strictEqual(1, this.server.requests.length, "Expecting a total of 1 XHR");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment