Skip to content
Snippets Groups Projects
Verified Commit 6f776365 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

TST: update tests for new implementation of linkify

parent 94f2132f
Branches
Tags
2 merge requests!59REL: release 0.4.1,!55F linkify edit mode
Pipeline #16866 passed
...@@ -46,13 +46,16 @@ QUnit.test("linkify - https", function (assert) { ...@@ -46,13 +46,16 @@ QUnit.test("linkify - https", function (assert) {
["this is other text https://link", 1], ["this is other text https://link", 1],
["this is other text https://link and here comes another link https://link and more text", 2], ["this is other text https://link and here comes another link https://link and more text", 2],
]; ];
for (let test_case of test_cases) { for (let test_case of test_cases) {
var text_value = $(`<div class="caosdb-f-property-text-value">${test_case[0]}</div>`); const container = $('<div></div>');
$(document.body).append(text_value); $(document.body).append(container);
assert.equal($(text_value).find("a[href='https://link']").length, 0, "no link present"); const text_value = $(`<div class="caosdb-f-property-text-value">${test_case[0]}</div>`);
container.append(text_value);
assert.equal($(container).find("a[href='https://link']").length, 0, "no link present");
cosmetics.linkify(); cosmetics.linkify();
assert.equal($(text_value).find("a[href='https://link']").length, test_case[1], "link is present"); assert.equal($(container).find("a[href='https://link']").length, test_case[1], "link is present");
text_value.remove(); container.remove();
} }
}); });
...@@ -66,22 +69,26 @@ QUnit.test("linkify - http", function (assert) { ...@@ -66,22 +69,26 @@ QUnit.test("linkify - http", function (assert) {
["this is other text http://link and here comes another link http://link and more text", 2], ["this is other text http://link and here comes another link http://link and more text", 2],
]; ];
for (let test_case of test_cases) { for (let test_case of test_cases) {
var text_value = $(`<div class="caosdb-f-property-text-value">${test_case[0]}</div>`); const container = $('<div></div>');
$(document.body).append(text_value); $(document.body).append(container);
assert.equal($(text_value).find("a[href='http://link']").length, 0, "no link present"); const text_value = $(`<div class="caosdb-f-property-text-value">${test_case[0]}</div>`);
$(container).append(text_value);
assert.equal($(container).find("a[href='http://link']").length, 0, "no link present");
cosmetics.linkify(); cosmetics.linkify();
assert.equal($(text_value).find("a[href='http://link']").length, test_case[1], "link is present"); assert.equal($(container).find("a[href='http://link']").length, test_case[1], "link is present");
text_value.remove(); container.remove();
} }
}); });
QUnit.test("linkify cut-off (40)", function (assert) { QUnit.test("linkify cut-off (40)", function (assert) {
var test_case = "here is some text https://this.is.a.link/with/more/than/40/characters/ this is more text"; const container = $('<div></div>');
var text_value = $(`<div class="caosdb-f-property-text-value">${test_case}</div>`); $(document.body).append(container);
$(document.body).append(text_value); const test_case = "here is some text https://this.is.a.link/with/more/than/40/characters/ this is more text";
assert.equal($(text_value).find("a").length, 0, "no link present"); const text_value = $(`<div class="caosdb-f-property-text-value">${test_case}</div>`);
$(container).append(text_value);
assert.equal($(container).find("a").length, 0, "no link present");
cosmetics.linkify(); cosmetics.linkify();
assert.equal($(text_value).find("a").length, 1, "link is present"); assert.equal($(container).find("a").length, 1, "link is present");
assert.equal($(text_value).find("a").text(), "https://this.is.a.link/with/more/th[...] ", "link text has been cut off"); assert.equal($(container).find("a").text(), "https://this.is.a.link/with/more/th[...] ", "link text has been cut off");
text_value.remove(); container.remove();
}); });
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment