Permalink
Browse files

small test for GraphicPreview model.

  • Loading branch information...
1 parent bacb397 commit 93af7c7cb86869328781deb69719e8310bd890bf @knowuh knowuh committed Apr 5, 2012
Showing with 43 additions and 2 deletions.
  1. +7 −2 apps/my_system/models/graphic_preview.js
  2. +36 −0 apps/my_system/tests/jasmine/unit/graphic_preview.js
@@ -31,17 +31,22 @@ MySystem.GraphicPreview = SC.Record.extend(
data.push("No. Sumbits: " + feedback.get('numOfSubmits'));
data.push("Feedback: " + feedback.get('feedback'));
}
- exporter = new ImageExporter(data);
+ exporter = this.getExporter(data);
this.set('svg', escape(new LZ77().compress(exporter.get_svg())));
// this.set('png', exporter.get_png());
+ },
+
+ getExporter: function(data) {
+ return new ImageExporter(data);
}
});
// we only ever want a single of these records to exist
MySystem.GraphicPreview.LAST_FEEDBACK_GUID = "LAST_GRAPHIC_PREVIEW";
-MySystem.GraphicPreview.instance = function(store) {
+MySystem.GraphicPreview.instance = function() {
+ var store = MySystem.store;
var lastPreview = store.find(MySystem.GraphicPreview,MySystem.GraphicPreview.LAST_FEEDBACK_GUID);
if (lastPreview && (lastPreview.get('status') & SC.Record.READY)){
return lastPreview;
@@ -0,0 +1,36 @@
+/*globals MySystem defineJasmineHelpers describe it expect xit xdescribe beforeEach afterEach spyOn runs waits waitsFor runAfterEach runBeforeEach */
+
+defineJasmineHelpers();
+
+describe("GraphicPreview", function (){
+ var recordType;
+ var graphicPreview;
+
+ var fake_svg = "<svg><fake></fake></svg>";
+ var compressed_data = new LZ77().compress(fake_svg);
+ var escaped_compressed_data = escape(compressed);
+
+ MySystem.setupStore(MySystem);
+ describe("instance", function() {
+ beforeEach( function() {
+ graphicPreview = MySystem.GraphicPreview.instance(MySystem.store);
+ spyOn(graphicPreview, 'getExporter').andCallFake(function (dtata) {
+ return ({
+ get_svg: function() {
+ graphicPreview.got_svg = true;
+ return fake_svg;
+ }
+ });
+ });
+ });
+
+ describe("updatePreview", function() {
+ it ("should result in compressed svg data being saved", function() {
+ graphicPreview.updatePreview();
+ expect(graphicPreview.get('svg')).toBe(escaped_compressed_data);
+ });
+ });
+
+ });
+
+});

0 comments on commit 93af7c7

Please sign in to comment.