From 0f6d1f9edbe018718247d842361a75c54e57eec7 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 20 Jul 2014 20:45:59 +0200 Subject: [PATCH] Add tests for toggleable headings. updates #83 --- spec/controlbox.js | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/spec/controlbox.js b/spec/controlbox.js index 3df356383..96ebfb8c0 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -7,6 +7,27 @@ } ); } (this, function (mock, utils) { + + var checkHeaderToggling = function ($header) { + var $toggle = $header.find('a.group-toggle'); + expect($header.css('display')).toEqual('block'); + spyOn(this.rosterview, 'toggleGroup').andCallThrough(); + expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy(); + this.rosterview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called + expect($toggle.hasClass('icon-closed')).toBeFalsy(); + expect($toggle.hasClass('icon-opened')).toBeTruthy(); + $toggle.click(); + expect(this.rosterview.toggleGroup).toHaveBeenCalled(); + expect($toggle.hasClass('icon-closed')).toBeTruthy(); + expect($toggle.hasClass('icon-opened')).toBeFalsy(); + expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:hidden').length).toBeTruthy(); + $toggle.click(); + expect(this.rosterview.toggleGroup).toHaveBeenCalled(); + expect($toggle.hasClass('icon-closed')).toBeFalsy(); + expect($toggle.hasClass('icon-opened')).toBeTruthy(); + expect($header.nextUntil('dt', 'dd').length === $header.nextUntil('dt', 'dd:visible').length).toBeTruthy(); + }; + describe("The Control Box", $.proxy(function (mock, utils) { beforeEach(function () { runs(function () { @@ -119,13 +140,13 @@ }); }, converse)); - it("do not have a heading if there aren't any", $.proxy(function () { + it("do not have a header if there aren't any", $.proxy(function () { converse.rosterview.model.reset(); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none'); }, converse)); - it("will have their own heading once they have been added", $.proxy(function () { - expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block'); + it("can be collapsed under their own header", $.proxy(function () { + checkHeaderToggling.apply(this, [this.rosterview.$el.find('dt#pending-xmpp-contacts')]); }, converse)); it("can be added to the roster", $.proxy(function () { @@ -168,7 +189,7 @@ expect(converse.emit).toHaveBeenCalledWith('rosterViewUpdated'); }, converse)); - it("will lose their own heading once the last one has been removed", $.proxy(function () { + it("will lose their own header once the last one has been removed", $.proxy(function () { var view; spyOn(window, 'confirm').andReturn(true); for (i=0; i