adapt rebased changes to jasmine 2
This commit is contained in:
parent
037671f1b6
commit
b07f6cf1db
3 changed files with 53 additions and 42 deletions
|
|
@ -23,6 +23,8 @@ describe PeopleController do
|
||||||
|
|
||||||
describe '#aspect_membership_dropdown' do
|
describe '#aspect_membership_dropdown' do
|
||||||
before do
|
before do
|
||||||
|
aspect = bob.aspects.create name: 'Testing'
|
||||||
|
bob.share_with alice.person, aspect
|
||||||
sign_in :user, bob
|
sign_in :user, bob
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,21 @@
|
||||||
describe("app.views.AspectMembershipBlueprint", function(){
|
describe("app.views.AspectMembershipBlueprint", function(){
|
||||||
|
var resp_success = {status: 200, responseText: '{}'};
|
||||||
|
var resp_fail = {status: 400};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
spec.loadFixture("aspect_membership_dropdown_blueprint");
|
spec.loadFixture("aspect_membership_dropdown_blueprint");
|
||||||
this.view = new app.views.AspectMembershipBlueprint();
|
this.view = new app.views.AspectMembershipBlueprint();
|
||||||
this.person_id = $('.dropdown_list').data('person_id');
|
this.person_id = $('.dropdown_list').data('person_id');
|
||||||
|
this.person_name = $('.dropdown_list').data('person-short-name');
|
||||||
|
|
||||||
|
Diaspora.I18n.load({
|
||||||
|
aspect_dropdown: {
|
||||||
|
started_sharing_with: 'you started sharing with <%= name %>',
|
||||||
|
stopped_sharing_with: 'you stopped sharing with <%= name %>',
|
||||||
|
error: 'unable to add <%= name %>',
|
||||||
|
error_remove: 'unable to remove <%= name %>'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('attaches to the aspect selector', function(){
|
|
||||||
spyOn($.fn, 'on');
|
|
||||||
view = new app.views.AspectMembership();
|
|
||||||
|
|
||||||
expect($.fn.on).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
context('adding to aspects', function() {
|
context('adding to aspects', function() {
|
||||||
|
|
@ -18,61 +24,63 @@ describe("app.views.AspectMembershipBlueprint", function(){
|
||||||
this.newAspectId = this.newAspect.data('aspect_id');
|
this.newAspectId = this.newAspect.data('aspect_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls "addMembership"', function() {
|
it('marks the aspect as selected', function() {
|
||||||
spyOn(this.view, "addMembership");
|
|
||||||
this.newAspect.trigger('click');
|
this.newAspect.trigger('click');
|
||||||
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect(this.view.addMembership).toHaveBeenCalledWith(this.person_id, this.newAspectId);
|
expect(this.newAspect.attr('class')).toContain('selected');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tries to create a new AspectMembership', function() {
|
it('displays flash message when added to first aspect', function() {
|
||||||
spyOn(app.models.AspectMembership.prototype, "save");
|
spec.content().find('li').removeClass('selected');
|
||||||
this.view.addMembership(1, 2);
|
this.newAspect.trigger('click');
|
||||||
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect(app.models.AspectMembership.prototype.save).toHaveBeenCalled();
|
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
||||||
|
Diaspora.I18n.t('aspect_dropdown.started_sharing_with', {name: this.person_name})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an error when it fails', function() {
|
it('displays an error when it fails', function() {
|
||||||
spyOn(this.view, "_displayError");
|
this.newAspect.trigger('click');
|
||||||
spyOn(app.models.AspectMembership.prototype, "save").andCallFake(function() {
|
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
||||||
this.trigger('error');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.view.addMembership(1, 2);
|
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
||||||
|
Diaspora.I18n.t('aspect_dropdown.error', {name: this.person_name})
|
||||||
expect(this.view._displayError).toHaveBeenCalledWith('aspect_dropdown.error');
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('removing from aspects', function(){
|
context('removing from aspects', function(){
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.oldAspect = $('li.selected');
|
this.oldAspect = $('li.selected').first();
|
||||||
this.oldMembershipId = this.oldAspect.data('membership_id');
|
this.oldMembershipId = this.oldAspect.data('membership_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls "removeMembership"', function(){
|
it('marks the aspect as unselected', function(){
|
||||||
spyOn(this.view, "removeMembership");
|
|
||||||
this.oldAspect.trigger('click');
|
this.oldAspect.trigger('click');
|
||||||
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect(this.view.removeMembership).toHaveBeenCalledWith(this.oldMembershipId);
|
expect(this.oldAspect.attr('class')).not.toContain('selected');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tries to destroy an AspectMembership', function() {
|
it('displays a flash message when removed from last aspect', function() {
|
||||||
spyOn(app.models.AspectMembership.prototype, "destroy");
|
spec.content().find('li.selected:last').removeClass('selected');
|
||||||
this.view.removeMembership(1);
|
this.oldAspect.trigger('click');
|
||||||
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect(app.models.AspectMembership.prototype.destroy).toHaveBeenCalled();
|
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
||||||
|
Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', {name: this.person_name})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('displays an error when it fails', function() {
|
it('displays an error when it fails', function() {
|
||||||
spyOn(this.view, "_displayError");
|
this.oldAspect.trigger('click');
|
||||||
spyOn(app.models.AspectMembership.prototype, "destroy").andCallFake(function() {
|
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
||||||
this.trigger('error');
|
|
||||||
});
|
|
||||||
|
|
||||||
this.view.removeMembership(1);
|
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
||||||
|
Diaspora.I18n.t('aspect_dropdown.error_remove', {name: this.person_name})
|
||||||
expect(this.view._displayError).toHaveBeenCalledWith('aspect_dropdown.error_remove');
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ describe("app.views.AspectMembership", function(){
|
||||||
spec.loadFixture("aspect_membership_dropdown_bootstrap");
|
spec.loadFixture("aspect_membership_dropdown_bootstrap");
|
||||||
this.view = new app.views.AspectMembership({el: $('.aspect_membership_dropdown')});
|
this.view = new app.views.AspectMembership({el: $('.aspect_membership_dropdown')});
|
||||||
this.person_id = $('.dropdown-menu').data('person_id');
|
this.person_id = $('.dropdown-menu').data('person_id');
|
||||||
|
this.person_name = $('.dropdown-menu').data('person-short-name');
|
||||||
Diaspora.I18n.load({
|
Diaspora.I18n.load({
|
||||||
aspect_dropdown: {
|
aspect_dropdown: {
|
||||||
started_sharing_with: 'you started sharing with <%= name %>',
|
started_sharing_with: 'you started sharing with <%= name %>',
|
||||||
|
|
@ -36,7 +37,7 @@ describe("app.views.AspectMembership", function(){
|
||||||
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
||||||
Diaspora.I18n.t('aspect_dropdown.started_sharing_with', {name: this.person.name})
|
Diaspora.I18n.t('aspect_dropdown.started_sharing_with', {name: this.person_name})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -45,14 +46,14 @@ describe("app.views.AspectMembership", function(){
|
||||||
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
||||||
|
|
||||||
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
||||||
Diaspora.I18n.t('aspect_dropdown.error', {name: this.person.name})
|
Diaspora.I18n.t('aspect_dropdown.error', {name: this.person_name})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('removing from aspects', function(){
|
context('removing from aspects', function(){
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.oldAspect = $('li.selected');
|
this.oldAspect = $('li.selected').first();
|
||||||
this.oldMembershipId = this.oldAspect.data('membership_id');
|
this.oldMembershipId = this.oldAspect.data('membership_id');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -69,7 +70,7 @@ describe("app.views.AspectMembership", function(){
|
||||||
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
jasmine.Ajax.requests.mostRecent().response(resp_success);
|
||||||
|
|
||||||
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
expect($('[id^="flash"]')).toBeSuccessFlashMessage(
|
||||||
Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', {name: this.person.name})
|
Diaspora.I18n.t('aspect_dropdown.stopped_sharing_with', {name: this.person_name})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -78,12 +79,12 @@ describe("app.views.AspectMembership", function(){
|
||||||
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
jasmine.Ajax.requests.mostRecent().response(resp_fail);
|
||||||
|
|
||||||
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
expect($('[id^="flash"]')).toBeErrorFlashMessage(
|
||||||
Diaspora.I18n.t('aspect_dropdown.error_remove', {name: this.person.name})
|
Diaspora.I18n.t('aspect_dropdown.error_remove', {name: this.person_name})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('updateSummary', function() {
|
context('button summary text', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.Aspect = $('li:eq(0)');
|
this.Aspect = $('li:eq(0)');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue