Permalink
Browse files

rough draft conversion to qunit

  • Loading branch information...
1 parent 84073e7 commit 4d9d567f70e2448def41a716e7cf9cc3c5c5f474 @collin committed Apr 29, 2012
@@ -1,41 +1,39 @@
{AS, $, _, sinon, jwerty} = require require("path").resolve("./test/client_helper")
-exports.Application =
- setUp: (callback) ->
- @app = AS.Application.new(el: @el = $("<div>"))
- callback()
-
- "attaches global key handlers w/jwerty": (test) ->
- events = [
- "open", "up", "down", "first", "last", "left",
- "right", "indent", "dedent", "alphanum"
- "escape", "accept", "delete"
- ]
-
- for event in events
- do (event) =>
- @app.bind event, (_event) -> test.ok(_event)
-
- triggers = [
- "esc", "cmd+enter", "backspace", "enter", "up", "down",
- "home", "end", "left", "right", "tab", "shift+tab"
- "a", "b", "C", "D", "1", "2"
- ]
- test.expect triggers.length
+module "Application",
+ setup: ->
+ @app = AS.Application.new(el: @el = $("<div>"))
- for trigger in triggers
- jwerty.fire trigger, @el
-
- test.done()
-
- "initializes views into the application context": (test) ->
- app_panel = @app.view AS.Views.Panel, key: "value"
- test.equal app_panel.application, @app
- test.equal app_panel.key, "value"
- test.done()
-
- "appends views into the app dom element": (test) ->
- app_panel = @app.view AS.Views.Panel, key: "value"
- @app.append app_panel
- test.equal @app.el.children()[0], app_panel.el[0]
- test.done()
+test "attaches global key handlers w/jwerty", ->
+ events = [
+ "open", "up", "down", "first", "last", "left",
+ "right", "indent", "dedent", "alphanum"
+ "escape", "accept", "delete"
+ ]
+
+ for event in events
+ do (event) =>
+ @app.bind event, (_event) -> ok(_event)
+
+ triggers = [
+ "esc", "cmd+enter", "backspace", "enter", "up", "down",
+ "home", "end", "left", "right", "tab", "shift+tab"
+ "a", "b", "C", "D", "1", "2"
+ ]
+ expect triggers.length
+
+
+ for trigger in triggers
+ jwerty.fire trigger, @el
+
+
+test "initializes views into the application context", ->
+ app_panel = @app.view AS.Views.Panel, key: "value"
+ equal app_panel.application, @app
+ equal app_panel.key, "value"
+
+test "appends views into the app dom element", ->
+ app_panel = @app.view AS.Views.Panel, key: "value"
+ @app.append app_panel
+ equal @app.el.children()[0], app_panel.el[0]
+
View
@@ -2,62 +2,18 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- "stashes the binding container": (test) ->
- [mocks, binding] = mock_binding(AS.Binding)
+module "Binding"
+test "stashes the binding container", ->
+ [mocks, binding] = mock_binding(AS.Binding)
- test.equal binding.container[0], binding.context.currentNode
+ equal binding.container[0], binding.context.currentNode
- test.done()
+
+test "stashes the binding group", ->
+ [mocks, binding] = mock_binding(AS.Binding)
+ equal binding.bindingGroup, binding.context.bindingGroup
- "stashes the binding group": (test) ->
- [mocks, binding] = mock_binding(AS.Binding)
- test.equal binding.bindingGroup, binding.context.bindingGroup
-
- test.done()
-
- "gets the field value": (test) ->
- [mocks, binding] = mock_binding(AS.Binding)
- test.equal binding.fieldValue(), "value"
-
- test.done()
-
- # Collection:
- # "field_value is the model": (test) ->
- # [mocks, binding] = mock_binding(AS.Binding.Many, model: new AS.Collection)
- # test.equal binding.pathValue(), binding.model
- # test.done()
-
- # HasOne:
- # "extends AS.Binding.Field": (test) ->
- # test.equal AS.Binding.HasOne.__super__.constructor, AS.Binding.Field
- # test.done()
-
- # BelongsTo:
- # setUp: (callback) ->
- # owner = new AS.Model
- # model = new BoundModel
- # model.owner owner
-
- # content_fn = (thing) -> @div id: thing.cid
-
- # [mocks, binding] = mock_binding(AS.Binding.BelongsTo, field: 'owner', model: model, fn: content_fn)
-
- # @owner = owner
- # @binding = binding
- # callback()
-
- # "initializes content": (test) ->
- # test.ok @binding.container.find("##{@owner.cid}").is("div")
- # test.done()
-
- # "removes content when relation set to null": (test) ->
- # @binding.model.owner(null)
- # test.equal @binding.container.html(), ""
- # test.done()
-
- # "creates content when relation set": (test) ->
- # new_owner = new AS.Model
- # @binding.model.owner new_owner
- # test.ok @binding.container.find("##{new_owner.cid}").is("div")
- # test.done()
+
+test "gets the field value", ->
+ [mocks, binding] = mock_binding(AS.Binding)
+ equal binding.fieldValue(), "value"
@@ -2,36 +2,32 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- CheckBox:
- "there is only one check box": (test) ->
- model = BoundModel.new maybe: true
- [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
- test.equal 1, binding.content.parent().find(":checkbox").length
- test.done()
+module "Binding.CheckBox"
- "the checkbox is checked if the starting value is true": (test) ->
- model = BoundModel.new maybe: true
- [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
- test.ok binding.content.is(":checked")
- test.done()
-
- "the checkbox is unchecked if the starting value is false": (test) ->
- model = BoundModel.new maybe: false
- [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
- test.ok binding.content.is(":not(:checked)")
- test.done()
-
- "checking the box sets the field to true": (test) ->
- model = BoundModel.new maybe: false
- [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
- binding.content.click().trigger("change")
- test.equal model.maybe.get(), true
- test.done()
-
- "unchecking the box sets the field to false": (test) ->
- model = BoundModel.new maybe: true
- [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
- binding.content.click().trigger("change")
- test.equal model.maybe.get(), false
- test.done()
+test "there is only one check box", ->
+ model = BoundModel.new maybe: true
+ [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ equal 1, binding.content.parent().find(":checkbox").length
+
+test "the checkbox is checked if the starting value is true", ->
+ model = BoundModel.new maybe: true
+ [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ ok binding.content.is(":checked")
+
+test "the checkbox is unchecked if the starting value is false", ->
+ model = BoundModel.new maybe: false
+ [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ ok binding.content.is(":not(:checked)")
+
+test "checking the box sets the field to true", ->
+ model = BoundModel.new maybe: false
+ [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ binding.content.click().trigger("change")
+ equal model.maybe.get(), true
+
+test "unchecking the box sets the field to false", ->
+ model = BoundModel.new maybe: true
+ [mocks, binding] = mock_binding(AS.Binding.CheckBox, model: model, field: model.maybe)
+ binding.content.click().trigger("change")
+ equal model.maybe.get(), false
+
@@ -2,68 +2,66 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- EditLine:
- setUp: (callback) ->
- @rangy_api =
- getSelection: -> {
- rangeCount: 0
- createRange: -> {
- startOffset: 0
- endOffset: 0
- }
- }
- createRange: -> {
- startOffset: 0
- endOffset: 0
- }
+# exports.Binding =
+# EditLine:
+# setUp: (callback) ->
+# @rangy_api =
+# getSelection: -> {
+# rangeCount: 0
+# createRange: -> {
+# startOffset: 0
+# endOffset: 0
+# }
+# }
+# createRange: -> {
+# startOffset: 0
+# endOffset: 0
+# }
- @real_open = AS.open_shared_object
- AS.open_shared_object = (id, did_open) ->
- did_open makeDoc(id)
+# @real_open = AS.open_shared_object
+# AS.open_shared_object = (id, did_open) ->
+# did_open makeDoc(id)
- @remote = (operation, model = @model) ->
- if model.share.emit
- model.share.emit "remoteop", operation
- else
- model.share.doc.emit "remoteop", operation
+# @remote = (operation, model = @model) ->
+# if model.share.emit
+# model.share.emit "remoteop", operation
+# else
+# model.share.doc.emit "remoteop", operation
- AS.Binding.EditLine::rangy = @rangy_api
- callback()
+# AS.Binding.EditLine::rangy = @rangy_api
+# callback()
- tearDown: (callback) ->
- AS.open_shared_object = @real_open
- callback()
+# tearDown: (callback) ->
+# AS.open_shared_object = @real_open
+# callback()
- # TODO: implement sharing things
- # "contenteditable area responds to all edit events": (test) ->
- # test.expect 8
- # EditLine = AS.Binding.EditLine.extend ({def}) ->
- # def generate_operation: -> test.ok true
- # [mocks, binding] = mock_binding(EditLine)
- # mocks.binding.expects("applyChange").exactly(0)
- # for event in ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste', 'click', 'focus']
- # binding.content.trigger(event)
- # mocks.verify()
- # test.done()
-
- # "applies change if content has changed on edit event": (test) ->
- # model = SharedBoundModel.open()
- # model.field("value")
- # model.when_indexed =>
- # [mocks, binding] = mock_binding(AS.Binding.EditLine, model: model)
- # binding.content[0].innerHTML += " change"
- # binding.generate_operation()
- # test.deepEqual model.share.get(), model.attributes_for_sharing()
- # test.done()
-
- # "applies change from remote operation": (test) ->
- # model = SharedBoundModel.open()
- # model.field("value")
- # model.when_indexed =>
- # [mocks, binding] = mock_binding(AS.Binding.EditLine, model: model)
- # @remote model.share.at("field").insert(0, "remote "), model
- # test.equal binding.content[0].innerHTML, "remote value"
- # test.equal model.share.at("field").get(), "remote value"
- # test.equal model.field(), "remote value"
- # test.done()
+# # TODO: implement sharing things
+# # "contenteditable area responds to all edit events", ->
+# # expect 8
+# # EditLine = AS.Binding.EditLine.extend ({def}) ->
+# # def generate_operation: -> ok true
+# # [mocks, binding] = mock_binding(EditLine)
+# # mocks.binding.expects("applyChange").exactly(0)
+# # for event in ['textInput', 'keydown', 'keyup', 'select', 'cut', 'paste', 'click', 'focus']
+# # binding.content.trigger(event)
+# # mocks.verify()
+# #
+# # "applies change if content has changed on edit event", ->
+# # model = SharedBoundModel.open()
+# # model.field("value")
+# # model.when_indexed =>
+# # [mocks, binding] = mock_binding(AS.Binding.EditLine, model: model)
+# # binding.content[0].innerHTML += " change"
+# # binding.generate_operation()
+# # deepEqual model.share.get(), model.attributes_for_sharing()
+# #
+# # "applies change from remote operation", ->
+# # model = SharedBoundModel.open()
+# # model.field("value")
+# # model.when_indexed =>
+# # [mocks, binding] = mock_binding(AS.Binding.EditLine, model: model)
+# # @remote model.share.at("field").insert(0, "remote "), model
+# # equal binding.content[0].innerHTML, "remote value"
+# # equal model.share.at("field").get(), "remote value"
+# # equal model.field(), "remote value"
+# #
Oops, something went wrong.

0 comments on commit 4d9d567

Please sign in to comment.