removelevelbutton tests

This commit is contained in:
realaravinth
2021-05-07 17:55:42 +05:30
parent 7b3f910da7
commit 5b5a995f57
19 changed files with 1100 additions and 204 deletions

View File

@@ -18,9 +18,11 @@
import {Level} from './index';
import CONST from '../const';
import log from '../../../../../logger';
/** Fetches level from DOM using the ID passesd and validates */
const getLevelFields = (id: number) => {
console.log(`[getLevelFields]: id: ${id}`);
log.debug(`[getLevelFields]: id: ${id}`);
const visitorID = CONST.VISITOR_WITHOUT_LEVEL + id.toString();
const difficultyID = CONST.DIFFICULTY_WITHOUT_LEVEL + id.toString();
@@ -45,7 +47,7 @@ const getLevelFields = (id: number) => {
visitor_threshold,
};
console.debug(
log.debug(
`[getLevelFields.ts] visitor: ${visitor_threshold} difficulty: ${difficulty_factor}`,
);

View File

@@ -17,13 +17,15 @@
import CONST from '../const';
import log from '../../../../../logger';
/** returns number of level input fields currently in DOM */
const getNumLevels = () => {
let numLevels = 0;
document
.querySelectorAll(`.${CONST.LEVEL_CONTAINER_CLASS}`)
.forEach(_ => numLevels++);
console.debug(`[getNumLevels]: numLevels: ${numLevels}`);
log.debug(`[getNumLevels]: numLevels: ${numLevels}`);
return numLevels;
};

View File

@@ -15,6 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import log from '../../../../../logger';
/** Datatype represenging an mCaptcha level */
export type Level = {
difficulty_factor: number;
@@ -30,7 +32,7 @@ class Levels {
}
add = (newLevel: Level) => {
console.debug(`[levels/index.ts] levels lenght: ${this.levels.length}`);
log.debug(`[levels/index.ts] levels lenght: ${this.levels.length}`);
if (newLevel.difficulty_factor <= 0) {
throw new Error('Difficulty must be greater than zero');
}
@@ -44,7 +46,6 @@ class Levels {
return true;
}
let msg;
let count = 1;
this.levels.forEach(level => {
@@ -90,25 +91,25 @@ export const LEVELS = (function() {
}
}
levels.levels = tmpLevel.levels;
console.log(`post update:`);
log.debug(`post update:`);
LEVELS.print();
return true;
} catch (e) {
console.log(e);
log.debug(e);
return false;
}
},
print: () =>
levels.levels.forEach(level =>
console.debug(
log.debug(
`difficulty_factor: ${level.difficulty_factor} visitor ${level.visitor_threshold}`,
),
),
/** remove level */
remove: (id: number) => {
console.debug(`[LEVELS] received order to remove ${id} element`);
log.debug(`[LEVELS] received order to remove ${id} element`);
const tmpLevel = new Levels();
@@ -118,9 +119,9 @@ export const LEVELS = (function() {
if (id != i) {
tmpLevel.add(levels.levels[i]);
} else {
console.debug(`[LEVELS] removing ${i} element`);
log.debug(`[LEVELS] removing ${i} element`);
const rmElement = levels.levels[i];
console.debug(
log.debug(
`[LEVELS] removing element:
difficulty_factor: ${rmElement.difficulty_factor}
visitor_threshold: ${rmElement.visitor_threshold}`,
@@ -128,11 +129,11 @@ export const LEVELS = (function() {
}
}
levels.levels = tmpLevel.levels;
console.debug('Post remove:');
log.debug('Post remove:');
LEVELS.print();
return true;
} catch (e) {
console.log(e);
log.debug(e);
return false;
}
},