UNPKG

skutter

Version:

Skutter: Opinionated BDD Browser based test framework

89 lines (88 loc) 5.69 kB
"use strict"; const verbosity_level_aware_logger_1 = require("../framework/services/verbosity-level-aware-logger"); class QualifierValidator { static qualifierValidate(qualifier, data, expected) { verbosity_level_aware_logger_1.VerbosityLevelAwareConsoleLog.test(`Testing: "${data}" ${qualifier} "${expected}".`); switch (qualifier) { case "is": return data === expected ? null : `Expected "${data}" to equal "${expected}".`; case "is not": return data !== expected ? null : `Expected "${data}" not to equal "${expected}".`; case "contains": return data.indexOf(expected) !== -1 ? null : `Expected "${data}" to contain "${expected}".`; case "does not contain": return data.indexOf(expected) === -1 ? null : `Expected "${data}" not to contain "${expected}".`; case "starts with": return data.indexOf(expected) === 0 ? null : `Expected "${data}" to start with "${expected}".`; case "does not start with": return data.indexOf(expected) !== 0 ? null : `Expected "${data}" not to start with "${expected}".`; case "ends with": return data.substr(-expected.length) === expected ? null : `Expected "${data}" to end with "${expected}".`; case "does not end with": return data.substr(-expected.length) !== expected ? null : `Expected "${data}" not to end with "${expected}".`; default: throw new Error(`[qualifierValidate] qualifier value of "${qualifier}" is not supported.`); } } static pluralQualifierValidate(qualifier, data, expected) { verbosity_level_aware_logger_1.VerbosityLevelAwareConsoleLog.test(`Testing: "${data}" ${qualifier} "${expected}".`); switch (qualifier) { case "are": return data === expected ? null : `Expected all to equal "${expected}", But found one with value "${data}".`; case "are not": return data !== expected ? null : `Expected none to equal "${expected}", But found one with value "${data}".`; case "contain": return data.indexOf(expected) !== -1 ? null : `Expected all to contain "${expected}", But found "${data}" which doesn't.`; case "do not contain": return data.indexOf(expected) === -1 ? null : `Expected none to contain "${expected}", But found "${data}" which does.`; case "start with": return data.indexOf(expected) === 0 ? null : `Expected all to start with "${expected}", But found "${data}" which doesn't.`; case "do not start with": return data.indexOf(expected) !== 0 ? null : `Expected none to start with "${expected}", But found "${data}" which does.`; case "end with": return data.substr(-expected.length) === expected ? null : `Expected all to end with "${expected}", But found "${data}" which doesn't.`; case "do not end with": return data.substr(-expected.length) !== expected ? null : `Expected none to end with "${expected}", But found "${data}" which does.`; default: throw new Error(`[qualifierValidate] qualifier value of "${qualifier}" is not supported.`); } } static qualifierNumericalValidate(data, qualifier, expected) { verbosity_level_aware_logger_1.VerbosityLevelAwareConsoleLog.test(`Testing: ${data} ${qualifier} ${expected}.`); switch (qualifier) { case "at least": return data >= expected ? null : `Expected ${data} to be at least ${expected}.`; case "greater than": return data > expected ? null : `Expected ${data} to be greater than ${expected}.`; case "less than": return data < expected ? null : `Expected ${data} to be less than ${expected}.`; case "is": case "exactly": return data == expected ? null : `Expected ${data} to be exactly ${expected}.`; case "is not": return data !== expected ? null : `Expected ${data} to not be ${expected}.`; case "at most": return data <= expected ? null : `Expected ${data} to be at most ${expected}.`; default: throw new Error(`[qualifierValidate] qualifier value of "${qualifier}" is not supported.`); } } static visibilityQualifierValidate(qualifier, result) { verbosity_level_aware_logger_1.VerbosityLevelAwareConsoleLog.test(`Testing: Element ${qualifier}`); switch (qualifier) { case "is visible": case "is not hidden": return result === true ? null : "Expected element to be visible."; case "is not visible": case "is hidden": return result === false ? null : "Expected element not to be visible."; default: throw new Error(`[qualifierValidate] qualifier value of "${qualifier}" is not supported.`); } } } QualifierValidator.qualifierRegex = /(is not|is|contains|does not contain|starts with|does not start with|ends with|does not end with)/; QualifierValidator.qualifierPluralRegex = /(are not|are|contain|do not contain|start with|do not start with|end with|do not end with)/; QualifierValidator.qualifierNumericalRegex = /(at least|less than|greater than|exactly|at most)/; QualifierValidator.qualifierVisibilityRegex = /(is not visible|is visible|is not hidden|is hidden)/; exports.QualifierValidator = QualifierValidator;