2013-04-04 19:06:52 -04:00
|
|
|
/*global waitsFor:true expect:true describe:true beforeEach:true it:true spyOn:true */
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-02-27 21:26:20 -05:00
|
|
|
describe("Discourse.Utilities", function() {
|
|
|
|
|
|
|
|
describe("categoryUrlId", function() {
|
|
|
|
|
|
|
|
it("returns the slug when it exists", function() {
|
|
|
|
expect(Discourse.Utilities.categoryUrlId({ slug: 'hello' })).toBe("hello");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns id-category when slug is an empty string", function() {
|
|
|
|
expect(Discourse.Utilities.categoryUrlId({ id: 123, slug: '' })).toBe("123-category");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns id-category without a slug", function() {
|
|
|
|
expect(Discourse.Utilities.categoryUrlId({ id: 456 })).toBe("456-category");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("emailValid", function() {
|
|
|
|
|
|
|
|
it("allows upper case in first part of emails", function() {
|
|
|
|
expect(Discourse.Utilities.emailValid('Bob@example.com')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows upper case in domain of emails", function() {
|
|
|
|
expect(Discourse.Utilities.emailValid('bob@EXAMPLE.com')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2013-04-04 19:06:52 -04:00
|
|
|
describe("validateFilesForUpload", function() {
|
|
|
|
|
|
|
|
it("returns false when file is undefined", function() {
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload(null)).toBe(false);
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload(undefined)).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns false when file there is no file", function() {
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload([])).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("supports only one file", function() {
|
|
|
|
spyOn(bootbox, 'alert');
|
|
|
|
spyOn(Em.String, 'i18n');
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload([1, 2])).toBe(false);
|
|
|
|
expect(bootbox.alert).toHaveBeenCalled();
|
|
|
|
expect(Em.String.i18n).toHaveBeenCalledWith('post.errors.upload_too_many_images');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("supports only an image", function() {
|
|
|
|
var html = { type: "text/html" };
|
|
|
|
spyOn(bootbox, 'alert');
|
|
|
|
spyOn(Em.String, 'i18n');
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload([html])).toBe(false);
|
|
|
|
expect(bootbox.alert).toHaveBeenCalled();
|
|
|
|
expect(Em.String.i18n).toHaveBeenCalledWith('post.errors.only_images_are_supported');
|
|
|
|
});
|
|
|
|
|
|
|
|
it("prevents the upload of a too large image", function() {
|
|
|
|
var image = { type: "image/png", size: 10 * 1024 };
|
|
|
|
Discourse.SiteSettings.max_upload_size_kb = 5;
|
|
|
|
spyOn(bootbox, 'alert');
|
|
|
|
spyOn(Em.String, 'i18n');
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload([image])).toBe(false);
|
|
|
|
expect(bootbox.alert).toHaveBeenCalled();
|
|
|
|
expect(Em.String.i18n).toHaveBeenCalledWith('post.errors.upload_too_large', { max_size_kb: 5 });
|
|
|
|
});
|
|
|
|
|
|
|
|
it("works", function() {
|
|
|
|
var image = { type: "image/png", size: 10 * 1024 };
|
|
|
|
Discourse.SiteSettings.max_upload_size_kb = 15;
|
|
|
|
expect(Discourse.Utilities.validateFilesForUpload([image])).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|