From 1c6564f7a5c460423f987fdd37dbc35544be9fed Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 14 Jan 2014 21:39:47 -0700 Subject: [PATCH] Move non-focus serialization specs from pane-view-spec to pane-spec --- spec/pane-spec.coffee | 40 +++++++++++++++++++++++++++++++++++++- spec/pane-view-spec.coffee | 21 -------------------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 5ea65f32b..71c6606ac 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -5,9 +5,18 @@ PaneContainer = require '../src/pane-container' describe "Pane", -> class Item extends Model - constructor: (@name) -> + @deserialize: ({name, uri}) -> new this(name, uri) + constructor: (@name, @uri) -> getUri: -> @uri getPath: -> @path + serialize: -> {deserializer: 'Item', @name, @uri} + isEqual: (other) -> @name is other?.name + + beforeEach -> + atom.deserializers.add(Item) + + afterEach -> + atom.deserializers.remove(Item) describe "construction", -> it "sets the active item to the first item", -> @@ -397,3 +406,32 @@ describe "Pane", -> expect(container.root.children).toEqual [pane1, pane2] pane2.destroy() expect(container.root).toBe pane1 + + describe "serialization", -> + pane = null + + beforeEach -> + pane = new Pane(items: [new Item("A", "a"), new Item("B", "b"), new Item("C", "c")]) + + it "can serialize and deserialize the pane and all its items", -> + newPane = pane.testSerialization() + expect(newPane.items).toEqual pane.items + + it "restores the active item on deserialization", -> + pane.activateItemAtIndex(1) + newPane = pane.testSerialization() + expect(newPane.activeItem).toEqual newPane.items[1] + + it "does not include items that cannot be deserialized", -> + spyOn(console, 'warn') + unserializable = {} + pane.activateItem(unserializable) + + newPane = pane.testSerialization() + expect(newPane.activeItem).toEqual pane.items[0] + expect(newPane.items.length).toBe pane.items.length - 1 + + it "includes the pane's focus state in the serialized state", -> + pane.focus() + newPane = pane.testSerialization() + expect(newPane.focused).toBe true diff --git a/spec/pane-view-spec.coffee b/spec/pane-view-spec.coffee index 17638264e..fb1815308 100644 --- a/spec/pane-view-spec.coffee +++ b/spec/pane-view-spec.coffee @@ -266,27 +266,6 @@ describe "PaneView", -> expect(container.find('> .pane-column > .pane').toArray()).toEqual [pane2[0], pane3[0]] describe "serialization", -> - it "can serialize and deserialize the pane and all its items", -> - newPane = new PaneView(pane.model.testSerialization()) - expect(newPane.getItems()).toEqual [view1, editor1, view2, editor2] - - it "restores the active item on deserialization", -> - pane.activateItem(editor2) - newPane = new PaneView(pane.model.testSerialization()) - expect(newPane.activeItem).toEqual editor2 - - it "does not show items that cannot be deserialized", -> - spyOn(console, 'warn') - - class Unserializable - getViewClass: -> TestView - - pane.activateItem(new Unserializable) - - newPane = new PaneView(pane.model.testSerialization()) - expect(newPane.activeItem).toEqual pane.items[0] - expect(newPane.items.length).toBe pane.items.length - 1 - it "focuses the pane after attach only if had focus when serialized", -> container.attachToDom() pane.focus()