All files / app/codeCharta/ui/ribbonBar/showScenariosButton/addCustomScenarioDialog/utils customScenarioName.validator.ts

100% Statements 8/8
100% Branches 2/2
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  5x   5x 3x 58x 7x   51x 1x   50x      
import { ValidatorFn, AbstractControl, ValidationErrors } from "@angular/forms"
import { ScenarioHelper } from "../../scenarioHelper"
 
export function customScenarioNameValidator(): ValidatorFn {
    return (control: AbstractControl): ValidationErrors | null => {
        if (control.value.length === 0) {
            return { Error: "Scenario name is required" }
        }
        if (ScenarioHelper.isScenarioExisting(control.value)) {
            return { Error: "A Scenario with this name already exists" }
        }
        return null
    }
}