Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
Merge branch 'feature/tests' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
steffansluis committed Jun 10, 2013
2 parents 7248adb + 801e4c1 commit a13f70b
Show file tree
Hide file tree
Showing 13 changed files with 973 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/views/modal._.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class View.HTMLModal extends Helper.Mixable
# Toggles the modal
#
toggle: () ->
@elem.modal 'toggle'
@_elem.modal 'toggle'
return this

# Binds function on close (before transition)
Expand Down Expand Up @@ -139,4 +139,4 @@ class View.HTMLModal extends Helper.Mixable
button = $ '<button class="btn" data-dismiss="modal" data-action="close" aria-hidden="true">Close</button>'
footer.append button
return [ footer, button ]


6 changes: 5 additions & 1 deletion app/assets/javascripts/views/modal.load.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class View.LoadModal extends View.HTMLModal
.fail( () -> body.text( 'Error.' ) )
return this

# Lists the cells from the origin in the tbody
#
# @param tbody [JQuery] The tbody
# @param cells [Array] The list of cells
# @param origin [String] The origin of the cells, either or some other origin
#
_listCells: ( tbody, cells, origin ) ->

Expand Down Expand Up @@ -143,4 +147,4 @@ class View.LoadModal extends View.HTMLModal
return "#{ Math.floor( diff ) } #{ step[ 1] } ago" if diff < step[0]
diff /= step[ 0 ]
return "#{date.getFullYear()} - #{date.getMonth()} - #{date.getDay()}"


31 changes: 20 additions & 11 deletions app/assets/javascripts/views/undo.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@ class View.Undo extends Helper.Mixable
@_createBindings()

@_rows = {}


# Creates bindings for the view
#
_createBindings: ( ) ->
@_bind("tree.node.added", @, @_onNodeAdd)
@_bind("tree.root.set", @, @_onRootSet )
@_bind("controller.undo.branch.finished", @, @_onBranch )

# Clears this view
#
# @return [self] For chaining
#
clear: ( ) ->
@_contents?.remove?()
@_contents?.remove()
return @

# Removes this view
#
# @return [self] For chaining
#
kill: ( ) ->
@_elem?.remove?()
@_elem?.remove()
return @

# Draws this view
#
Expand Down Expand Up @@ -124,7 +132,7 @@ class View.Undo extends Helper.Mixable
# Shows the buttons
#
_showButtons: ( ) ->
@_footer.addClass('active-buttons')
@_footer?.addClass('active-buttons')

# Hides the buttons
#
Expand All @@ -135,34 +143,37 @@ class View.Undo extends Helper.Mixable
#
# @param tree [Model.Tree] The tree the node was added to
# @param node [Model.Node] The node that was added
# @return [Boolean] True is the tree was our timachine, false otherwise
#
_onNodeAdd: ( tree, node ) ->
if tree is @timemachine
if @_list.scrollTop() == @_list[0].scrollHeight - @_list.height()
doScroll = true

if node.parent?.children.length - 1 > 0
@_drawContents()
else
if node.parent?.children.length <= 1
@_list.append(@_getNodeView(node))
@selectNode(@timemachine.current)
else
@_drawContents()

if doScroll
@_scrollToBottom()

return tree is @timemachine

# Gets called when the root of the tree is set
#
# @param tree [Model.Tree] The tree
# @param node [Model.Node] The new root
# @return [Boolean] True is the tree was our timachine, false otherwise
#
_onRootSet: ( tree, node ) ->
if tree is @timemachine
@_drawContents()
return tree is @timemachine

