feat: frontend unit tests

This commit is contained in:
Yiannis Stergiou
2026-01-07 19:47:54 +02:00
committed by GitHub
parent ed5cfa1a84
commit 1c15880ae3
74 changed files with 6000 additions and 877 deletions

View File

@@ -1,38 +1,41 @@
import { logErrorAndReturnError } from './errors';
import { isPositiveInteger, isPositiveIntegerOrZero } from './math';
export const PositiveIntegerOrZero = (function () {
return function (obj, key, comp) {
return void 0 === obj[key] || isPositiveIntegerOrZero(obj[key])
? null
: logErrorAndReturnError([
'Invalid prop `' +
key +
'` of type `' +
typeof obj[key] +
'` supplied to `' +
(comp || 'N/A') +
'`, expected `positive integer or zero` (' +
obj[key] +
').',
]);
};
const isPositiveIntegerOrZero = (x) => x === Math.trunc(x) && x >= 0;
return function (obj, key, comp) {
return void 0 === obj[key] || isPositiveIntegerOrZero(obj[key])
? null
: logErrorAndReturnError([
'Invalid prop `' +
key +
'` of type `' +
typeof obj[key] +
'` supplied to `' +
(comp || 'N/A') +
'`, expected `positive integer or zero` (' +
obj[key] +
').',
]);
};
})();
export const PositiveInteger = (function () {
return function (obj, key, comp) {
return void 0 === obj[key] || isPositiveInteger(obj[key])
? null
: logErrorAndReturnError([
'Invalid prop `' +
key +
'` of type `' +
typeof obj[key] +
'` supplied to `' +
(comp || 'N/A') +
'`, expected `positive integer` (' +
obj[key] +
').',
]);
};
const isPositiveInteger = (x) => x === Math.trunc(x) && x > 0;
return function (obj, key, comp) {
return void 0 === obj[key] || isPositiveInteger(obj[key])
? null
: logErrorAndReturnError([
'Invalid prop `' +
key +
'` of type `' +
typeof obj[key] +
'` supplied to `' +
(comp || 'N/A') +
'`, expected `positive integer` (' +
obj[key] +
').',
]);
};
})();

View File

@@ -1,8 +1,15 @@
// check templates/config/installation/translations.html for more
export function replaceString(string) {
for (const key in window.REPLACEMENTS) {
string = string.replace(key, window.REPLACEMENTS[key]);
export function replaceString(word) {
if (!window.REPLACEMENTS) {
return word;
}
return string;
let result = word;
for (const [search, replacement] of Object.entries(window.REPLACEMENTS)) {
result = result.split(search).join(replacement);
}
return result;
}

View File

@@ -7,13 +7,13 @@ export async function getRequest(url, sync, callback, errorCallback) {
};
function responseHandler(result) {
if (callback instanceof Function) {
if (callback instanceof Function || typeof callback === 'function') {
callback(result);
}
}
function errorHandler(error) {
if (errorCallback instanceof Function) {
if (errorCallback instanceof Function || typeof errorCallback === 'function') {
let err = error;
if (void 0 === error.response) {
err = {
@@ -58,13 +58,13 @@ export async function postRequest(url, postData, configData, sync, callback, err
postData = postData || {};
function responseHandler(result) {
if (callback instanceof Function) {
if (callback instanceof Function || typeof callback === 'function') {
callback(result);
}
}
function errorHandler(error) {
if (errorCallback instanceof Function) {
if (errorCallback instanceof Function || typeof errorCallback === 'function') {
errorCallback(error);
}
}
@@ -84,13 +84,13 @@ export async function putRequest(url, putData, configData, sync, callback, error
putData = putData || {};
function responseHandler(result) {
if (callback instanceof Function) {
if (callback instanceof Function || typeof callback === 'function') {
callback(result);
}
}
function errorHandler(error) {
if (errorCallback instanceof Function) {
if (errorCallback instanceof Function || typeof errorCallback === 'function') {
errorCallback(error);
}
}
@@ -110,13 +110,13 @@ export async function deleteRequest(url, configData, sync, callback, errorCallba
configData = configData || {};
function responseHandler(result) {
if (callback instanceof Function) {
if (callback instanceof Function || typeof callback === 'function') {
callback(result);
}
}
function errorHandler(error) {
if (errorCallback instanceof Function) {
if (errorCallback instanceof Function || typeof errorCallback === 'function') {
errorCallback(error);
}
}

View File

@@ -1,9 +1,5 @@
// check templates/config/installation/translations.html for more
export function translateString(string) {
if (window.TRANSLATION && window.TRANSLATION[string]) {
return window.TRANSLATION[string];
} else {
return string;
}
export function translateString(str) {
return window.TRANSLATION?.[str] ?? str;
}