2016-02-12 13:31:26 -05:00
|
|
|
/* global Int8Array:true */
|
2016-06-14 14:31:51 -04:00
|
|
|
import {
|
|
|
|
emailValid,
|
2016-06-15 13:49:57 -04:00
|
|
|
extractDomainFromUrl,
|
2016-06-14 14:31:51 -04:00
|
|
|
isAnImage,
|
|
|
|
avatarUrl,
|
2016-10-20 13:53:41 -04:00
|
|
|
authorizedExtensions,
|
|
|
|
allowsImages,
|
2016-06-14 14:31:51 -04:00
|
|
|
allowsAttachments,
|
|
|
|
getRawSize,
|
|
|
|
avatarImg,
|
|
|
|
defaultHomepage,
|
2017-11-09 14:45:19 -05:00
|
|
|
setDefaultHomepage,
|
2016-06-14 14:31:51 -04:00
|
|
|
validateUploadedFiles,
|
|
|
|
getUploadMarkdown,
|
|
|
|
caretRowCol,
|
2018-01-12 21:43:49 -05:00
|
|
|
setCaretPosition,
|
|
|
|
fillMissingDates
|
2018-06-15 11:03:24 -04:00
|
|
|
} from "discourse/lib/utilities";
|
|
|
|
import * as Utilities from "discourse/lib/utilities";
|
2016-06-14 14:31:51 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("lib:utilities");
|
2013-06-19 15:06:23 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("emailValid", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
emailValid("Bob@example.com"),
|
|
|
|
"allows upper case in the first part of emails"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
emailValid("bob@EXAMPLE.com"),
|
|
|
|
"allows upper case in the email domain"
|
|
|
|
);
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("extractDomainFromUrl", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
extractDomainFromUrl("http://meta.discourse.org:443/random"),
|
|
|
|
"meta.discourse.org",
|
|
|
|
"extract domain name from url"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
extractDomainFromUrl("meta.discourse.org:443/random"),
|
|
|
|
"meta.discourse.org",
|
|
|
|
"extract domain regardless of scheme presence"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
extractDomainFromUrl("http://192.168.0.1:443/random"),
|
|
|
|
"192.168.0.1",
|
|
|
|
"works for IP address"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
extractDomainFromUrl("http://localhost:443/random"),
|
|
|
|
"localhost",
|
|
|
|
"works for localhost"
|
|
|
|
);
|
2016-06-15 13:49:57 -04:00
|
|
|
});
|
|
|
|
|
2016-06-14 14:31:51 -04:00
|
|
|
var validUpload = validateUploadedFiles;
|
2013-06-19 15:06:23 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("validateUploadedFiles", assert => {
|
|
|
|
assert.not(validUpload(null), "no files are invalid");
|
|
|
|
assert.not(validUpload(undefined), "undefined files are invalid");
|
|
|
|
assert.not(validUpload([]), "empty array of files is invalid");
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("uploading one file", assert => {
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(bootbox, "alert");
|
2013-06-19 15:06:23 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(validUpload([1, 2]));
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(bootbox.alert.calledWith(I18n.t("post.errors.too_many_uploads")));
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("new user cannot upload images", assert => {
|
2013-07-04 18:43:54 -04:00
|
|
|
Discourse.SiteSettings.newuser_max_images = 0;
|
2014-07-31 13:24:07 -04:00
|
|
|
Discourse.User.resetCurrent(Discourse.User.create());
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(bootbox, "alert");
|
2013-07-04 18:43:54 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(validUpload([{ name: "image.png" }]), "the upload is not valid");
|
|
|
|
assert.ok(
|
|
|
|
bootbox.alert.calledWith(
|
|
|
|
I18n.t("post.errors.image_upload_not_allowed_for_new_user")
|
|
|
|
),
|
|
|
|
"the alert is called"
|
|
|
|
);
|
2013-07-21 20:39:17 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("new user cannot upload attachments", assert => {
|
2013-07-21 20:39:17 -04:00
|
|
|
Discourse.SiteSettings.newuser_max_attachments = 0;
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(bootbox, "alert");
|
2014-07-31 13:24:07 -04:00
|
|
|
Discourse.User.resetCurrent(Discourse.User.create());
|
2013-07-21 20:39:17 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(validUpload([{ name: "roman.txt" }]));
|
|
|
|
assert.ok(
|
|
|
|
bootbox.alert.calledWith(
|
|
|
|
I18n.t("post.errors.attachment_upload_not_allowed_for_new_user")
|
|
|
|
)
|
|
|
|
);
|
2013-07-04 18:43:54 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("ensures an authorized upload", assert => {
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(bootbox, "alert");
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(validUpload([{ name: "unauthorized.html" }]));
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
bootbox.alert.calledWith(
|
|
|
|
I18n.t("post.errors.upload_not_authorized", {
|
|
|
|
authorized_extensions: authorizedExtensions()
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
|
|
|
|
2018-10-14 21:43:31 -04:00
|
|
|
QUnit.test("skipping validation works", assert => {
|
|
|
|
const files = [{ name: "backup.tar.gz" }];
|
|
|
|
sandbox.stub(bootbox, "alert");
|
|
|
|
|
|
|
|
assert.not(validUpload(files, { skipValidation: false }));
|
|
|
|
assert.ok(validUpload(files, { skipValidation: true }));
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("staff can upload anything in PM", assert => {
|
2017-06-12 16:41:29 -04:00
|
|
|
const files = [{ name: "some.docx" }];
|
|
|
|
Discourse.SiteSettings.authorized_extensions = "jpeg";
|
|
|
|
Discourse.User.resetCurrent(Discourse.User.create({ moderator: true }));
|
|
|
|
|
|
|
|
sandbox.stub(bootbox, "alert");
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(validUpload(files));
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
validUpload(files, {
|
|
|
|
isPrivateMessage: true,
|
|
|
|
allowStaffToUploadAnyFileInPm: true
|
|
|
|
})
|
|
|
|
);
|
2017-06-12 16:41:29 -04:00
|
|
|
});
|
|
|
|
|
2015-01-23 13:17:33 -05:00
|
|
|
var imageSize = 10 * 1024;
|
|
|
|
|
2013-07-03 18:39:23 -04:00
|
|
|
var dummyBlob = function() {
|
2018-06-15 11:03:24 -04:00
|
|
|
var BlobBuilder =
|
|
|
|
window.BlobBuilder ||
|
|
|
|
window.WebKitBlobBuilder ||
|
|
|
|
window.MozBlobBuilder ||
|
|
|
|
window.MSBlobBuilder;
|
2013-07-10 16:59:16 -04:00
|
|
|
if (BlobBuilder) {
|
|
|
|
var bb = new BlobBuilder();
|
2015-01-23 13:17:33 -05:00
|
|
|
bb.append([new Int8Array(imageSize)]);
|
2013-07-03 18:39:23 -04:00
|
|
|
return bb.getBlob("image/png");
|
|
|
|
} else {
|
2018-06-15 11:03:24 -04:00
|
|
|
return new Blob([new Int8Array(imageSize)], { type: "image/png" });
|
2013-07-03 18:39:23 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("allows valid uploads to go through", assert => {
|
2014-07-31 13:24:07 -04:00
|
|
|
Discourse.User.resetCurrent(Discourse.User.create());
|
2013-09-07 04:49:11 -04:00
|
|
|
Discourse.User.currentProp("trust_level", 1);
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(bootbox, "alert");
|
2013-06-19 15:06:23 -04:00
|
|
|
|
2013-07-03 18:39:23 -04:00
|
|
|
// image
|
2015-01-23 13:17:33 -05:00
|
|
|
var image = { name: "image.png", size: imageSize };
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(validUpload([image]));
|
2013-07-03 18:39:23 -04:00
|
|
|
// pasted image
|
|
|
|
var pastedImage = dummyBlob();
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(validUpload([pastedImage]));
|
2013-07-03 18:39:23 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(bootbox.alert.calledOnce);
|
2013-06-19 15:06:23 -04:00
|
|
|
});
|
2013-06-30 20:19:03 -04:00
|
|
|
|
2019-05-28 21:00:25 -04:00
|
|
|
var testUploadMarkdown = function(filename, opts = {}) {
|
|
|
|
return getUploadMarkdown(
|
|
|
|
Object.assign(
|
|
|
|
{
|
|
|
|
original_filename: filename,
|
|
|
|
filesize: 42,
|
|
|
|
thumbnail_width: 100,
|
|
|
|
thumbnail_height: 200,
|
|
|
|
url: "/uploads/123/abcdef.ext"
|
|
|
|
},
|
|
|
|
opts
|
|
|
|
)
|
|
|
|
);
|
2013-07-10 16:59:16 -04:00
|
|
|
};
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("getUploadMarkdown", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
testUploadMarkdown("lolcat.gif"),
|
|
|
|
"![lolcat|100x200](/uploads/123/abcdef.ext)"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
testUploadMarkdown("[foo|bar].png"),
|
|
|
|
"![%5Bfoo%7Cbar%5D|100x200](/uploads/123/abcdef.ext)"
|
|
|
|
);
|
2019-05-28 21:00:25 -04:00
|
|
|
|
|
|
|
const short_url = "uploads://asdaasd.ext";
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
testUploadMarkdown("important.txt", { short_url }),
|
2019-06-11 03:21:06 -04:00
|
|
|
`[important.txt|attachment](${short_url}) (42 Bytes)`
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2013-07-10 16:59:16 -04:00
|
|
|
});
|
|
|
|
|
2017-11-28 05:05:34 -05:00
|
|
|
QUnit.test("replaces GUID in image alt text on iOS", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
testUploadMarkdown("8F2B469B-6B2C-4213-BC68-57B4876365A0.jpeg"),
|
|
|
|
"![8F2B469B-6B2C-4213-BC68-57B4876365A0|100x200](/uploads/123/abcdef.ext)"
|
|
|
|
);
|
|
|
|
|
|
|
|
sandbox.stub(Utilities, "isAppleDevice").returns(true);
|
|
|
|
assert.equal(
|
|
|
|
testUploadMarkdown("8F2B469B-6B2C-4213-BC68-57B4876365A0.jpeg"),
|
|
|
|
"![image|100x200](/uploads/123/abcdef.ext)"
|
|
|
|
);
|
2017-11-28 05:05:34 -05:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("isAnImage", assert => {
|
2019-02-11 00:28:43 -05:00
|
|
|
["png", "jpg", "jpeg", "gif", "ico"].forEach(extension => {
|
|
|
|
var image = "image." + extension;
|
|
|
|
assert.ok(isAnImage(image), image + " is recognized as an image");
|
|
|
|
assert.ok(
|
|
|
|
isAnImage("http://foo.bar/path/to/" + image),
|
|
|
|
image + " is recognized as an image"
|
|
|
|
);
|
|
|
|
});
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(isAnImage("file.txt"));
|
|
|
|
assert.not(isAnImage("http://foo.bar/path/to/file.txt"));
|
|
|
|
assert.not(isAnImage(""));
|
2013-07-10 16:59:16 -04:00
|
|
|
});
|
2013-07-18 12:03:09 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("avatarUrl", assert => {
|
2016-06-14 14:31:51 -04:00
|
|
|
var rawSize = getRawSize;
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.blank(avatarUrl("", "tiny"), "no template returns blank");
|
|
|
|
assert.equal(
|
|
|
|
avatarUrl("/fake/template/{size}.png", "tiny"),
|
|
|
|
"/fake/template/" + rawSize(20) + ".png",
|
|
|
|
"simple avatar url"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
avatarUrl("/fake/template/{size}.png", "large"),
|
|
|
|
"/fake/template/" + rawSize(45) + ".png",
|
|
|
|
"different size"
|
|
|
|
);
|
2013-07-18 12:03:09 -04:00
|
|
|
});
|
|
|
|
|
2015-03-20 08:53:56 -04:00
|
|
|
var setDevicePixelRatio = function(value) {
|
2018-06-15 11:03:24 -04:00
|
|
|
if (Object.defineProperty && !window.hasOwnProperty("devicePixelRatio")) {
|
2015-08-11 12:27:07 -04:00
|
|
|
Object.defineProperty(window, "devicePixelRatio", { value: 2 });
|
2015-03-20 08:53:56 -04:00
|
|
|
} else {
|
|
|
|
window.devicePixelRatio = value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("avatarImg", assert => {
|
2014-05-27 00:40:46 -04:00
|
|
|
var oldRatio = window.devicePixelRatio;
|
2015-03-20 08:53:56 -04:00
|
|
|
setDevicePixelRatio(2);
|
2014-05-27 00:40:46 -04:00
|
|
|
|
2013-08-13 16:08:29 -04:00
|
|
|
var avatarTemplate = "/path/to/avatar/{size}.png";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
avatarImg({ avatarTemplate: avatarTemplate, size: "tiny" }),
|
|
|
|
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar'>",
|
|
|
|
"it returns the avatar html"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
avatarImg({
|
|
|
|
avatarTemplate: avatarTemplate,
|
|
|
|
size: "tiny",
|
|
|
|
title: "evilest trout"
|
|
|
|
}),
|
|
|
|
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar' title='evilest trout'>",
|
|
|
|
"it adds a title if supplied"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
avatarImg({
|
|
|
|
avatarTemplate: avatarTemplate,
|
|
|
|
size: "tiny",
|
|
|
|
extraClasses: "evil fish"
|
|
|
|
}),
|
|
|
|
"<img alt='' width='20' height='20' src='/path/to/avatar/40.png' class='avatar evil fish'>",
|
|
|
|
"it adds extra classes if supplied"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.blank(
|
|
|
|
avatarImg({ avatarTemplate: "", size: "tiny" }),
|
|
|
|
"it doesn't render avatars for invalid avatar template"
|
|
|
|
);
|
2014-05-27 00:40:46 -04:00
|
|
|
|
2015-03-20 08:53:56 -04:00
|
|
|
setDevicePixelRatio(oldRatio);
|
2013-07-21 20:39:17 -04:00
|
|
|
});
|
2013-08-23 12:48:29 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("allowsImages", assert => {
|
2016-10-20 13:53:41 -04:00
|
|
|
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif";
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(allowsImages(), "works");
|
2016-10-20 13:53:41 -04:00
|
|
|
|
|
|
|
Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif";
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(allowsImages(), "works with old extensions syntax");
|
2016-10-20 13:53:41 -04:00
|
|
|
|
|
|
|
Discourse.SiteSettings.authorized_extensions = "txt|pdf|*";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
allowsImages(),
|
|
|
|
"images are allowed when all extensions are allowed"
|
|
|
|
);
|
2016-10-20 13:53:41 -04:00
|
|
|
|
|
|
|
Discourse.SiteSettings.authorized_extensions = "json|jpg|pdf|txt";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
allowsImages(),
|
|
|
|
"images are allowed when at least one extension is an image extension"
|
|
|
|
);
|
2016-10-20 13:53:41 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("allowsAttachments", assert => {
|
2016-10-20 13:53:41 -04:00
|
|
|
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif";
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.not(allowsAttachments(), "no attachments allowed by default");
|
2014-06-04 13:51:26 -04:00
|
|
|
|
2016-10-20 13:53:41 -04:00
|
|
|
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|*";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
allowsAttachments(),
|
|
|
|
"attachments are allowed when all extensions are allowed"
|
|
|
|
);
|
2014-06-04 13:51:26 -04:00
|
|
|
|
2016-10-20 13:53:41 -04:00
|
|
|
Discourse.SiteSettings.authorized_extensions = "jpg|jpeg|gif|pdf";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
allowsAttachments(),
|
|
|
|
"attachments are allowed when at least one extension is not an image extension"
|
|
|
|
);
|
2016-10-20 13:53:41 -04:00
|
|
|
|
|
|
|
Discourse.SiteSettings.authorized_extensions = ".jpg|.jpeg|.gif|.pdf";
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(allowsAttachments(), "works with old extensions syntax");
|
2014-06-04 13:51:26 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("defaultHomepage", assert => {
|
2013-12-30 12:46:18 -05:00
|
|
|
Discourse.SiteSettings.top_menu = "latest|top|hot";
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
defaultHomepage(),
|
|
|
|
"latest",
|
|
|
|
"default homepage is the first item in the top_menu site setting"
|
|
|
|
);
|
2017-11-09 14:45:19 -05:00
|
|
|
var meta = document.createElement("meta");
|
|
|
|
meta.name = "discourse_current_homepage";
|
|
|
|
meta.content = "hot";
|
|
|
|
document.body.appendChild(meta);
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
defaultHomepage(),
|
|
|
|
"hot",
|
|
|
|
"default homepage is pulled from <meta name=discourse_current_homepage>"
|
|
|
|
);
|
2017-11-09 14:45:19 -05:00
|
|
|
document.body.removeChild(meta);
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("setDefaultHomepage", assert => {
|
|
|
|
var meta = document.createElement("meta");
|
|
|
|
meta.name = "discourse_current_homepage";
|
|
|
|
meta.content = "hot";
|
|
|
|
document.body.appendChild(meta);
|
|
|
|
setDefaultHomepage("top");
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
meta.content,
|
|
|
|
"top",
|
|
|
|
"default homepage set by setDefaultHomepage"
|
|
|
|
);
|
2017-11-09 14:45:19 -05:00
|
|
|
document.body.removeChild(meta);
|
2013-12-30 12:46:18 -05:00
|
|
|
});
|
2015-12-28 01:28:16 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("caretRowCol", assert => {
|
2018-06-15 11:03:24 -04:00
|
|
|
var textarea = document.createElement("textarea");
|
2015-12-28 01:28:16 -05:00
|
|
|
const content = document.createTextNode("01234\n56789\n012345");
|
|
|
|
textarea.appendChild(content);
|
|
|
|
document.body.appendChild(textarea);
|
|
|
|
|
|
|
|
const assertResult = (setCaretPos, expectedRowNum, expectedColNum) => {
|
2016-06-14 14:31:51 -04:00
|
|
|
setCaretPosition(textarea, setCaretPos);
|
2015-12-28 01:28:16 -05:00
|
|
|
|
2016-06-14 14:31:51 -04:00
|
|
|
const result = caretRowCol(textarea);
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
result.rowNum,
|
|
|
|
expectedRowNum,
|
|
|
|
"returns the right row of the caret"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
result.colNum,
|
|
|
|
expectedColNum,
|
|
|
|
"returns the right col of the caret"
|
|
|
|
);
|
2015-12-28 01:28:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
assertResult(0, 1, 0);
|
|
|
|
assertResult(5, 1, 5);
|
|
|
|
assertResult(6, 2, 0);
|
|
|
|
assertResult(11, 2, 5);
|
|
|
|
assertResult(14, 3, 2);
|
|
|
|
|
|
|
|
document.body.removeChild(textarea);
|
2017-07-25 15:11:28 -04:00
|
|
|
});
|
2018-01-12 21:43:49 -05:00
|
|
|
|
|
|
|
QUnit.test("fillMissingDates", assert => {
|
|
|
|
const startDate = "2017-11-12"; // YYYY-MM-DD
|
|
|
|
const endDate = "2017-12-12"; // YYYY-MM-DD
|
2018-06-15 11:03:24 -04:00
|
|
|
const data =
|
|
|
|
'[{"x":"2017-11-12","y":3},{"x":"2017-11-27","y":2},{"x":"2017-12-06","y":9},{"x":"2017-12-11","y":2}]';
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
fillMissingDates(JSON.parse(data), startDate, endDate).length,
|
|
|
|
31,
|
|
|
|
"it returns a JSON array with 31 dates"
|
|
|
|
);
|
2018-01-12 21:43:49 -05:00
|
|
|
});
|