# Gets called when branching occurs
#
# @param direction [String] The direction of the branching
#
_onBranch: ( ) ->
if @_elem?
@_drawContents()
Expand Down Expand Up @@ -212,7 +223,6 @@ class View.Undo extends Helper.Mixable
# @param node [Model.Node] The node
#
setActive: ( node ) ->
console.log "Active",node.object
view = @_rows[node.id]
if view?
view.addClass("active")
Expand All @@ -223,7 +233,6 @@ class View.Undo extends Helper.Mixable
# @param node [Model.Node] The node
#
setInactive: ( node ) ->
console.log "Inactive",node.object
view = @_rows[node.id]
if view?
view.removeClass("active")
Expand Down
81 changes: 81 additions & 0 deletions spec/javascripts/view_specs/__spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
describe("Base", function() {
var view, paper, raphael, x, y;

beforeEach( function() {
x = 42;
y = 24;
raphael = Raphael(0, 0, 0, 0);
paper = {
set: jasmine.createSpy('set').andReturn(raphael.set()),
circle: jasmine.createSpy('circle').andReturn(raphael.circle(x, y, 0))
};
view = new View.RaphaelBase(paper);
});

afterEach( function() {
view.kill();
});

describe("when constructed", function() {
it("should have set the paper", function() {
expect(view.paper).toBe(paper);
});

it("should be able to get x and y when nothing is set", function() {
expect(view.x).toEqual(0);
expect(view.y).toEqual(0);
});

describe("when drawn", function() {
var contents;

beforeEach( function() {
spyOn(view, 'clear').andCallThrough();
contents = view.draw(x, y);
});

it("should clear first", function() {
expect(view.clear).toHaveBeenCalled();
});

it("should have drawn and return the contents", function() {
expect(contents).toBeDefined();
});

describe("when moved to a new fixed position", function() {
beforeEach( function() {
spyOn(view, 'move').andCallThrough();
view.moveTo(x, y);
});

it("should have been moved", function() {
expect(view.move).toHaveBeenCalled();
expect(view.x).toEqual(x);
expect(view.y).toEqual(y);
});
});

describe("when moved to a new position relative to its parent", function() {
beforeEach( function() {
spyOn(view, 'moveTo').andCallThrough();
view.setPosition();
});

it("should do nothing when parent is null", function() {
expect(view.moveTo).not.toHaveBeenCalled();
});
});

describe("when redrawn", function() {
beforeEach( function() {
spyOn(view, 'draw');
view.redraw();
});

it("should have redrawn and return the contents", function() {
expect(view.draw).toHaveBeenCalled();
});
});
});
});
});
112 changes: 112 additions & 0 deletions spec/javascripts/view_specs/modal___spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
describe("Modal", function() {
describe("when constructed", function() {
beforeEach( function() {
header = "";
contents = {};
id = 1;
classname = "";
view = new View.HTMLModal(header, contents, id, classname)
});

it("should have set all the properties", function() {
expect( view._header ).toBe( header );
expect( view._contents ).toBe( contents );
expect( view.id ).toBe( id );
expect( view._id ).toBe( id );
expect( view._elem ).toBeDefined();
});

describe("when showing", function() {
beforeEach( function() {
spyOn( view._elem, "modal" );
view.show();
});

it("should have set action to undefined", function() {
expect( view._action ).toBe( undefined );
});

it("should have called modal", function() {
expect( view._elem.modal ).toHaveBeenCalledWith( "show" );
})
});

describe("when hiding", function() {
beforeEach( function() {
spyOn( view._elem, "modal" );
view.hide();
});

it("should have called modal", function() {
expect( view._elem.modal ).toHaveBeenCalledWith( "hide" );
})
});

describe("when toggling", function() {
beforeEach( function() {
spyOn( view._elem, "modal" );
view.toggle();
});

it("should have called modal", function() {
expect( view._elem.modal ).toHaveBeenCalledWith( "toggle" );
})
});

describe("when binding to close", function() {
beforeEach( function() {
spyOn( view, "_bind" );
context = {};
action = {};
view.onClose( context, action );
});

it("should have called bind", function() {
expect( view._bind ).toHaveBeenCalledWith( "modal.confirm.close", context, action );
});
});

describe("when unbinding to close", function() {
beforeEach( function() {
spyOn( view, "_unbind" );
context = {};
action = {};
view.offClose( context, action );
});

it("should have called unbind", function() {
expect( view._unbind ).toHaveBeenCalledWith( "modal.confirm.close", context, action );
});
});

describe("when binding to closed", function() {
beforeEach( function() {
spyOn( view, "_bind" );
context = {};
action = {};
view.onClosed( context, action );
});

it("should have called bind", function() {
expect( view._bind ).toHaveBeenCalledWith( "modal.confirm.closed", context, action );
});
});

describe("when unbinding to closed", function() {
beforeEach( function() {
spyOn( view, "_unbind" );
context = {};
action = {};
view.offClosed( context, action );
});

it("should have called unbind", function() {
expect( view._unbind ).toHaveBeenCalledWith( "modal.confirm.closed", context, action );
});
});

afterEach( function() {
view.kill();
});
});
});
23 changes: 23 additions & 0 deletions spec/javascripts/view_specs/modal_confirm_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe("ConfirmModal", function() {
describe("when constructed", function() {
beforeEach( function() {
header = "";
contents = {};
id = 1;
classname = "";
view = new View.ConfirmModal(header, contents, id, classname)
});

it("the modal should have a cancel button", function() {
expect( view._elem.find("[data-action=\"cancel\"]").length ).toBe( 1 );
});

it("the modal should have a confirm button", function() {
expect( view._elem.find("[data-action=\"confirm\"]").length ).toBe( 1 );
});

afterEach( function() {
view.kill();
});
});
});
Loading

0 comments on commit a13f70b

Please sign in to comment.