diff --git a/spec/view-registry-spec.coffee b/spec/view-registry-spec.coffee new file mode 100644 index 000000000..86801b088 --- /dev/null +++ b/spec/view-registry-spec.coffee @@ -0,0 +1,51 @@ +ViewRegistry = require '../src/view-registry' +{View} = require '../src/space-pen-extensions' + +describe "ViewRegistry", -> + registry = null + + beforeEach -> + registry = new ViewRegistry + + describe "::getView(object)", -> + describe "when passed a DOM node", -> + it "returns the given DOM node", -> + node = document.createElement('div') + expect(registry.getView(node)).toBe node + + describe "when passed a SpacePen view", -> + it "returns the root node of the view with a __spacePenView property pointing at the SpacePen view", -> + class TestView extends View + @content: -> @div "Hello" + + view = new TestView + node = registry.getView(view) + expect(node.textContent).toBe "Hello" + expect(node.__spacePenView).toBe view + + describe "when passed a model object", -> + describe "when no view provider is registered for the object's constructor", -> + describe "when the object has a .getViewClass() method", -> + it "builds an instance of the view class with the model, then returns its root node with a __spacePenView property pointing at the view", -> + class TestView extends View + @content: (model) -> @div model.name + initialize: (@model) -> + + class TestModel + constructor: (@name) -> + getViewClass: -> TestView + + model = new TestModel("hello") + node = registry.getView(model) + + expect(node.textContent).toBe "hello" + view = node.__spacePenView + expect(view instanceof TestView).toBe true + expect(view.model).toBe model + + # returns the same DOM node for repeated calls + expect(registry.getView(model)).toBe node + + describe "when the object has no .getViewClass() method", -> + it "throws an exception", -> + expect(-> registry.getView(new Object)).toThrow() diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index 45452dca3..8e2d426f4 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -8,49 +8,6 @@ describe "Workspace", -> atom.project.setPath(atom.project.resolve('dir')) atom.workspace = workspace = new Workspace - describe "::getView(object)", -> - describe "when passed a DOM node", -> - it "returns the given DOM node", -> - node = document.createElement('div') - expect(workspace.getView(node)).toBe node - - describe "when passed a SpacePen view", -> - it "returns the root node of the view with a __spacePenView property pointing at the SpacePen view", -> - class TestView extends View - @content: -> @div "Hello" - - view = new TestView - node = workspace.getView(view) - expect(node.textContent).toBe "Hello" - expect(node.__spacePenView).toBe view - - describe "when passed a model object", -> - describe "when no view provider is registered for the object's constructor", -> - describe "when the object has a .getViewClass() method", -> - it "builds an instance of the view class with the model, then returns its root node with a __spacePenView property pointing at the view", -> - class TestView extends View - @content: (model) -> @div model.name - initialize: (@model) -> - - class TestModel - constructor: (@name) -> - getViewClass: -> TestView - - model = new TestModel("hello") - node = workspace.getView(model) - - expect(node.textContent).toBe "hello" - view = node.__spacePenView - expect(view instanceof TestView).toBe true - expect(view.model).toBe model - - # returns the same DOM node for repeated calls - expect(workspace.getView(model)).toBe node - - describe "when the object has no .getViewClass() method", -> - it "throws an exception", -> - expect(-> workspace.getView(new Object)).toThrow() - describe "::open(uri, options)", -> openEvents = null