removelevelbutton tests

This commit is contained in:
realaravinth
2021-05-07 18:37:44 +05:30
parent 5b5a995f57
commit d4cf24493a
5 changed files with 148 additions and 14 deletions

View File

@@ -17,22 +17,31 @@
import CONST from '../../const';
import log from '../../../../../../logger';
const updateLabel = (levelGroup: Element, newLevel: number) => {
const updateLabels = (levelGroup: Element, newLevel: number) => {
// rename labels
const labels = <NodeListOf<HTMLLabelElement>>(
levelGroup.querySelectorAll(`.${CONST.LABEL_CLASS}`)
levelGroup.querySelectorAll(`label`)
);
log.log(labels);
labels.forEach(label => {
log.log(`${label.htmlFor}`);
if (label.htmlFor.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
const currentFor = label.htmlFor;
if (currentFor.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
label.htmlFor = `${CONST.VISITOR_WITHOUT_LEVEL}${newLevel}`;
}
if (label.htmlFor.includes(CONST.DIFFICULTY_WITHOUT_LEVEL)) {
} else if (currentFor.includes(CONST.DIFFICULTY_WITHOUT_LEVEL)) {
label.htmlFor = `${CONST.DIFFICULTY_WITHOUT_LEVEL}${newLevel}`;
} else if (
currentFor.includes(CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL)
) {
label.htmlFor = `${CONST.REMOVE_LEVEL_BUTTON_ID_WITHOUT_LEVEL}${newLevel}`;
} else {
if (currentFor != 'add') {
throw new Error(
`Did you add an extra label to DOM? Found label with for: ${currentFor}`,
);
}
}
});
};
export default updateLabel;
export default updateLabels;