Skip to content

Commit

Permalink
Format all JS (#1340)
Browse files Browse the repository at this point in the history
The original commit missed subdirectories.
  • Loading branch information
chrismiceli authored Sep 27, 2024
1 parent 4f3c712 commit b1a7f1e
Show file tree
Hide file tree
Showing 31 changed files with 722 additions and 745 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pinc/3rdparty/**/*.js
34 changes: 12 additions & 22 deletions SETUP/tests/jsTests/addprooferTests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global $ QUnit AddProofer */

QUnit.module("addproofer tests", {
beforeEach: function() {
beforeEach: function () {
$(document.body).append(`
<table id='add-proofer-table'>
<tr>
Expand All @@ -21,34 +21,24 @@ QUnit.module("addproofer tests", {
</tr>
</table>`);
},
afterEach: function() {
$('#add-proofer-table').remove();
afterEach: function () {
$("#add-proofer-table").remove();
},
});

QUnit.test("Referrer details hidden if other not selected", function(assert) {
QUnit.test("Referrer details hidden if other not selected", function (assert) {
var addProofer = new AddProofer();
assert.ok(
$('#referrer_details').is(':visible'),
'Referrer details should be visible before form init.');
assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible before form init.");
addProofer.initForm();
assert.notOk(
$('#referrer_details').is(':visible'),
'Referrer details should be hidden after form init.');
assert.notOk($("#referrer_details").is(":visible"), "Referrer details should be hidden after form init.");
});

QUnit.test("Referrer details visible if other selected", function(assert) {
QUnit.test("Referrer details visible if other selected", function (assert) {
var addProofer = new AddProofer();
assert.ok(
$('#referrer_details').is(':visible'),
'Referrer details should be visible before form init.');
assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible before form init.");
addProofer.initForm();
assert.notOk(
$('#referrer_details').is(':visible'),
'Referrer details should be hidden after form init.');
document.querySelector('select[name=referrer]').value = 'other';
document.querySelector('select[name=referrer]').dispatchEvent(new Event('change'));
assert.ok(
$('#referrer_details').is(':visible'),
'Referrer details should be visible after other selection.');
assert.notOk($("#referrer_details").is(":visible"), "Referrer details should be hidden after form init.");
document.querySelector("select[name=referrer]").value = "other";
document.querySelector("select[name=referrer]").dispatchEvent(new Event("change"));
assert.ok($("#referrer_details").is(":visible"), "Referrer details should be visible after other selection.");
});
77 changes: 41 additions & 36 deletions SETUP/tests/jsTests/ajaxTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,90 @@

let codeUrl = "https://www.dummy.org";

QUnit.module("Ajax test", function() {

QUnit.module("Ajax test", function () {
QUnit.test("Return correct data", function (assert) {
function fetchPromise() {
const blob = new Blob([JSON.stringify({key: "value"})], {type : 'application/json'});
const init = {status: 200, headers: {'content-type': 'application/json'}};
const blob = new Blob([JSON.stringify({ key: "value" })], { type: "application/json" });
const init = { status: 200, headers: { "content-type": "application/json" } };
return Promise.resolve(new Response(blob, init));
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function(data) {
assert.deepEqual(data, {key: "value"});
});
return ajax("GET", "myUrl", {}, {}, fetchPromise).then(function (data) {
assert.deepEqual(data, { key: "value" });
});
});

QUnit.test("Wrong type of data", function (assert) {
function fetchPromise() {
const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'});
const init = {status: 200, headers: {'content-type': 'text/html'}};
const blob = new Blob([JSON.stringify("mydata")], { type: "application/json" });
const init = { status: 200, headers: { "content-type": "text/html" } };
return Promise.resolve(new Response(blob, init));
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function() {}, function(data) {
assert.deepEqual(data, {error: "Incorrect response type", code: AJAX_ERROR_CODES.INCORRECT_RESPONSE_TYPE});
});
return ajax("GET", "myUrl", {}, {}, fetchPromise).then(
function () {},
function (data) {
assert.deepEqual(data, { error: "Incorrect response type", code: AJAX_ERROR_CODES.INCORRECT_RESPONSE_TYPE });
},
);
});

QUnit.test("Status 404", function (assert) {
function fetchPromise() {
const blob = new Blob([JSON.stringify({error: "not found"})], {type : 'application/json'});
const init = {status: 404, headers: {'content-type': 'application/json'}};
const blob = new Blob([JSON.stringify({ error: "not found" })], { type: "application/json" });
const init = { status: 404, headers: { "content-type": "application/json" } };
return Promise.resolve(new Response(blob, init));
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function() {}, function(data) {
return ajax("GET", "myUrl", {}, {}, fetchPromise).then(
function () {},
function (data) {
assert.strictEqual(data.error, "not found");
});
},
);
});

QUnit.test("Unknown error", function (assert) {
function fetchPromise() {
const blob = new Blob([JSON.stringify("")], {type : 'application/json'});
const init = {status: 404, headers: {'content-type': 'application/json'}};
const blob = new Blob([JSON.stringify("")], { type: "application/json" });
const init = { status: 404, headers: { "content-type": "application/json" } };
return Promise.resolve(new Response(blob, init));
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function() {}, function(data) {
assert.deepEqual(data, {error: "Unknown error", code: AJAX_ERROR_CODES.UNKNOWN_ERROR});
});
return ajax("GET", "myUrl", {}, {}, fetchPromise).then(
function () {},
function (data) {
assert.deepEqual(data, { error: "Unknown error", code: AJAX_ERROR_CODES.UNKNOWN_ERROR });
},
);
});

QUnit.test("Network error", function (assert) {
function fetchPromise() {
return Promise.reject();
}

return ajax("GET", "myUrl", {}, {}, fetchPromise)
.then(function() {}, function(data) {
assert.deepEqual(data, {error: "Network error", code: AJAX_ERROR_CODES.NETWORK_ERROR});
});
return ajax("GET", "myUrl", {}, {}, fetchPromise).then(
function () {},
function (data) {
assert.deepEqual(data, { error: "Network error", code: AJAX_ERROR_CODES.NETWORK_ERROR });
},
);
});

QUnit.test("Check sent data", function (assert) {
function fetchPromise(url, options) {
assert.strictEqual(url.href, "https://www.dummy.org/api/index.php?url=myUrl&querykey=queryvalue");
assert.strictEqual(options.method, "POST");
assert.strictEqual(options.headers['Content-Type'], 'application/json');
assert.strictEqual(options.headers["Content-Type"], "application/json");
assert.strictEqual(options.headers["X-API-KEY"], "SESSION");
assert.strictEqual(options.headers.Accept, 'application/json');
assert.strictEqual(options.body, "{\"datakey\":\"datavalue\"}");
const blob = new Blob([JSON.stringify("mydata")], {type : 'application/json'});
const init = {status: 200, headers: {'content-type': 'application/json'}};
assert.strictEqual(options.headers.Accept, "application/json");
assert.strictEqual(options.body, '{"datakey":"datavalue"}');
const blob = new Blob([JSON.stringify("mydata")], { type: "application/json" });
const init = { status: 200, headers: { "content-type": "application/json" } };
return Promise.resolve(new Response(blob, init));
}

return ajax("POST", "myUrl", {querykey: "queryvalue"}, {datakey: "datavalue"}, fetchPromise)
.then();
return ajax("POST", "myUrl", { querykey: "queryvalue" }, { datakey: "datavalue" }, fetchPromise).then();
});
});
5 changes: 2 additions & 3 deletions SETUP/tests/jsTests/characterValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

var validCharacterPattern;

QUnit.module("Character validation test", function() {

QUnit.module("Character validation test", function () {
let basicLatin = "^(?:[\n\r -~¡-¬®-ÿŒœŠšŽžŸƒ‹›])$";

QUnit.test("In basic latin basic latin character is valid", function (assert) {
Expand Down Expand Up @@ -53,6 +52,6 @@ QUnit.module("Character validation test", function() {
assert.strictEqual(testText("\u{13000}"), true);
assert.strictEqual(testText("𓀂"), true);
assert.strictEqual(testText("𓀁"), true);
assert.strictEqual(testText("𓀉"),false);
assert.strictEqual(testText("𓀉"), false);
});
});
86 changes: 43 additions & 43 deletions SETUP/tests/jsTests/dp_proofTests.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/* global QUnit surroundSelection submitForm */

QUnit.module("dp_proof tests", function(hooks) {
QUnit.module("dp_proof tests", function (hooks) {
let setTestText = (text, start, end) => {
window.docRef = {
editform: {
// eslint-disable-next-line camelcase
text_data: document.createElement('textarea'),
}
text_data: document.createElement("textarea"),
},
};
window.docRef.editform.text_data.value = text;
window.docRef.editform.text_data.setSelectionRange(start, end, 'forward');
window.docRef.editform.text_data.setSelectionRange(start, end, "forward");
};

hooks.beforeEach(function() {
hooks.beforeEach(function () {
window.inFace = 0;
});

hooks.afterEach(function() {
hooks.afterEach(function () {
delete window.docRef;
delete window.inFace;
});

QUnit.test("submitForm prevents double submit", function (assert) {
const done = assert.async();
const form = document.createElement('form');
const submitButton = document.createElement('input');
const form = document.createElement("form");
const submitButton = document.createElement("input");
let submitCount = 0;
submitButton.type = 'submit';
form.addEventListener('submit', (event) => {
submitButton.type = "submit";
form.addEventListener("submit", (event) => {
event.preventDefault();
submitForm(event.target);
submitCount++;
Expand All @@ -49,68 +49,68 @@ QUnit.module("dp_proof tests", function(hooks) {
});

QUnit.test("surroundSelection surrounds selection", function (assert) {
setTestText('hello', 0, 5);
surroundSelection('<i>', '</i>');
assert.strictEqual(window.docRef.editform.text_data.value, "<i>hello</i>", 'surrouned text with <i>');
setTestText("hello", 0, 5);
surroundSelection("<i>", "</i>");
assert.strictEqual(window.docRef.editform.text_data.value, "<i>hello</i>", "surrouned text with <i>");
});

QUnit.test("surroundSelection surrounds selection", function (assert) {
setTestText('hello', 0, 5);
surroundSelection('<i>', '</i>');
assert.strictEqual(window.docRef.editform.text_data.value, "<i>hello</i>", 'surrouned text with <i>');
setTestText("hello", 0, 5);
surroundSelection("<i>", "</i>");
assert.strictEqual(window.docRef.editform.text_data.value, "<i>hello</i>", "surrouned text with <i>");
});

QUnit.test("surroundSelection with [** without selection", function (assert) {
setTestText('hello', 0, 0);
surroundSelection('[** ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[** ]hello", 'inserts [**');
setTestText("hello", 0, 0);
surroundSelection("[** ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[** ]hello", "inserts [**");
});

QUnit.test("surroundSelection with [** duplicates selection for typos", function (assert) {
setTestText('hello', 0, 5);
surroundSelection('[** ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "hello[** hello]", 'surrouned text with [**');
setTestText("hello", 0, 5);
surroundSelection("[** ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "hello[** hello]", "surrouned text with [**");
});

QUnit.test("surroundSelection with [Illustration: with selection", function (assert) {
setTestText('hello', 0, 5);
surroundSelection('[Illustration: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration: hello]", 'surrouned text with [Illustration: ');
setTestText("hello", 0, 5);
surroundSelection("[Illustration: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration: hello]", "surrouned text with [Illustration: ");
});

QUnit.test("surroundSelection with [Illustration: without selection", function (assert) {
setTestText('hello', 0, 0);
surroundSelection('[Illustration: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", 'inserts text with [Illustration ');
setTestText("hello", 0, 0);
surroundSelection("[Illustration: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", "inserts text with [Illustration ");
});

QUnit.test("surroundSelection with [Illustration: without selection", function (assert) {
setTestText('hello', 0, 0);
surroundSelection('[Illustration: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", 'inserts text with [Illustration ');
setTestText("hello", 0, 0);
surroundSelection("[Illustration: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Illustration]hello", "inserts text with [Illustration ");
});

QUnit.test("surroundSelection with [Footnote #: without selection", function (assert) {
setTestText('hello', 0, 0);
surroundSelection('[Footnote #: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote]hello", 'inserts text with [Footnote]');
setTestText("hello", 0, 0);
surroundSelection("[Footnote #: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote]hello", "inserts text with [Footnote]");
});

QUnit.test("surroundSelection with [Footnote #: with selection", function (assert) {
setTestText('hello', 0, 5);
surroundSelection('[Footnote #: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote: hello]", 'surrounds text with [Footnote: ]');
setTestText("hello", 0, 5);
surroundSelection("[Footnote #: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote: hello]", "surrounds text with [Footnote: ]");
});

QUnit.test("surroundSelection with [Footnote #: with selection and identifier", function (assert) {
setTestText('a hello', 0, 7);
surroundSelection('[Footnote #: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote a: hello]", 'surrounds text with [Footnote: ]');
setTestText("a hello", 0, 7);
surroundSelection("[Footnote #: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote a: hello]", "surrounds text with [Footnote: ]");
});

QUnit.test("surroundSelection with [Footnote #: with selection and identifier", function (assert) {
setTestText('1 hello', 0, 7);
surroundSelection('[Footnote #: ', ']');
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote 1: hello]", 'surrounds text with [Footnote: ]');
setTestText("1 hello", 0, 7);
surroundSelection("[Footnote #: ", "]");
assert.strictEqual(window.docRef.editform.text_data.value, "[Footnote 1: hello]", "surrounds text with [Footnote: ]");
});
});
Loading

0 comments on commit b1a7f1e

Please sign in to comment.