Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rough draft conversion to qunit

  • Loading branch information...
commit 4d9d567f70e2448def41a716e7cf9cc3c5c5f474 1 parent 84073e7
@collin authored
Showing with 1,374 additions and 1,570 deletions.
  1. +36 −38 test/client/application.coffee
  2. +12 −56 test/client/binding.coffee
  3. +28 −32 test/client/binding/check_box.coffee
  4. +58 −60 test/client/binding/edit_line.coffee
  5. +45 −51 test/client/binding/field.coffee
  6. +19 −23 test/client/binding/input.coffee
  7. +63 −71 test/client/binding/many.coffee
  8. +51 −54 test/client/binding/model.coffee
  9. +29 −35 test/client/binding/one.coffee
  10. +41 −47 test/client/binding/select.coffee
  11. +69 −73 test/client/binding_group.coffee
  12. +23 −24 test/client/dom.coffee
  13. +114 −132 test/client/models/targets.coffee
  14. +183 −206 test/client/view.coffee
  15. +40 −42 test/client/view_events.coffee
  16. +20 −22 test/client/view_model.coffee
  17. +4 −4 test/client/views/panel.coffee
  18. +9 −9 test/client/views/region.coffee
  19. +85 −85 test/core/filtered_collection.coffee
  20. +19 −20 test/core/model/rest.coffee
  21. +57 −72 test/core/model/share.coffee
  22. +20 −22 test/core/models/grouping.coffee
  23. +6 −4 test/core/models/radio_selection_model.coffee
  24. +92 −102 test/core/properties/belongs_to.coffee
  25. +1 −1  test/core/properties/field.coffee
  26. +119 −136 test/core/properties/has_many.coffee
  27. +66 −74 test/core/properties/has_one.coffee
  28. +63 −73 test/core/properties/virtual_property.coffee
  29. +2 −2 test/helper.coffee
View
74 test/client/application.coffee
@@ -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
68 test/client/binding.coffee
@@ -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"
View
60 test/client/binding/check_box.coffee
@@ -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
+
View
118 test/client/binding/edit_line.coffee
@@ -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"
+# #
View
96 test/client/binding/field.coffee
@@ -2,54 +2,48 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- Field:
- "sets appropriate initial content": (test) ->
- [mocks, binding] = mock_binding(AS.Binding.Field)
- test.equal binding.container.find("span").text(), "value"
- test.done()
-
- "clears content when value undefined": (test) ->
- [mocks, binding] = mock_binding AS.Binding.Field,
- fn: ->
- @h1 -> @span "fn value"
-
- binding.model.field.set(undefined)
- test.equal "", binding.container.html()
- test.done()
-
- "clears content when value null": (test) ->
- [mocks, binding] = mock_binding AS.Binding.Field,
- fn: ->
- @h1 -> @span "fn value"
-
- binding.model.field.set(null)
- test.equal "", binding.container.html()
- test.done()
-
- "updates content when model changes": (test) ->
- [mocks, binding] = mock_binding(AS.Binding.Field)
- binding.model.field.set("new value")
- test.equal binding.container.find("span").text(), "new value"
- test.done()
-
- "uses given fn to generate content": (test) ->
- [mocks, binding] = mock_binding AS.Binding.Field,
- fn: ->
- @h1 -> @span "fn value"
-
- test.equal binding.container.find("h1 > span").text(), "fn value"
- test.done()
-
- "updates fn content when value changes": (test) ->
- model = BoundModel.new field: "value"
- [mocks, binding] = mock_binding AS.Binding.Field,
- model: model
- fn: ->
- @h1 -> @span model.field.get()
-
- test.equal binding.container.find("h1 > span").text(), "value"
- binding.model.field.set("changed value")
- test.equal binding.container.find("h1 > span").text(), "changed value"
- test.done()
-
+module "Binding.Field"
+
+test "sets appropriate initial content", ->
+ [mocks, binding] = mock_binding(AS.Binding.Field)
+ equal binding.container.find("span").text(), "value"
+
+test "clears content when value undefined", ->
+ [mocks, binding] = mock_binding AS.Binding.Field,
+ fn: ->
+ @h1 -> @span "fn value"
+
+ binding.model.field.set(undefined)
+ equal "", binding.container.html()
+
+test "clears content when value null", ->
+ [mocks, binding] = mock_binding AS.Binding.Field,
+ fn: ->
+ @h1 -> @span "fn value"
+
+ binding.model.field.set(null)
+ equal "", binding.container.html()
+
+test "updates content when model changes", ->
+ [mocks, binding] = mock_binding(AS.Binding.Field)
+ binding.model.field.set("new value")
+ equal binding.container.find("span").text(), "new value"
+
+test "uses given fn to generate content", ->
+ [mocks, binding] = mock_binding AS.Binding.Field,
+ fn: ->
+ @h1 -> @span "fn value"
+
+ equal binding.container.find("h1 > span").text(), "fn value"
+
+test "updates fn content when value changes", ->
+ model = BoundModel.new field: "value"
+ [mocks, binding] = mock_binding AS.Binding.Field,
+ model: model
+ fn: ->
+ @h1 -> @span model.field.get()
+
+ equal binding.container.find("h1 > span").text(), "value"
+ binding.model.field.set("changed value")
+ equal binding.container.find("h1 > span").text(), "changed value"
+
View
42 test/client/binding/input.coffee
@@ -2,26 +2,22 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- Input:
- "sets input value on initialization": (test) ->
- [mocks, binding] = mock_binding(AS.Binding.Input)
- test.equal "value", binding.content.val()
- test.done()
-
- "updates input value when model changes": (test) ->
- [mocks, binding] = mock_binding(AS.Binding.Input)
- binding.model.field.set("changed value")
- test.equal "changed value", binding.content.val()
- test.done()
-
- "updates model value when input changes": (test) ->
- [mocks, binding] = mock_binding(AS.Binding.Input)
- binding.model.field.set("changed value")
- binding.content.val("user value").trigger("change")
- test.equal "user value", binding.model.field.get()
- test.done()
-
- "inherits from Field": (test) ->
- test.equal AS.Binding.Input.__super__.constructor, AS.Binding.Field
- test.done()
+module "Binding.Input"
+test "sets input value on initialization", ->
+ [mocks, binding] = mock_binding(AS.Binding.Input)
+ equal "value", binding.content.val()
+
+test "updates input value when model changes", ->
+ [mocks, binding] = mock_binding(AS.Binding.Input)
+ binding.model.field.set("changed value")
+ equal "changed value", binding.content.val()
+
+test "updates model value when input changes", ->
+ [mocks, binding] = mock_binding(AS.Binding.Input)
+ binding.model.field.set("changed value")
+ binding.content.val("user value").trigger("change")
+ equal "user value", binding.model.field.get()
+
+test "inherits from Field", ->
+ equal AS.Binding.Input.__super__.constructor, AS.Binding.Field
+
View
134 test/client/binding/many.coffee
@@ -2,95 +2,87 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- Many:
- setUp: (callback) ->
- model = BoundModel.new()
- items = model.items
- items.add()
- items.add()
- items.add()
+module "Binding.Many",
+ setup: ->
+ model = BoundModel.new()
+ items = model.items
+ items.add()
+ items.add()
+ items.add()
- content_fn = (thing) -> @div id: thing.cid.replace(".", "-")
+ content_fn = (thing) -> @div id: thing.cid.replace(".", "-")
- [mocks, binding] = mock_binding(AS.Binding.Many, field: model.items, model: model, fn: content_fn)
+ [mocks, binding] = mock_binding(AS.Binding.Many, field: model.items, model: model, fn: content_fn)
- @items = items
- @binding = binding
- callback()
+ @items = items
+ @binding = binding
- "creates initial collection dom": (test) ->
- test.expect 3
- @items.each (item) =>
- test.ok @binding.container.find("##{item.cid.replace(".", "-")}").is("div")
+test "creates initial collection dom", ->
+ expect 3
+ @items.each (item) =>
+ ok @binding.container.find("##{item.cid.replace(".", "-")}").is("div")
- test.done()
+
+test "adds additional dom elements when items added to collection", ->
+ expect 1
+ item = @items.add()
+ ok @binding.container.find("##{item.cid.replace(".", "-")}").is("div")
- "adds additional dom elements when items added to collection": (test) ->
- test.expect 1
- item = @items.add()
- test.ok @binding.container.find("##{item.cid.replace(".", "-")}").is("div")
+
+test "adds new dom elements at correct index", ->
+ expect 1
+ item = @items.add({}, at: 0)
- test.done()
+ ok @binding.container.children(":first").is("##{item.cid.replace(".", "-")}")
- "adds new dom elements at correct index": (test) ->
- test.expect 1
- item = @items.add({}, at: 0)
+
+test "removes dom elements when item removed from collection", ->
+ item = @items.at(0)
+ @items.remove item
+ ok @binding.container.find("##{item.cid.replace(".", "-")}")[0] is undefined
- test.ok @binding.container.children(":first").is("##{item.cid.replace(".", "-")}")
+module "Binding.HasManyWithFilter"
+ setup: ->
+ model = BoundModel.new()
+ items = model.items
- test.done()
+ content_fn = (thing) -> @div id: thing.cid.replace(".", "-")
- "removes dom elements when item removed from collection": (test) ->
- item = @items.at(0)
- @items.remove item
- test.ok @binding.container.find("##{item.cid.replace(".", "-")}")[0] is undefined
- test.done()
+ [mocks, binding] = mock_binding(AS.Binding.Many,
+ field: items,
+ model: model,
+ fn: content_fn
+ options: filter: (field: ["true", "43"])
+ )
- HasManyWithFilter:
- setUp: (callback) ->
- model = BoundModel.new()
- items = model.items
+ @items = items
+ @binding = binding
- content_fn = (thing) -> @div id: thing.cid.replace(".", "-")
- [mocks, binding] = mock_binding(AS.Binding.Many,
- field: items,
- model: model,
- fn: content_fn
- options: filter: (field: ["true", "43"])
- )
+test "filters items in the collection", ->
+ one = @items.add field: "true"
+ two = @items.add field: "false"
+ three = @items.add field: "43"
- @items = items
- @binding = binding
- callback()
+ equal @binding.container.find("##{one.cid.replace(".", "-")}")[0].id, one.cid.replace(".", "-")
+ equal @binding.container.find("##{two.cid.replace(".", "-")}")[0], undefined
+ equal @binding.container.find("##{three.cid.replace(".", "-")}")[0].id, three.cid.replace(".", "-")
+
+test "moves items into place in the collection when their values change", ->
+ one = @items.add field: true
+ two = @items.add field: false
+ three = @items.add field: true
- "filters items in the collection": (test) ->
- one = @items.add field: "true"
- two = @items.add field: "false"
- three = @items.add field: "43"
+ two.field.set("43")
- test.equal @binding.container.find("##{one.cid.replace(".", "-")}")[0].id, one.cid.replace(".", "-")
- test.equal @binding.container.find("##{two.cid.replace(".", "-")}")[0], undefined
- test.equal @binding.container.find("##{three.cid.replace(".", "-")}")[0].id, three.cid.replace(".", "-")
- test.done()
+ equal @binding.container.children()[1].id, two.cid.replace(".", "-")
- "moves items into place in the collection when their values change": (test) ->
- one = @items.add field: true
- two = @items.add field: false
- three = @items.add field: true
+
+test "removes items when their values change", ->
+ one = @items.add field: true
- two.field.set("43")
+ one.field.set(false)
- test.equal @binding.container.children()[1].id, two.cid.replace(".", "-")
-
- test.done()
-
- "removes items when their values change": (test) ->
- one = @items.add field: true
-
- one.field.set(false)
-
- test.equal @binding.container.children().length, 0
- test.done()
+ equal @binding.container.children().length, 0
+
View
105 test/client/binding/model.coffee
@@ -2,75 +2,72 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- Model:
+module "Binding.Model"
+test "paints styles", ->
+ context = AS.View.new()
+ context_mock = sinon.mock context
+ content = $("<div>")
+ content_mock = sinon.mock content
+ model = AS.Model.new()
+ binding = AS.Binding.Model.new context, model, content
- "paints styles": (test) ->
- context = AS.View.new()
- context_mock = sinon.mock context
- content = $("<div>")
- content_mock = sinon.mock content
- model = AS.Model.new()
- binding = AS.Binding.Model.new context, model, content
+ context_mock.expects('binds').withArgs(model, "change:field1")
+ context_mock.expects('binds').withArgs(model, "change:field2")
- context_mock.expects('binds').withArgs(model, "change:field1")
- context_mock.expects('binds').withArgs(model, "change:field2")
+ binding.css
+ "background-color":
+ fn: (model) -> model.bgcolor or "mock-color"
+ field: ["field1"]
- binding.css
- "background-color":
- fn: (model) -> model.bgcolor or "mock-color"
- field: ["field1"]
+ binding.css
+ "background-color":
+ fn: (model) -> model.bgcolor or "mock-color"
+ field: ["field2"]
- binding.css
- "background-color":
- fn: (model) -> model.bgcolor or "mock-color"
- field: ["field2"]
+ content_mock.expects("css").withExactArgs
+ "background-color": "mock-color"
- content_mock.expects("css").withExactArgs
- "background-color": "mock-color"
+ binding.paint()
- binding.paint()
+ model.bgcolor = "bgcolor"
- model.bgcolor = "bgcolor"
+ content_mock.expects("css").withExactArgs
+ "background-color": "bgcolor"
- content_mock.expects("css").withExactArgs
- "background-color": "bgcolor"
+ model.field1.trigger("change")
- model.field1.trigger("change")
+
+test "paints attributes", ->
+ context = AS.View.new()
+ context_mock = sinon.mock context
+ content = $("<div>")
+ content_mock = sinon.mock content
+ model = AS.Model.new()
+ binding = AS.Binding.Model.new context, model, content
- test.done()
+ context_mock.expects('binds').withArgs(model, "field1")
+ context_mock.expects('binds').withArgs(model, "field2")
- "paints attributes": (test) ->
- context = AS.View.new()
- context_mock = sinon.mock context
- content = $("<div>")
- content_mock = sinon.mock content
- model = AS.Model.new()
- binding = AS.Binding.Model.new context, model, content
+ binding.attr
+ "data-property":
+ fn: (model) -> model.property or "mock-value"
+ field: ["field1"]
- context_mock.expects('binds').withArgs(model, "field1")
- context_mock.expects('binds').withArgs(model, "field2")
+ binding.attr
+ "data-property":
+ fn: (model) -> model.property or "mock-value"
+ field: ["field2"]
- binding.attr
- "data-property":
- fn: (model) -> model.property or "mock-value"
- field: ["field1"]
+ content_mock.expects("attr").withExactArgs
+ "data-property": "mock-value"
- binding.attr
- "data-property":
- fn: (model) -> model.property or "mock-value"
- field: ["field2"]
+ binding.paint()
- content_mock.expects("attr").withExactArgs
- "data-property": "mock-value"
+ model.property = "value2"
- binding.paint()
+ content_mock.expects("attr").withExactArgs
+ "data-property": "value2"
- model.property = "value2"
+ model.field2.trigger("change")
- content_mock.expects("attr").withExactArgs
- "data-property": "value2"
-
- model.field2.trigger("change")
-
- test.done()
+
View
64 test/client/binding/one.coffee
@@ -2,38 +2,32 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- One:
- setUp: (callback) ->
- @model = BoundModel.new( owner: BoundModel.new() )
-
- content_fn = (thing) ->
- @div id: thing.cid.replace('.', '-')
-
- [mocks, binding] = mock_binding(AS.Binding.One, field: @model.owner, model: @model, fn: content_fn)
-
- @binding = binding
- callback()
-
- "creates initial dom": (test) ->
- test.ok @binding.content.find("##{@model.owner.get().cid.replace('.', '-')}").is("div")
- test.done()
-
- "clears dom when field is null": (test) ->
- @binding.model.owner.set(null)
- test.equal undefined, @model.owner.get()
- test.equal "", @binding.content.html()
- test.done()
-
- "does nothing when model properties change": (test) ->
- el = @binding.content.containerChildren[0]
- @binding.model.owner.get().field.set("Changed Name")
- test.equal el, @binding.content.containerChildren[0]
- test.done()
-
- "passes a model binding to the content_fn": (test) ->
- @binding.fn = (model, binding) ->
- test.equal AS.Binding.Model, binding.constructor
- test.done()
-
- @binding.setContent()
+module "Binding.One",
+ setup: (callback) ->
+ @model = BoundModel.new( owner: BoundModel.new() )
+
+ content_fn = (thing) ->
+ @div id: thing.cid.replace('.', '-')
+
+ [mocks, binding] = mock_binding(AS.Binding.One, field: @model.owner, model: @model, fn: content_fn)
+
+ @binding = binding
+
+test "creates initial dom", ->
+ ok @binding.content.find("##{@model.owner.get().cid.replace('.', '-')}").is("div")
+
+test "clears dom when field is null", ->
+ @binding.model.owner.set(null)
+ equal undefined, @model.owner.get()
+ equal "", @binding.content.html()
+
+test "does nothing when model properties change", ->
+ el = @binding.content.containerChildren[0]
+ @binding.model.owner.get().field.set("Changed Name")
+ equal el, @binding.content.containerChildren[0]
+
+test "passes a model binding to the content_fn", ->
+ @binding.fn = (model, binding) ->
+ equal AS.Binding.Model, binding.constructor
+
+ @binding.setContent()
View
88 test/client/binding/select.coffee
@@ -2,63 +2,57 @@
SimpleModel, mock_binding, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.Binding =
- Select:
- "must provide options option": (test) ->
- test.throws (-> mock_binding(AS.Binding.Select)), AS.Binding.MissingOption
- test.done()
+module "Binding.Select"
+test "must provide options option", ->
+ raises (-> mock_binding(AS.Binding.Select)), AS.Binding.MissingOption
+
+test "uses provided Array for select options", ->
+ options = [1..3]
+ [mocks, binding] = mock_binding(AS.Binding.Select, options: options: options)
- "uses provided Array for select options": (test) ->
- options = [1..3]
- [mocks, binding] = mock_binding(AS.Binding.Select, options: options: options)
+ equal binding.container.find("option").length, 3
+ equal binding.container.find("select").text(), "123"
- test.equal binding.container.find("option").length, 3
- test.equal binding.container.find("select").text(), "123"
+
+test "uses provided Object for select options", ->
+ options =
+ "one": 1
+ "two": 2
+ "three": 3
+ [mocks, binding] = mock_binding(AS.Binding.Select, options: options: options)
- test.done()
+ equal binding.container.find("option").length, 3
- "uses provided Object for select options": (test) ->
- options =
- "one": 1
- "two": 2
- "three": 3
- [mocks, binding] = mock_binding(AS.Binding.Select, options: options: options)
+ for key, value of options
+ equal $(binding.container.find("option[value='#{value}']")).text(), key
- test.equal binding.container.find("option").length, 3
+
+test "sets select value on initialization", ->
+ model = BoundModel.new field: "value"
+ options = ["notvalue", "value"]
+ [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
- for key, value of options
- test.equal $(binding.container.find("option[value='#{value}']")).text(), key
+ equal binding.container.find("select").val(), "value"
- test.done()
+
+test "sets value of dom when model value changes", ->
+ model = BoundModel.new field: "value"
+ options = ["notvalue", "value"]
+ [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
- "sets select value on initialization": (test) ->
- model = BoundModel.new field: "value"
- options = ["notvalue", "value"]
- [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
+ model.field.set("notvalue")
- test.equal binding.container.find("select").val(), "value"
+ equal binding.container.find("select").val()[0], "notvalue"
- test.done()
+
+test "sets value on object when dom changes", ->
+ model = BoundModel.new field: "value"
+ options = ["notvalue", "value"]
+ [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
- "sets value of dom when model value changes": (test) ->
- model = BoundModel.new field: "value"
- options = ["notvalue", "value"]
- [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
+ binding.container.find("select").val("notvalue")
+ binding.container.find("select").trigger("change")
- model.field.set("notvalue")
+ equal model.field.get(), "notvalue"
- test.equal binding.container.find("select").val()[0], "notvalue"
-
- test.done()
-
- "sets value on object when dom changes": (test) ->
- model = BoundModel.new field: "value"
- options = ["notvalue", "value"]
- [mocks, binding] = mock_binding(AS.Binding.Select, options: (options: options), model: model)
-
- binding.container.find("select").val("notvalue")
- binding.container.find("select").trigger("change")
-
- test.equal model.field.get(), "notvalue"
-
- test.done()
+
View
142 test/client/binding_group.coffee
@@ -1,74 +1,70 @@
{AS, $, _, sinon} = require require("path").resolve("./test/client_helper")
-exports.BindingGroup =
- "has a unique namespace": (test) ->
- bg1 = AS.BindingGroup.new()
- bg2 = AS.BindingGroup.new()
-
- test.notEqual bg1.namespace, bg2.namespace
- test.equal bg1.namespace[0], "b"
-
- test.done()
-
- "binds to jquery objects": (test) ->
- bg = AS.BindingGroup.new()
-
- object = jquery: true, bind: ->
- mock = sinon.mock(object)
- handler = ->
-
- mock.expects("bind").withArgs("event.#{bg.namespace}")
- bg.binds object, "event", handler
-
- mock.verify()
-
- test.done()
-
- "binds to AS.Event event model": (test) ->
- bg = AS.BindingGroup.new()
-
- object = bind: ->
- mock = sinon.mock(object)
- handler = ->
- mock.expects("bind").withExactArgs
- event: "event"
- namespace: bg.namespace
- handler: handler
- context: object
- bg.binds object, "event", handler, object
- mock.verify()
-
- test.done()
-
- "unbinds bound objects": (test) ->
- bg = AS.BindingGroup.new()
-
- object =
- bind: ->
- unbind: ->
-
- mock = sinon.mock(object)
- handler = ->
- mock.expects("unbind").withExactArgs("."+bg.namespace)
- bg.binds object, "event", handler, object
- bg.unbind()
- mock.verify()
-
- test.done()
-
-
- "unbinds bound objects in nested binding groups": (test) ->
- parent = AS.BindingGroup.new()
- child = parent.addChild()
-
- object =
- bind: ->
- unbind: ->
-
- mock = sinon.mock(object)
- handler = ->
- mock.expects("unbind").withExactArgs("."+child.namespace)
- child.binds object, "event", handler, object
- parent.unbind()
- mock.verify()
-
- test.done()
+module "BindingGroup"
+test "has a unique namespace", ->
+ bg1 = AS.BindingGroup.new()
+ bg2 = AS.BindingGroup.new()
+
+ notEqual bg1.namespace, bg2.namespace
+ equal bg1.namespace[0], "b"
+
+
+test "binds to jquery objects", ->
+ bg = AS.BindingGroup.new()
+
+ object = jquery: true, bind: ->
+ mock = sinon.mock(object)
+ handler = ->
+
+ mock.expects("bind").withArgs("event.#{bg.namespace}")
+ bg.binds object, "event", handler
+
+ mock.verify()
+
+
+test "binds to AS.Event event model", ->
+ bg = AS.BindingGroup.new()
+
+ object = bind: ->
+ mock = sinon.mock(object)
+ handler = ->
+ mock.expects("bind").withExactArgs
+ event: "event"
+ namespace: bg.namespace
+ handler: handler
+ context: object
+ bg.binds object, "event", handler, object
+ mock.verify()
+
+
+test "unbinds bound objects", ->
+ bg = AS.BindingGroup.new()
+
+ object =
+ bind: ->
+ unbind: ->
+
+ mock = sinon.mock(object)
+ handler = ->
+ mock.expects("unbind").withExactArgs("."+bg.namespace)
+ bg.binds object, "event", handler, object
+ bg.unbind()
+ mock.verify()
+
+
+
+test "unbinds bound objects in nested binding groups", ->
+ parent = AS.BindingGroup.new()
+ child = parent.addChild()
+
+ object =
+ bind: ->
+ unbind: ->
+
+ mock = sinon.mock(object)
+ handler = ->
+ mock.expects("unbind").withExactArgs("."+child.namespace)
+ child.binds object, "event", handler, object
+ parent.unbind()
+ mock.verify()
+
+
View
47 test/client/dom.coffee
@@ -1,28 +1,27 @@
{AS, $, _, sinon} = require require("path").resolve("./test/client_helper")
-exports.DOM =
- "creates document fragments": (test) ->
- html = AS.DOM.new().html ->
- @head ->
- @title "This is the Title"
- @body ->
- @h1 "This is the Header"
- @section ->
- @p "I'm the body copy :D"
- @div "data-custom": "attributes!"
- test.equal $(html).find("title").text(), "This is the Title"
- test.equal $(html).find("h1").text(), "This is the Header"
- test.equal $(html).find("p").text(), "I'm the body copy :D"
- test.equal $(html).find("[data-custom]").data().custom, "attributes!"
+module "DOM"
+test "creates document fragments", ->
+ html = AS.DOM.new().html ->
+ @head ->
+ @title "This is the Title"
+ @body ->
+ @h1 "This is the Header"
+ @section ->
+ @p "I'm the body copy :D"
+ @div "data-custom": "attributes!"
- test.done()
+ equal $(html).find("title").text(), "This is the Title"
+ equal $(html).find("h1").text(), "This is the Header"
+ equal $(html).find("p").text(), "I'm the body copy :D"
+ equal $(html).find("[data-custom]").data().custom, "attributes!"
- "appends raw (scary html) content": (test) ->
- raw = AS.DOM.new().raw("<html>")
- test.ok $(raw).find("html").is("html")
- test.done()
-
- "appends escaped (non-scary html) content": (test)->
- raw = AS.DOM.new().span -> @text("<html>")
- test.equal $(raw).find("html")[0], undefined
- test.done()
+
+test "appends raw (scary html) content", ->
+ raw = AS.DOM.new().raw("<html>")
+ ok $(raw).find("html").is("html")
+
+test "appends escaped (non-scary html) content": (test)->
+ raw = AS.DOM.new().span -> @text("<html>")
+ equal $(raw).find("html")[0], undefined
+
View
246 test/client/models/targets.coffee
@@ -14,8 +14,8 @@ class ClientRect
@right = @left + @width
@bottom = @top + @height
-exports.Targets =
- setUp: (callback) ->
+module "Targets",
+ setup: (callback) ->
body = $("body")
body.empty()
body.append "<target />"
@@ -36,164 +36,149 @@ exports.Targets =
@t3.getBoundingClientRect = ->
new ClientRect top: 100, width: 100, height: 50
- callback()
-
- "gathers targets": (test) ->
+test "gathers targets", ->
targets = NS.SomeTargets.new().targets
- test.equal targets.length, 3
- test.equal targets[1].el[0], @t2
- test.equal targets[1].rect.top, 50, 'top'
- test.equal targets[1].rect.right, 100, 'right'
- test.equal targets[1].rect.bottom, 100, 'bottom'
- test.equal targets[1].rect.left, 0, 'left'
- test.equal targets[1].rect.width, 100, 'width'
- test.equal targets[1].rect.height, 50, 'height'
- test.done()
-
- "dropend triggers dropend event": (test) ->
+ equal targets.length, 3
+ equal targets[1].el[0], @t2
+ equal targets[1].rect.top, 50, 'top'
+ equal targets[1].rect.right, 100, 'right'
+ equal targets[1].rect.bottom, 100, 'bottom'
+ equal targets[1].rect.left, 0, 'left'
+ equal targets[1].rect.width, 100, 'width'
+ equal targets[1].rect.height, 50, 'height'
+
+test "dropend triggers dropend event", ->
targets = NS.SomeTargets.new()
- test.expect 1
- targets.bind "dropend", -> test.ok true
+ expect 1
+ targets.bind "dropend", -> ok true
targets.dropend()
- test.done()
-
- "dropstart triggers dropstart event if current hit has a rect": (test) ->
+
+test "dropstart triggers dropstart event if current hit has a rect", ->
targets = NS.SomeTargets.new()
hit = rect: true
targets.current_hit = hit
- test.expect 1
- targets.bind "dropstart", (thehit) -> test.equal hit, thehit
+ expect 1
+ targets.bind "dropstart", (thehit) -> equal hit, thehit
targets.dropstart()
- test.done()
-
- "dropstart is a noop if current hit lacks a rect": (test) ->
+
+test "dropstart is a noop if current hit lacks a rect", ->
targets = NS.SomeTargets.new()
- test.expect 0
- targets.bind "dropstart", -> test.ok true
+ expect 0
+ targets.bind "dropstart", -> ok true
targets.dropstart()
- test.done()
-
- "dragend calls drop and triggers drop if current hit has a rect": (test) ->
+
+test "dragend calls drop and triggers drop if current hit has a rect", ->
targets = NS.SomeTargets.new()
hit = rect: true
data = new Object
targets.current_hit = hit
- test.expect 2
- targets.bind "drop", (thehit) -> test.equal hit, thehit
- targets.drop = (thedata) -> test.equal thedata, data
+ expect 2
+ targets.bind "drop", (thehit) -> equal hit, thehit
+ targets.drop = (thedata) -> equal thedata, data
targets.dragend(data)
- test.done()
-
- "dragend is a noop if current hit lacks a rect": (test) ->
+
+test "dragend is a noop if current hit lacks a rect", ->
targets = NS.SomeTargets.new()
data = new Object
- test.expect 0
- targets.bind "drop", (thehit) -> test.equal hit, thehit
- targets.drop = (thedata) -> test.equal thedata, data
+ expect 0
+ targets.bind "drop", (thehit) -> equal hit, thehit
+ targets.drop = (thedata) -> equal thedata, data
targets.dragend(data)
- test.done()
-
- "transition_hit()":
- "noop if hit has no rect": (test) ->
+
+test "noop if hit has no rect", ->
targets = NS.SomeTargets.new()
- targets.dropend = -> test.ok true
- test.expect 0
+ targets.dropend = -> ok true
+ expect 0
targets.transition_hit {}
- test.done()
-
- "noop if currenth hit equals hit": (test) ->
+
+test "noop if currenth hit equals hit", ->
targets = NS.SomeTargets.new()
targets.current_hit = equals: -> true
- targets.dropend = -> test.ok true
- test.expect 0
+ targets.dropend = -> ok true
+ expect 0
targets.transition_hit {}
- test.done()
-
- "transitions if current hit does not equal hit": (test) ->
+
+test "transitions if current hit does not equal hit", ->
targets = NS.SomeTargets.new()
targets.current_hit = equals: -> false
hit = rect: true
- test.expect 2
+ expect 2
targets.dropend = ->
- test.ok targets.current_hit isnt hit
+ ok targets.current_hit isnt hit
targets.dropstart = ->
- test.ok targets.current_hit is hit
+ ok targets.current_hit is hit
targets.transition_hit hit
- test.done()
-
+
target_event = (x, y) ->
return {
- "jquery/event": originalEvent:
+test "jquery/event": originalEvent:
clientX: x, clientY: y
}
-exports.Targets.Edge =
- setUp: (callback) ->
- @targets = AS.Models.Targets.Edge.new()
- @el = {}
- @rect = new ClientRect width: 100, height: 50
- @targets.targets = [
- el: @el
- rect: @rect
- ]
+
+setupEdgeTargets = ->
+ @targets = AS.Models.Targets.Edge.new()
+ @el = {}
+ @rect = new ClientRect width: 100, height: 50
+ @targets.targets = [
+ el: @el
+ rect: @rect
+ ]
+
+module "Targets.Edge",
+
+module "Targets.Edge.vertical_target",
+ setup: ->
+ setupEdgeTargets.call(this)
+ @check = (x, y) =>
+ @targets.vertical_target target_event(x, y)
callback()
- "vertical_target":
- setUp: (callback) ->
- @check = (x, y) =>
- @targets.vertical_target target_event(x, y)
- callback()
-
- "misses when not inside box": (test) ->
- test.equal null, @check(-1, -1), "before"
- test.equal null, @check(101, 51), "after"
- test.equal null, @check(70, 101), "inside x, outside y"
- test.equal null, @check(50, 130), "outside x, inside y"
- test.done()
-
- "hits when inside the box": (test) ->
- test.ok @check(100, 80), "within edge x, inside y"
- test.ok @check(0, -30), "within edge x, inside y"
- test.done()
-
- "hits TOP/BOTTOM": (test) ->
+test "misses when not inside box", ->
+ equal null, @check(-1, -1), "before"
+ equal null, @check(101, 51), "after"
+ equal null, @check(70, 101), "inside x, outside y"
+ equal null, @check(50, 130), "outside x, inside y"
+
+test "hits when inside the box", ->
+ ok @check(100, 80), "within edge x, inside y"
+ ok @check(0, -30), "within edge x, inside y"
+
+test "hits TOP/BOTTOM", ->
hit = @check(0, 0)
- test.equal hit.section, hit.TOP
+ equal hit.section, hit.TOP
hit = @check(0, 50)
- test.equal hit.section, hit.BOTTOM
- test.done()
-
- "horizontal_target":
- setUp: (callback) ->
- @check = (x, y) =>
- @targets.horizontal_target target_event(x, y)
- callback()
-
- "misses when not inside box": (test) ->
- test.equal null, @check(-1, -1), "before"
- test.equal null, @check(101, 51), "after"
- test.equal null, @check(70, 101), "outside x, inside y"
- test.equal null, @check(50, 50), "inside x, outside y"
- test.done()
-
- "hits when inside the box": (test) ->
- test.ok @check(130, 50), "within x, inside edge y"
- test.ok @check(-30, 0), "within x, inside edge y"
- test.done()
-
- "hits LEFT/RIGHT": (test) ->
- hit = @check(0, 0)
- test.equal hit.section, hit.LEFT
-
- hit = @check(100, 0)
- test.equal hit.section, hit.RIGHT
-
- test.done()
+ equal hit.section, hit.BOTTOM
+
+module "Targets.Edge.horizontal_target",
+ setup: (callback) ->
+ setupEdgeTargets.call(this)
+ @check = (x, y) =>
+ @targets.horizontal_target target_event(x, y)
+ callback()
-exports.Targets.Thirds =
- setUp: (callback) ->
+test "misses when not inside box", ->
+ equal null, @check(-1, -1), "before"
+ equal null, @check(101, 51), "after"
+ equal null, @check(70, 101), "outside x, inside y"
+ equal null, @check(50, 50), "inside x, outside y"
+
+test "hits when inside the box", ->
+ ok @check(130, 50), "within x, inside edge y"
+ ok @check(-30, 0), "within x, inside edge y"
+
+test "hits LEFT/RIGHT", ->
+ hit = @check(0, 0)
+ equal hit.section, hit.LEFT
+
+ hit = @check(100, 0)
+ equal hit.section, hit.RIGHT
+
+
+module "Targets.Thirds",
+ setup: ->
@targets = AS.Models.Targets.Thirds.new()
@el = {}
@rect = new ClientRect width: 100, height: 50
@@ -206,21 +191,18 @@ exports.Targets.Thirds =
@targets.target target_event(x, y)
callback()
-
- "misses when not inside vertically": (test) ->
- test.equal null, @check(0, -1), "before"
- test.equal null, @check(0, 51), "after"
- test.done()
-
- "hits TOP/MIDDLE/BOTTOM": (test) ->
+test "misses when not inside vertically", ->
+ equal null, @check(0, -1), "before"
+ equal null, @check(0, 51), "after"
+
+test "hits TOP/MIDDLE/BOTTOM", ->
hit = @check(0, 0)
- test.equal hit.section, hit.TOP
+ equal hit.section, hit.TOP
hit = @check(0, 25)
- test.equal hit.section, hit.MIDDLE
+ equal hit.section, hit.MIDDLE
hit = @check(0, 50)
- test.equal hit.section, hit.BOTTOM
-
- test.done()
+ equal hit.section, hit.BOTTOM
+
View
389 test/client/view.coffee
@@ -1,207 +1,184 @@
{AS, $, _, sinon, NS} = require require("path").resolve("./test/client_helper")
-exports.View =
- "generates klass strings": (test) ->
- test.equal AS.View.new().klassString(), "View", "basic klassString is ASView"
-
- NS.SomeView = AS.View.extend()
-
- test.equal NS.SomeView.new().klassString(), "View SomeView", "subclasses include parent class string"
-
- test.done()
-
- "builds an element": (test) ->
- test.ok AS.View.new().el.is("div")
- NS.ListView = AS.View.extend ({def}) ->
- def tagName: "ol"
-
- test.ok NS.ListView.new().el.is("ol.View.ListView")
- test.done()
-
- "sets options from constructor": (test) ->
- test.equal AS.View.new(this: "that").this, "that"
- test.done()
-
- "turns Model options into AS.ViewModels": (test) ->
- it = AS.Model.new()
- view = AS.View.new(it:it)
- test.ok view.it instanceof AS.ViewModel
- test.done()
-
- "has a root binding group": (test) ->
- test.ok AS.View.new().bindingGroup instanceof AS.BindingGroup
- test.done()
-
- "pluralizes text": (test) ->
- view = AS.View.new()
- test.equal view.pluralize("cat", 4), "cats"
- test.equal view.pluralize("person", 0), "people"
- test.equal view.pluralize("duck", 1), "duck"
- test.equal view.pluralize("duck", -1), "duck"
- test.equal view.pluralize("cat", -4), "cats"
- test.done()
-
- "delegates view methods to @el": (test) ->
- methods = ['addClass', 'removeClass', 'show', 'hide', 'html']
- test.expect methods.length
- view = AS.View.new()
- view.el = el = {}
-
- for method in methods
- el[method] = -> test.ok(true)
- view[method]()
-
- test.done()
-
- "allows view element to be set as an option in the constructor": (test) ->
- el = $("<div>")
- view = AS.View.new(el:el)
- test.equal el[0], view.currentNode
- test.done()
-
- "stashes childViews": (test) ->
- test.deepEqual [], AS.View.new().childViews
- test.done()
-
- "views have a 'view' method to create child views": (test) ->
- view = AS.View.new()
- returned = view.view AS.View, el: subEl = view.div()
- test.equal subEl, returned
- test.equal subEl, view.childViews[0].el[0]
-
- # child view is added to the bindingGroup's children so 'unbind'
- # will be called on the view object.
- test.equal view.childViews[0], view.bindingGroup.children.reverse()[0]
-
- test.done()
-
- # "when view is unbound it is removed from it's parents childViews and from the DOM": (test) ->
- # view = AS.View.new()
- # view.view(AS.View, el: view.div(-> @h1()))
- # view.bindingGroup.unbind()
- # test.deepEqual [], view.childViews
- # test.equal "", view.html()
- # test.done()
-
- "binding()":
- "creates a binding for a collection": (test) ->
- view = AS.View.new()
- collection = AS.Collection.new()
- test.ok view.binding(collection, ->).constructor is AS.Binding.Many
- test.done()
-
- "creates a binding for a model": (test) ->
- view = AS.View.new()
- model = AS.Model.new()
- test.ok view.binding(model).constructor is AS.Binding.Model
- test.done()
-
-
- "descendantViews()":
- "returns all descendantViews": (test) ->
- view = AS.View.new()
- view.view AS.View
- view.childViews[0].view AS.View
-
- test.equal 2, view.descendantViews().length
- test.done()
-
- "filters descendantViews by constructor": (test) ->
- NS.SubView = AS.View.extend()
- view = AS.View.new()
- view.view NS.SubView
- view.childViews[0].view AS.View
-
- test.equal 1, view.descendantViews(null, NS.SubView).length
- test.done()
-
-exports["View Integration"] =
- "property binding with two children":
- setUp: (callback) ->
- NS.Parent = AS.Model.extend ({delegate, include, def, defs}) ->
- @property "item"
-
- NS.Item = AS.Model.extend ({delegate, include, def, defs}) ->
- @hasMany 'children', model: -> NS.Child
-
- NS.Child = AS.Model.extend ({delegate, include, def, defs}) ->
- @field 'name'
-
-
- @item1 = NS.Item.new()
- @item2 = NS.Item.new()
-
- @item1.children.add name: "child1"
- @item1.children.add name: "child2"
-
- @item2.children.add name: "child3"
- @item2.children.add name: "child4"
-
- @parent = NS.Parent.new(item: @item1)
-
- NS.View = AS.View.extend ({delegate, include, def, defs}) ->
- def content: ->
- binding = @parent.binding 'item', (item) ->
- @ol ->
- item.binding 'children', (child) ->
- @li -> child.binding 'name'
- @ul ->
- item.binding 'children', (child) ->
- @li -> child.binding 'name'
-
- @view = NS.View.new(parent: @parent)
- callback()
-
- "cleans up all content when property changes": (test) ->
- test.equal 2, @view.el.find("ol li").length
- test.equal 2, @view.el.find("ul li").length
- @parent.item.set(null)
- test.equal 0, @view.el.find("ol li").length
- test.equal 0, @view.el.find("ul li").length
- test.done()
-
- "property binding nested ina property binding":
- setUp: (callback) ->
- NS.Model = AS.Model.extend ({delegate, include, def, defs}) ->
- @property "other"
- @hasMany "children"
-
- NS.View = AS.View.extend ({delegate, include, def, defs}) ->
- def content: ->
- @root.binding 'other', (other) ->
- @section class: "root-other", id:other.model.objectId(), ->
- other.binding 'children', (child) ->
- @section id: child.model.objectId()
-
- binding = @model.binding 'other', ->
- @section class:"model-other"
-
- @root = NS.Model.new()
-
- @thing1 = NS.Model.new children: [{}]
- @thing2 = NS.Model.new children: [{}, {}]
-
- @other1 = NS.Model.new()
- @other2 = NS.Model.new()
- @model = NS.Model.new(other: @other1)
-
- @view = NS.View.new(root: @root, model: @model)
-
- callback()
-
- "cleans up bindings": (test) ->
- otherBinding = NS.OtherBinding
-
- @root.other.set(@thing1)
- test.ok @view.el.find("##{@thing1.objectId()}").is("*"), "renders first thing"
- test.ok @view.el.find("##{@thing1.children.at(0).objectId()}").is("*"), "renders first thing child"
-
- @root.other.set(@thing2)
- test.ok @view.el.find("##{@thing2.objectId()}").is("*"), "renders second thing"
- test.ok @view.el.find("##{@thing2.children.at(0).objectId()}").is("*"), "renders second thing first child"
- test.ok @view.el.find("##{@thing2.children.at(1).objectId()}").is("*"), "renders second thing second child"
-
- @model.other.set(@other2)
-
- test.equal 1, @view.el.find(".model-other").length, "renders only one other"
- test.ok @view.el.find("##{@thing2.objectId()}").is("*"), "second thing still visiible"
- test.done()
+module "View"
+test "generates klass strings", ->
+ equal AS.View.new().klassString(), "View", "basic klassString is ASView"
+
+ NS.SomeView = AS.View.extend()
+
+ equal NS.SomeView.new().klassString(), "View SomeView", "subclasses include parent class string"
+
+
+test "builds an element", ->
+ ok AS.View.new().el.is("div")
+ NS.ListView = AS.View.extend ({def}) ->
+ def tagName: "ol"
+
+ ok NS.ListView.new().el.is("ol.View.ListView")
+
+test "sets options from constructor", ->
+ equal AS.View.new(this: "that").this, "that"
+
+test "turns Model options into AS.ViewModels", ->
+ it = AS.Model.new()
+ view = AS.View.new(it:it)
+ ok view.it instanceof AS.ViewModel
+
+test "has a root binding group", ->
+ ok AS.View.new().bindingGroup instanceof AS.BindingGroup
+
+test "pluralizes text", ->
+ view = AS.View.new()
+ equal view.pluralize("cat", 4), "cats"
+ equal view.pluralize("person", 0), "people"
+ equal view.pluralize("duck", 1), "duck"
+ equal view.pluralize("duck", -1), "duck"
+ equal view.pluralize("cat", -4), "cats"
+
+test "delegates view methods to @el", ->
+ methods = ['addClass', 'removeClass', 'show', 'hide', 'html']
+ expect methods.length
+ view = AS.View.new()
+ view.el = el = {}
+
+ for method in methods
+ el[method] = -> ok(true)
+ view[method]()
+
+
+test "allows view element to be set as an option in the constructor", ->
+ el = $("<div>")
+ view = AS.View.new(el:el)
+ equal el[0], view.currentNode
+
+test "stashes childViews", ->
+ deepEqual [], AS.View.new().childViews
+
+test "views have a 'view' method to create child views", ->
+ view = AS.View.new()
+ returned = view.view AS.View, el: subEl = view.div()
+ equal subEl, returned
+ equal subEl, view.childViews[0].el[0]
+
+ # child view is added to the bindingGroup's children so 'unbind'
+ # will be called on the view object.
+ equal view.childViews[0], view.bindingGroup.children.reverse()[0]
+
+
+# "when view is unbound it is removed from it's parents childViews and from the DOM", ->
+# view = AS.View.new()
+# view.view(AS.View, el: view.div(-> @h1()))
+# view.bindingGroup.unbind()
+# deepEqual [], view.childViews
+# equal "", view.html()
+#
+
+module "View.binding()"
+test "creates a binding for a collection", ->
+ view = AS.View.new()
+ collection = AS.Collection.new()
+ ok view.binding(collection, ->).constructor is AS.Binding.Many
+
+test "creates a binding for a model", ->
+ view = AS.View.new()
+ model = AS.Model.new()
+ ok view.binding(model).constructor is AS.Binding.Model
+
+
+module "View.descendantViews()"
+test "returns all descendantViews", ->
+ view = AS.View.new()
+ view.view AS.View
+ view.childViews[0].view AS.View
+
+ equal 2, view.descendantViews().length
+
+test "filters descendantViews by constructor", ->
+ NS.SubView = AS.View.extend()
+ view = AS.View.new()
+ view.view NS.SubView
+ view.childViews[0].view AS.View
+
+ equal 1, view.descendantViews(null, NS.SubView).length
+
+module "View Integration: "
+test "property binding with two children cleans up all content when property changes", ->
+ NS.Parent = AS.Model.extend ({delegate, include, def, defs}) ->
+ @property "item"
+
+ NS.Item = AS.Model.extend ({delegate, include, def, defs}) ->
+ @hasMany 'children', model: -> NS.Child
+
+ NS.Child = AS.Model.extend ({delegate, include, def, defs}) ->
+ @field 'name'
+
+
+ @item1 = NS.Item.new()
+ @item2 = NS.Item.new()
+
+ @item1.children.add name: "child1"
+ @item1.children.add name: "child2"
+
+ @item2.children.add name: "child3"
+ @item2.children.add name: "child4"
+
+ @parent = NS.Parent.new(item: @item1)
+
+ NS.View = AS.View.extend ({delegate, include, def, defs}) ->
+ def content: ->
+ binding = @parent.binding 'item', (item) ->
+ @ol ->
+ item.binding 'children', (child) ->
+ @li -> child.binding 'name'
+ @ul ->
+ item.binding 'children', (child) ->
+ @li -> child.binding 'name'
+
+ @view = NS.View.new(parent: @parent)
+ equal 2, @view.el.find("ol li").length
+ equal 2, @view.el.find("ul li").length
+ @parent.item.set(null)
+ equal 0, @view.el.find("ol li").length
+ equal 0, @view.el.find("ul li").length
+
+test "property binding nested ina property binding test cleans up bindings", ->
+ NS.Model = AS.Model.extend ({delegate, include, def, defs}) ->
+ @property "other"
+ @hasMany "children"
+
+ NS.View = AS.View.extend ({delegate, include, def, defs}) ->
+ def content: ->
+ @root.binding 'other', (other) ->
+ @section class: "root-other", id:other.model.objectId(), ->
+ other.binding 'children', (child) ->
+ @section id: child.model.objectId()
+
+ binding = @model.binding 'other', ->
+ @section class:"model-other"
+
+ @root = NS.Model.new()
+
+ @thing1 = NS.Model.new children: [{}]
+ @thing2 = NS.Model.new children: [{}, {}]
+
+ @other1 = NS.Model.new()
+ @other2 = NS.Model.new()
+ @model = NS.Model.new(other: @other1)
+
+ @view = NS.View.new(root: @root, model: @model)
+
+ otherBinding = NS.OtherBinding
+
+ @root.other.set(@thing1)
+ ok @view.el.find("##{@thing1.objectId()}").is("*"), "renders first thing"
+ ok @view.el.find("##{@thing1.children.at(0).objectId()}").is("*"), "renders first thing child"
+
+ @root.other.set(@thing2)
+ ok @view.el.find("##{@thing2.objectId()}").is("*"), "renders second thing"
+ ok @view.el.find("##{@thing2.children.at(0).objectId()}").is("*"), "renders second thing first child"
+ ok @view.el.find("##{@thing2.children.at(1).objectId()}").is("*"), "renders second thing second child"
+
+ @model.other.set(@other2)
+
+ equal 1, @view.el.find(".model-other").length, "renders only one other"
+ ok @view.el.find("##{@thing2.objectId()}").is("*"), "second thing still visiible"
+
View
82 test/client/view_events.coffee
@@ -1,35 +1,35 @@
{AS, $, _, sinon, coreSetUp} = require require("path").resolve("./test/client_helper")
exports.setUp = coreSetUp
-exports.ViewEvents =
- "delegates events": (test) ->
- test.expect 3
- BoundView = AS.View.extend ({def}) ->
- def events:
- "click": "click_handler"
- "click button": "button_handler"
- "event @member": "member_handler"
+module "ViewEvents"
+test "delegates events", ->
+ expect 3
- def initialize: ->
- @member = AS.Model.new()
- @_super.apply(this, arguments)
- @_button = @$ @button()
+ BoundView = AS.View.extend ({def}) ->
+ def events:
+ "click": "click_handler"
+ "click button": "button_handler"
+ "event @member": "member_handler"
- def click_handler: -> test.ok true
- def member_handler: -> test.ok true
- def button_handler: -> test.ok true
- def guard_fail_handler: -> test.ok true
- def guard_pass_handler: -> test.ok true
+ def initialize: ->
+ @member = AS.Model.new()
+ @_super.apply(this, arguments)
+ @_button = @$ @button()
- view = BoundView.new()
+ def click_handler: -> ok true
+ def member_handler: -> ok true
+ def button_handler: -> ok true
+ def guard_fail_handler: -> ok true
+ def guard_pass_handler: -> ok true
- view.member.trigger("event")
- view._button.trigger("click")
+ view = BoundView.new()
- test.done()
+ view.member.trigger("event")
+ view._button.trigger("click")
+
# rethinkign stately and other types of event guarding
- # "registers state event": (test) ->
+ # "registers state event", ->
# StatelyView = AS.View.extend ({def}) ->
# def left_events:
# "event": "event_handler"
@@ -42,14 +42,13 @@ exports.ViewEvents =
# view = StatelyView.new()
- # test.ok view.state_events.left instanceof AS.ViewEvents
- # test.ok view.state_events.right instanceof AS.ViewEvents
+ # ok view.state_events.left instanceof AS.ViewEvents
+ # ok view.state_events.right instanceof AS.ViewEvents
- # test.done()
-
- # "bind and unbinds state events on state changes": (test) ->
- # test.expect 5
+ #
+ # "bind and unbinds state events on state changes", ->
+ # expect 5
# StatelyView = AS.View.extend ({def}) ->
@@ -59,15 +58,15 @@ exports.ViewEvents =
# def right_events:
# "click": "other_event_handler"
- # def event_handler: -> test.equal "left", @state
- # def other_event_handler: -> test.ok "right", @state
+ # def event_handler: -> equal "left", @state
+ # def other_event_handler: -> ok "right", @state
# view = StatelyView.new()
- # view.bind "exitstate:left", -> test.ok true
- # view.bind "enterstate:left", -> test.ok true
- # view.bind "exitstate:right", -> test.ok true
- # view.bind "enterstate:right", -> test.ok true
+ # view.bind "exitstate:left", -> ok true
+ # view.bind "enterstate:left", -> ok true
+ # view.bind "exitstate:right", -> ok true
+ # view.bind "enterstate:right", -> ok true
# view.transition_state from: undefined, to: "left"
# view.el.trigger "click"
@@ -76,9 +75,8 @@ exports.ViewEvents =
# view.el.trigger "click"
- # test.done()
-
- # "bind state transition events": (test) ->
+ #
+ # "bind state transition events", ->
# StatelyView = AS.View.extend ({def}) ->
# def left_events:
# "click": "event_handler"
@@ -90,8 +88,8 @@ exports.ViewEvents =
# "crank @": transition:
# from: "right", to: "left"
- # def event_handler: -> test.equal "left", @state
- # def other_event_handler: -> test.ok "right", @state
+ # def event_handler: -> equal "left", @state
+ # def other_event_handler: -> ok "right", @state
# def initialize: ->
# @_super()
@@ -99,8 +97,8 @@ exports.ViewEvents =
# view = StatelyView.new()
# view.trigger 'crank'
- # test.equal view.state, "right"
+ # equal view.state, "right"
# view.trigger 'crank'
- # test.equal view.state, "left"
+ # equal view.state, "left"
- # test.done()
+ #
View
42 test/client/view_model.coffee
@@ -19,31 +19,29 @@ NS.Viewed = AS.Model.extend ({def}) ->
def other: ->
-exports.ViewModel =
- "builds viewmodels": (test) ->
- view = NS.AView.new()
- model = NS.Viewed.new()
- vm = AS.ViewModel.build view, model
+module "ViewModel"
+test "builds viewmodels", ->
+ view = NS.AView.new()
+ model = NS.Viewed.new()
+ vm = AS.ViewModel.build view, model
- test.equal vm.view, view
- test.equal vm.model, model
+ equal vm.view, view
+ equal vm.model, model
- test.done()
+
+test "caches constructors", ->
+ vm1 = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
+ vm2 = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
- "caches constructors": (test) ->
- vm1 = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
- vm2 = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
+ equal vm1.constructor, vm2.constructor
- test.equal vm1.constructor, vm2.constructor
+
+test "configures constructor", ->
+ vm = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
+ bindables = vm.constructor.bindables
- test.done()
+ equal bindables.field, AS.Binding.Field
+ equal bindables.many, AS.Binding.Many
+ equal bindables.one, AS.Binding.One
- "configures constructor": (test) ->
- vm = AS.ViewModel.build NS.AView.new(), NS.Viewed.new()
- bindables = vm.constructor.bindables
-
- test.equal bindables.field, AS.Binding.Field
- test.equal bindables.many, AS.Binding.Many
- test.equal bindables.one, AS.Binding.One
-
- test.done()
+
View
8 test/client/views/panel.coffee
@@ -1,6 +1,6 @@
{AS, $, _, sinon} = require require("path").resolve("./test/client_helper")
-exports["Views Panel"] =
- "Panel extends View": (test) ->
- test.ok new AS.Views.Panel instanceof AS.View
+module "Views Panel"
+test "Panel extends View", ->
+ ok new AS.Views.Panel instanceof AS.View
- test.done()
+
View
18 test/client/views/region.coffee
@@ -1,10 +1,10 @@
{AS, $, _, sinon} = require require("path").resolve("./test/client_helper")
-exports["Views Regions"] =
- "regions for cardinal directions/center extend Region": (test) ->
- test.ok AS.Views.Region.new() instanceof AS.View
- test.ok AS.Views.North.new() instanceof AS.Views.Region
- test.ok AS.Views.East.new() instanceof AS.Views.Region
- test.ok AS.Views.South.new() instanceof AS.Views.Region
- test.ok AS.Views.West.new() instanceof AS.Views.Region
- test.ok AS.Views.Center.new() instanceof AS.Views.Region
- test.done()
+module "Views Regions"
+test "regions for cardinal directions/center extend Region", ->
+ ok AS.Views.Region.new() instanceof AS.View
+ ok AS.Views.North.new() instanceof AS.Views.Region
+ ok AS.Views.East.new() instanceof AS.Views.Region
+ ok AS.Views.South.new() instanceof AS.Views.Region
+ ok AS.Views.West.new() instanceof AS.Views.Region
+ ok AS.Views.Center.new() instanceof AS.Views.Region
+
View
170 test/core/filtered_collection.coffee
@@ -9,90 +9,90 @@ C.Model = AS.Model.extend ({delegate, include, def, defs}) ->
C.Collection = AS.Collection.extend ({delegate, include, def, defs}) ->
module "FilteredCollection"
- "by default, all members are in the filtered collection", ->
- c = C.Collection.new()
- f = c.filter()
-
- one = c.add C.Model.new()
- two = c.add C.Model.new()
- three = c.add C.Model.new()
-
- deepEqual [one, two, three], f.models.value()
-
- "removes items from filter when they are removed from collection", ->
- c = C.Collection.new()
- f = c.filter()
-
- one = c.add C.Model.new()
- two = c.add C.Model.new()
- three = c.add C.Model.new()
-
- c.remove(two)
-
- deepEqual [one, three], f.models.value()
-
- "respects filter function when adding models", ->
- c = C.Collection.new()
- f = c.filter truth: false
-
- one = c.add C.Model.new()
-