-
-
Save joefiorini/ec4f76b6503406561aa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.App = Ember.Application.create({ | |
store: DataStore.create(), | |
Reports: {}, | |
Settings: {}, | |
Shared: {} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.set("rootElement", "#qunit-fixture"); | |
window.lookupStore = function(){ | |
return App.__container__.lookup('store:main'); | |
} | |
window.lookupController = function(name){ | |
return App.__container__.lookup('controller:' + name); | |
} | |
window.lookupRouter = function(){ | |
return App.__container__.lookup('router:main'); | |
} | |
function stubSignIn(){ | |
AuthClient.Storage.setItem("session-token", AuthClient.stubToken); | |
} | |
function stubIndexRoute(){ | |
App.IndexRoute.reopen({ | |
redirect: function() { } | |
}); | |
} | |
function redirectToIndex(){ | |
window.location.hash = "/"; | |
} | |
Ember.run(function(){ | |
App.deferReadiness(); | |
}); | |
QUnit.begin(function(){ | |
Ember.run(function(){ | |
App.reset(); | |
}); | |
}); | |
$(function(){ | |
stubIndexRoute(); | |
redirectToIndex(); | |
Ember.run(function(){ | |
stubSignIn(); | |
App.initialize(); | |
App.startRouting(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.DataStore = null; | |
(function(){ | |
window.DataStore = DS.Store.extend({ revision: 12, adapter: 'App.ReportsAdapter' }); | |
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var router, server, transitioned; | |
var Fixtures = { | |
punctualitySummary: { | |
"summary": { | |
"stats": { | |
"totalPunctualCalls": 20, | |
"totalCallsReturned": 100 | |
} | |
}, | |
"analysis": { | |
"stats": { | |
"total_calls": 100, | |
"spread_level_1": 0.30, | |
"spread_level_2": 0.20, | |
"spread_level_3": 0.40, | |
"spread_level_4": 0.10 | |
} | |
} | |
} | |
} | |
module("Punctuality Summary", { | |
setup: function(){ | |
server = sinon.fakeServer.create(); | |
server.respondWith("GET", new RegExp("/stat-group/punctuality/summary.json"), | |
[200, {"Content-Type": "application/json"}, JSON.stringify(Fixtures.punctualitySummary)]); | |
Ember.run(function(){ | |
App.store.destroy(); | |
App.store = DataStore.create(); | |
App.reset(); | |
router = lookupRouter(); | |
}); | |
if(!transitioned){ | |
Ember.run(function(){ | |
router.transitionTo("reports.index"); | |
transitioned = true; | |
}); | |
} | |
server.respond(); | |
}, | |
teardown: function(){ | |
server.restore(); | |
} | |
}); | |
test('makes summary data conveniently accessible in controller', function(assert){ | |
var controller = lookupController("punctualitySummary"), | |
model = controller.get("content"); | |
assert.ok(controller.get("summary")); | |
assert.deepEqual(controller.get("summary"), model.get("summary.stats")); | |
}); | |
function getI18n(key){ | |
var props = key.split("."); | |
return props.reduce(function(value, prop){ | |
return value[prop]; | |
}, Em.I18n.translations); | |
} | |
test('displays analysis summary chart', function(assert){ | |
Ember.run(function(){ | |
var el = $("[data-type=punctuality]"), | |
controller = lookupController("punctualitySummary"), | |
model = controller.get("content.analysis.stats"); | |
el.find(".report-graph-data").each(function(idx){ | |
var key = "spread_level_" + (idx + 1), | |
value = model.get(key) * 100, | |
actual = $(this).attr("style").replace(/width: /, ""), | |
actual = parseInt(actual); | |
assert.equal(actual, value, "data item " + idx + ": " + value); | |
}); | |
el.find(".report-swatch-container").each(function(idx){ | |
var num = idx + 1, | |
expected = getI18n("stacked-bar-graph.punctuality-summary.legend." + num), | |
expected = $("<div>").html(expected).text(), | |
actual = $(this).text().trim().split("\n").join(""), | |
key = "spread_level_" + (idx + 1); | |
expected += " " + model.get(key) * 100 + "%"; | |
assert.equal(actual, expected, "label " + num + ": " + expected); | |
}); | |
}); | |
}); | |
test("displays summary data", function(assert){ | |
ok(router._lookupActiveView("punctualitySummary")); | |
var content = $("[data-type=punctuality]").text(); | |
assert.match(content, /20 out of/, "displays totalPunctualCalls"); | |
assert.match(content, /out of[\n\s]* 100/, "displays totalCallsReturned"); | |
assert.match(content, /20%/, "displays punctuality ratio"); | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment