diaspora/spec/javascripts/app/views/aspects_dropdown_view_spec.js
theworldbright 98f11b944a Fix styleguide violations
Fix hound remark 12

Remove unnecessary explicit div tag

Rename el_**** to ****El (hound remark 2 and 3)

Only find and replace operations were done with
this commit

Fix hound remark 4 and 8

Fix hound remark 6

Fix hound remark 7

Fix hound remark 9

Fix hound remark 10 and 11

Fix hound remark 13

Fix hound remark 1

Change single quotes to double quotes

Change single quotes to double in publisher view

Fix camelCase and missing {} in publisher view

Change single quotes to double in bookmarklet view

Use dot notation for serializedForm in publisher

Change single quotes to double in bookmarklet spec

Change single quotes to double in publisher spec

Fix missing {} in publisher views

Use ruby 1.9 hash syntax in invite_link

Fix indentation in publisher view
2015-06-04 18:05:44 +02:00

111 lines
4.8 KiB
JavaScript

describe("app.views.AspectsDropdown", function(){
beforeEach(function() {
spec.loadFixture("bookmarklet");
Diaspora.I18n.reset({
'aspect_dropdown': {
'select_aspects': "Select aspects",
'all_aspects': "All aspects",
'toggle': {
'zero': "Select aspects",
'one': "In <%= count %> aspect",
'other': "In <%= count %> aspects"
}}});
this.view = new app.views.AspectsDropdown({el: $('.aspect_dropdown')});
});
context('_toggleCheckbox', function() {
beforeEach(function() {
this.view.$("li.selected").removeClass("selected");
this.view.$("li.all_aspects").addClass("selected");
});
it('deselects all radio buttons', function() {
this.view._toggleCheckbox(this.view.$('li.aspect_selector:eq(0)'));
expect(this.view.$('li.all_aspects.radio').hasClass('selected')).toBeFalsy();
});
it('selects the clicked aspect', function() {
this.view._toggleCheckbox(this.view.$('li.aspect_selector:eq(0)'));
expect(this.view.$('li.aspect_selector:eq(0)').hasClass('selected')).toBeTruthy();
});
it('selects multiple aspects', function() {
this.view._toggleCheckbox(this.view.$('li.aspect_selector:eq(0)'));
this.view._toggleCheckbox(this.view.$('li.aspect_selector:eq(1)'));
expect(this.view.$('li.aspect_selector:eq(0)').hasClass('selected')).toBeTruthy();
expect(this.view.$('li.aspect_selector:eq(1)').hasClass('selected')).toBeTruthy();
});
});
context('_toggleRadio', function(){
beforeEach(function() {
this.view.$('li.selected').removeClass('selected');
this.view.$('li.aspect_selector:eq(0)').addClass('selected');
this.view.$('li.aspect_selector:eq(1)').addClass('selected');
});
it('deselects all checkboxes', function() {
this.view._toggleRadio(this.view.$("li.all_aspects"));
expect(this.view.$("li.aspect_selector:eq(0)").hasClass("selected")).toBeFalsy();
expect(this.view.$("li.aspect_selector:eq(1)").hasClass("selected")).toBeFalsy();
});
it('toggles the clicked radio buttons', function() {
this.view._toggleRadio(this.view.$("li.all_aspects"));
expect(this.view.$("li.all_aspects").hasClass("selected")).toBeTruthy();
expect(this.view.$("li.public").hasClass("selected")).toBeFalsy();
this.view._toggleRadio(this.view.$("li.public"));
expect(this.view.$("li.all_aspects").hasClass("selected")).toBeFalsy();
expect(this.view.$("li.public").hasClass("selected")).toBeTruthy();
this.view._toggleRadio(this.view.$("li.all_aspects"));
expect(this.view.$("li.all_aspects").hasClass("selected")).toBeTruthy();
expect(this.view.$("li.public").hasClass("selected")).toBeFalsy();
});
});
context('_selectAspects', function(){
beforeEach(function() {
this.view.$('li.selected').removeClass('selected');
this.view.$('li.aspect_selector:eq(0)').addClass('selected');
});
it('select aspects in the dropdown by a given list of ids', function() {
this.ids = [this.view.$('li.aspect_selector:eq(1)').data('aspect_id'),'public'];
this.view._selectAspects(this.ids);
expect(this.view.$('li.all_aspects').hasClass('selected')).toBeFalsy();
expect(this.view.$('li.public').hasClass('selected')).toBeTruthy();
expect(this.view.$('li.aspect_selector:eq(0)').hasClass('selected')).toBeFalsy();
expect(this.view.$('li.aspect_selector:eq(1)').hasClass('selected')).toBeTruthy();
});
});
context('_updateButton', function() {
beforeEach(function() {
this.view.$('li.selected').removeClass('selected');
});
it('shows "Select aspects" when nothing is selected', function() {
this.view._updateButton('inAspectClass');
expect(this.view.$('.btn.dropdown-toggle > .text').text()).toContain(Diaspora.I18n.t('aspect_dropdown.select_aspects'));
});
it('shows the name of the selected radio button', function() {
this.view.$("li.all_aspects").addClass("selected");
this.view._updateButton("inAspectClass");
expect(this.view.$(".btn.dropdown-toggle > .text").text()).toContain(Diaspora.I18n.t("aspect_dropdown.all_aspects"));
});
it('shows the name of the selected aspect ( == 1 )', function() {
this.view.$('li.aspect_selector:eq(1)').addClass('selected');
this.view._updateButton('inAspectClass');
expect(this.view.$('.btn.dropdown-toggle > .text').text()).toContain(this.view.$('li.aspect_selector:eq(1) .text').text());
});
it('shows the number of selected aspects ( > 1)', function() {
this.view.$('li.aspect_selector:eq(0)').addClass('selected');
this.view.$('li.aspect_selector:eq(1)').addClass('selected');
this.view._updateButton('inAspectClass');
expect(this.view.$('.btn.dropdown-toggle > .text').text()).toContain(Diaspora.I18n.t('aspect_dropdown.toggle', { 'count':2 }));
});
});
});