From 54378b11d440742c5fed09bf21fbfc3cc4418964 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 17 Sep 2014 10:47:30 -0600 Subject: [PATCH] Isolate ViewRegistry specs --- spec/view-registry-spec.coffee | 51 ++++++++++++++++++++++++++++++++++ spec/workspace-spec.coffee | 43 ---------------------------- 2 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 spec/view-registry-spec.coffee 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