BUGFIX: change the image upload icon when only images are authorized (fixes #2359)

This commit is contained in:
Régis Hanol
2014-06-04 19:51:26 +02:00
parent 8e7f0aa268
commit 897f219d61
6 changed files with 46 additions and 24 deletions

View File

@@ -10,15 +10,15 @@ test("emailValid", function() {
var validUpload = utils.validateUploadedFiles;
test("validateUploadedFiles", function() {
ok(!validUpload(null), "no files are invalid");
ok(!validUpload(undefined), "undefined files are invalid");
ok(!validUpload([]), "empty array of files is invalid");
not(validUpload(null), "no files are invalid");
not(validUpload(undefined), "undefined files are invalid");
not(validUpload([]), "empty array of files is invalid");
});
test("uploading one file", function() {
this.stub(bootbox, "alert");
ok(!validUpload([1, 2]));
not(validUpload([1, 2]));
ok(bootbox.alert.calledWith(I18n.t('post.errors.too_many_uploads')));
});
@@ -26,7 +26,7 @@ test("new user cannot upload images", function() {
Discourse.SiteSettings.newuser_max_images = 0;
this.stub(bootbox, "alert");
ok(!validUpload([{name: "image.png"}]), 'the upload is not valid');
not(validUpload([{name: "image.png"}]), 'the upload is not valid');
ok(bootbox.alert.calledWith(I18n.t('post.errors.image_upload_not_allowed_for_new_user')), 'the alert is called');
});
@@ -34,7 +34,7 @@ test("new user cannot upload attachments", function() {
Discourse.SiteSettings.newuser_max_attachments = 0;
this.stub(bootbox, "alert");
ok(!validUpload([{name: "roman.txt"}]));
not(validUpload([{name: "roman.txt"}]));
ok(bootbox.alert.calledWith(I18n.t('post.errors.attachment_upload_not_allowed_for_new_user')));
});
@@ -43,7 +43,7 @@ test("ensures an authorized upload", function() {
var extensions = Discourse.SiteSettings.authorized_extensions.replace(/\|/g, ", ");
this.stub(bootbox, "alert");
ok(!validUpload([html]));
not(validUpload([html]));
ok(bootbox.alert.calledWith(I18n.t('post.errors.upload_not_authorized', { authorized_extensions: extensions })));
});
@@ -53,7 +53,7 @@ test("prevents files that are too big from being uploaded", function() {
Discourse.User.currentProp("trust_level", 1);
this.stub(bootbox, "alert");
ok(!validUpload([image]));
not(validUpload([image]));
ok(bootbox.alert.calledWith(I18n.t('post.errors.image_too_large', { max_size_kb: 5 })));
});
@@ -80,7 +80,7 @@ test("allows valid uploads to go through", function() {
var pastedImage = dummyBlob();
ok(validUpload([pastedImage]));
ok(!bootbox.alert.calledOnce);
not(bootbox.alert.calledOnce);
});
var getUploadMarkdown = function(filename) {
@@ -104,15 +104,15 @@ test("isAnImage", function() {
ok(utils.isAnImage(image), image + " is recognized as an image");
ok(utils.isAnImage("http://foo.bar/path/to/" + image), image + " is recognized as an image");
});
ok(!utils.isAnImage("file.txt"));
ok(!utils.isAnImage("http://foo.bar/path/to/file.txt"));
ok(!utils.isAnImage(""));
not(utils.isAnImage("file.txt"));
not(utils.isAnImage("http://foo.bar/path/to/file.txt"));
not(utils.isAnImage(""));
});
test("avatarUrl", function() {
blank(Discourse.Utilities.avatarUrl('', 'tiny'), "no template returns blank");
equal(Discourse.Utilities.avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + 20*window.devicePixelRatio + ".png", "simple avatar url");
equal(Discourse.Utilities.avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + 45*window.devicePixelRatio + ".png", "different size");
blank(utils.avatarUrl('', 'tiny'), "no template returns blank");
equal(utils.avatarUrl('/fake/template/{size}.png', 'tiny'), "/fake/template/" + 20*window.devicePixelRatio + ".png", "simple avatar url");
equal(utils.avatarUrl('/fake/template/{size}.png', 'large'), "/fake/template/" + 45*window.devicePixelRatio + ".png", "different size");
});
test("avatarImg", function() {
@@ -120,27 +120,38 @@ test("avatarImg", function() {
window.devicePixelRatio = 2;
var avatarTemplate = "/path/to/avatar/{size}.png";
equal(Discourse.Utilities.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}),
equal(utils.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny'}),
"<img width='20' height='20' src='/path/to/avatar/40.png' class='avatar'>",
"it returns the avatar html");
equal(Discourse.Utilities.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}),
equal(utils.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', title: 'evilest trout'}),
"<img width='20' height='20' src='/path/to/avatar/40.png' class='avatar' title='evilest trout'>",
"it adds a title if supplied");
equal(Discourse.Utilities.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}),
equal(utils.avatarImg({avatarTemplate: avatarTemplate, size: 'tiny', extraClasses: 'evil fish'}),
"<img width='20' height='20' src='/path/to/avatar/40.png' class='avatar evil fish'>",
"it adds extra classes if supplied");
blank(Discourse.Utilities.avatarImg({avatarTemplate: "", size: 'tiny'}),
blank(utils.avatarImg({avatarTemplate: "", size: 'tiny'}),
"it doesn't render avatars for invalid avatar template");
window.devicePixelRatio = oldRatio;
});
test("allowsAttachments", function() {
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif";
not(utils.allowsAttachments(), "no attachments allowed by default");
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|*";
ok(utils.allowsAttachments(), "attachments are allowed when all extensions are allowed");
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|pdf";
ok(utils.allowsAttachments(), "attachments are allowed when at least one extension is not an image extension");
});
test("defaultHomepage", function() {
Discourse.SiteSettings.top_menu = "latest|top|hot";
equal(Discourse.Utilities.defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting");
equal(utils.defaultHomepage(), "latest", "default homepage is the first item in the top_menu site setting");
});
module("Discourse.Utilities.cropAvatar with animated avatars", {
@@ -150,7 +161,7 @@ module("Discourse.Utilities.cropAvatar with animated avatars", {
asyncTestDiscourse("cropAvatar", function() {
expect(1);
Discourse.Utilities.cropAvatar("/path/to/avatar.gif", "image/gif").then(function(avatarTemplate) {
utils.cropAvatar("/path/to/avatar.gif", "image/gif").then(function(avatarTemplate) {
equal(avatarTemplate, "/path/to/avatar.gif", "returns the url to the gif when animated gif are enabled");
start();
});