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
192 lines
6.9 KiB
JavaScript
192 lines
6.9 KiB
JavaScript
describe("app.views.AspectCreate", function() {
|
|
beforeEach(function() {
|
|
app.events.off("aspect:create");
|
|
// disable jshint camelcase for i18n
|
|
/* jshint camelcase: false */
|
|
Diaspora.I18n.load({
|
|
aspects: {
|
|
make_aspect_list_visible: "Make contacts in this aspect visible to each other?",
|
|
name: "Name",
|
|
create: {
|
|
add_a_new_aspect: "Add a new aspect",
|
|
success: "Your new aspect <%= name %> was created",
|
|
failure: "Aspect creation failed."
|
|
}
|
|
}
|
|
});
|
|
/* jshint camelcase: true */
|
|
});
|
|
|
|
context("without a person id", function() {
|
|
beforeEach(function() {
|
|
this.view = new app.views.AspectCreate();
|
|
});
|
|
|
|
describe("#render", function() {
|
|
beforeEach(function() {
|
|
this.view.render();
|
|
});
|
|
|
|
it("should show the aspect creation form inside a modal", function() {
|
|
expect(this.view.$("#newAspectModal.modal").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal form").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal input#aspect_name").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal input#aspect_contacts_visible").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal .btn-primary").length).toBe(1);
|
|
});
|
|
|
|
it("shouldn't show a hidden person id input", function() {
|
|
expect(this.view.$("#newAspectModal input#aspect_person_id").length).toBe(0);
|
|
});
|
|
});
|
|
|
|
|
|
describe("#createAspect", function() {
|
|
beforeEach(function() {
|
|
this.view.render();
|
|
});
|
|
|
|
it("should send the correct name to the server", function() {
|
|
var name = "New aspect name";
|
|
this.view.$("input#aspect_name").val(name);
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
expect(obj.name).toBe(name);
|
|
});
|
|
|
|
it("should send the correct contacts_visible to the server", function() {
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.contacts_visible).toBeFalsy();
|
|
/* jshint camelcase: true */
|
|
|
|
this.view.$("input#aspect_contacts_visible").prop("checked", true);
|
|
this.view.createAspect();
|
|
obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.contacts_visible).toBeTruthy();
|
|
/* jshint camelcase: true */
|
|
});
|
|
|
|
it("should send person_id = null to the server", function() {
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.person_id).toBe(null);
|
|
/* jshint camelcase: true */
|
|
});
|
|
|
|
context("with a successfull request", function() {
|
|
beforeEach(function() {
|
|
this.response = {
|
|
status: 200,
|
|
responseText: JSON.stringify({id: 1337, name: "new name"})
|
|
};
|
|
});
|
|
|
|
it("should hide the modal", function() {
|
|
this.view.$(".modal").removeClass("fade");
|
|
this.view.$(".modal").modal("toggle");
|
|
expect(this.view.$(".modal")).toHaveClass("in");
|
|
this.view.createAspect();
|
|
jasmine.Ajax.requests.mostRecent().respondWith(this.response);
|
|
expect(this.view.$(".modal")).not.toHaveClass("in");
|
|
});
|
|
|
|
it("should display a flash message", function() {
|
|
this.view.createAspect();
|
|
jasmine.Ajax.requests.mostRecent().respondWith(this.response);
|
|
expect($("[id^=\"flash\"]")).toBeSuccessFlashMessage(
|
|
Diaspora.I18n.t("aspects.create.success", {name: "new name"})
|
|
);
|
|
});
|
|
});
|
|
|
|
context("with a failing request", function() {
|
|
beforeEach(function() {
|
|
this.response = { status: 422 };
|
|
});
|
|
|
|
it("should hide the modal", function() {
|
|
this.view.$(".modal").removeClass("fade");
|
|
this.view.$(".modal").modal("show");
|
|
expect(this.view.$(".modal")).toHaveClass("in");
|
|
this.view.createAspect();
|
|
jasmine.Ajax.requests.mostRecent().respondWith(this.response);
|
|
expect(this.view.$(".modal")).not.toHaveClass("in");
|
|
});
|
|
|
|
it("should display a flash message", function() {
|
|
this.view.createAspect();
|
|
jasmine.Ajax.requests.mostRecent().respondWith(this.response);
|
|
expect($("[id^=\"flash\"]")).toBeErrorFlashMessage(
|
|
Diaspora.I18n.t("aspects.create.failure")
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
context("with a person id", function() {
|
|
beforeEach(function() {
|
|
this.view = new app.views.AspectCreate({personId: "42"});
|
|
});
|
|
|
|
describe("#render", function() {
|
|
beforeEach(function() {
|
|
this.view.render();
|
|
});
|
|
|
|
it("should show the aspect creation form inside a modal", function() {
|
|
expect(this.view.$("#newAspectModal.modal").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal form").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal input#aspect_name").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal input#aspect_contacts_visible").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal .btn-primary").length).toBe(1);
|
|
});
|
|
|
|
it("should show a hidden person id input", function() {
|
|
expect(this.view.$("#newAspectModal input#aspect_person_id").length).toBe(1);
|
|
expect(this.view.$("#newAspectModal input#aspect_person_id").prop("value")).toBe("42");
|
|
});
|
|
});
|
|
|
|
describe("#createAspect", function() {
|
|
beforeEach(function() {
|
|
this.view.render();
|
|
});
|
|
|
|
it("should send the correct name to the server", function() {
|
|
var name = "New aspect name";
|
|
this.view.$("input#aspect_name").val(name);
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
expect(obj.name).toBe(name);
|
|
});
|
|
|
|
it("should send the correct contacts_visible to the server", function() {
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.contacts_visible).toBeFalsy();
|
|
/* jshint camelcase: true */
|
|
|
|
this.view.$("input#aspect_contacts_visible").prop("checked", true);
|
|
this.view.createAspect();
|
|
obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.contacts_visible).toBeTruthy();
|
|
/* jshint camelcase: true */
|
|
});
|
|
|
|
it("should send the correct person_id to the server", function() {
|
|
this.view.createAspect();
|
|
var obj = JSON.parse(jasmine.Ajax.requests.mostRecent().params);
|
|
/* jshint camelcase: false */
|
|
expect(obj.person_id).toBe("42");
|
|
/* jshint camelcase: true */
|
|
});
|
|
});
|
|
});
|
|
});
|