mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-01-20 07:12:58 -05:00
feat: frontend unit tests
This commit is contained in:
@@ -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] +
|
||||
').',
|
||||
]);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user