From 2151b4f791b4f0c9166ecb32b4a697b4b7f1316a Mon Sep 17 00:00:00 2001 From: Flaburgan Date: Tue, 26 Aug 2014 14:22:25 +0200 Subject: [PATCH] Add jasmine tests --- .../views/publisher/aspect_selector_view.js | 2 +- .../app/views/publisher_view_spec.js | 44 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/views/publisher/aspect_selector_view.js b/app/assets/javascripts/app/views/publisher/aspect_selector_view.js index 567ea8642..ce14a612f 100644 --- a/app/assets/javascripts/app/views/publisher/aspect_selector_view.js +++ b/app/assets/javascripts/app/views/publisher/aspect_selector_view.js @@ -32,7 +32,7 @@ app.views.PublisherAspectSelector = app.views.AspectsDropdown.extend({ this._updateButton('btn-default'); // update the globe or lock icon - var icon = $('#visibility-icon'); + var icon = this.$('#visibility-icon'); if (target.find('.text').text().trim() == Diaspora.I18n.t('stream.public')) { icon.removeClass('lock'); icon.addClass('globe'); diff --git a/spec/javascripts/app/views/publisher_view_spec.js b/spec/javascripts/app/views/publisher_view_spec.js index 37e27fc45..2a86fce7c 100644 --- a/spec/javascripts/app/views/publisher_view_spec.js +++ b/spec/javascripts/app/views/publisher_view_spec.js @@ -6,7 +6,7 @@ describe("app.views.Publisher", function() { describe("standalone", function() { beforeEach(function() { - // should be jasmine helper + // TODO should be jasmine helper loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); spec.loadFixture("aspects_index"); @@ -26,7 +26,7 @@ describe("app.views.Publisher", function() { context("plain publisher", function() { beforeEach(function() { - // should be jasmine helper + // TODO should be jasmine helper loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); spec.loadFixture("aspects_index"); @@ -245,9 +245,11 @@ describe("app.views.Publisher", function() { context("aspect selection", function(){ beforeEach( function(){ spec.loadFixture('status_message_new'); + Diaspora.I18n.load({ stream: { public: 'Public' }}); this.radio_els = $('#publisher .dropdown li.radio'); this.check_els = $('#publisher .dropdown li.aspect_selector'); + this.visibility_icon = $('#visibility-icon'); this.view = new app.views.Publisher(); this.view.open(); @@ -260,17 +262,50 @@ describe("app.views.Publisher", function() { _.each(this.check_els, function(el){ expect($(el).hasClass('selected')).toBeFalsy(); }); + expect(this.visibility_icon.hasClass('globe')).toBeFalsy(); + expect(this.visibility_icon.hasClass('lock')).toBeTruthy(); }); it("toggles the selected entry visually", function(){ + // click on the last aspect this.check_els.last().trigger('click'); - + // public and "all aspects" are deselected _.each(this.radio_els, function(el){ expect($(el).hasClass('selected')).toBeFalsy(); }); - + // the first aspect is not selected expect(this.check_els.first().hasClass('selected')).toBeFalsy(); + // the last aspect is selected expect(this.check_els.last().hasClass('selected')).toBeTruthy(); + // visibility icon is set to the lock icon + expect(this.visibility_icon.hasClass('globe')).toBeFalsy(); + expect(this.visibility_icon.hasClass('lock')).toBeTruthy(); + + // click on public + this.radio_els.first().trigger('click'); + // public is selected, "all aspects" is deselected + expect(this.radio_els.first().hasClass('selected')).toBeTruthy(); + expect(this.radio_els.last().hasClass('selected')).toBeFalsy(); + // the aspects are deselected + _.each(this.check_els, function(el){ + expect($(el).hasClass('selected')).toBeFalsy(); + }); + // visibility icon is set to the globe icon + expect(this.visibility_icon.hasClass('globe')).toBeTruthy(); + expect(this.visibility_icon.hasClass('lock')).toBeFalsy(); + + // click on "all aspects" + this.radio_els.last().trigger('click'); + // public is deselected, "all aspects" is selected + expect(this.radio_els.first().hasClass('selected')).toBeFalsy(); + expect(this.radio_els.last().hasClass('selected')).toBeTruthy(); + // the aspects are deselected + _.each(this.check_els, function(el){ + expect($(el).hasClass('selected')).toBeFalsy(); + }); + // visibility icon is set to the lock icon + expect(this.visibility_icon.hasClass('globe')).toBeFalsy(); + expect(this.visibility_icon.hasClass('lock')).toBeTruthy(); }); describe("hidden form elements", function(){ @@ -312,7 +347,6 @@ describe("app.views.Publisher", function() { expect(this.view.$('input[name="aspect_ids[]"][value="99"]').length).toBe(1); }); }); - }); context("locator", function() {