UNPKG

detox-allure2-adapter

Version:
323 lines 11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SliderPositionMatcherResult = exports.AnythingMatcherResult = exports.ClassMatcherResult = exports.FocusMatcherResult = exports.NotVisibleMatcherResult = exports.VisibilityMatcherResult = exports.NullMatcherResult = exports.ToggleableMatcherResult = exports.IndexMatcherResult = exports.DescendantMatcherResult = exports.AncestorMatcherResult = exports.NotMatcherResult = exports.OrMatcherResult = exports.AndMatcherResult = exports.ContentDescriptionMatcherResult = exports.ShallowAccessibilityLabelMatcherResult = exports.AccessibilityLabelMatcherResult = exports.TextMatcherResult = exports.TestIdMatcherResult = exports.StateMatcher = exports.CompositeMatcher = exports.ExactMatcher = exports.RegexMatcher = void 0; const utils_1 = require("../../utils"); class DualMatcherResult { matcher; constructor(value, isRegex, exactFactory, regexFactory) { this.matcher = isRegex ? regexFactory(value) : exactFactory(value); } toJSON() { return this.matcher.toJSON(); } } class RegexMatcher { pattern; type; constructor(pattern, type) { this.pattern = pattern; this.type = type; } toJSON() { const typeStr = this.getTypeString(); return (0, utils_1.msg)(`with ${typeStr} matching /${this.pattern}/`); } getTypeString() { switch (this.type) { case 'a11y-label': { return 'accessibility label'; } case 'shallow-a11y-label': { return 'shallow accessibility label'; } case 'content-desc': { return 'content description'; } case 'text': { return 'text'; } default: { return this.type; } } } } exports.RegexMatcher = RegexMatcher; class ExactMatcher { value; type; constructor(value, type) { this.value = value; this.type = type; } toJSON() { switch (this.type) { case 'id': { return (0, utils_1.msg)(`#${this.value}`, { id: this.value }); } case 'text': { return (0, utils_1.msg)(JSON.stringify(this.value), { text: this.value }); } case 'type': { return (0, utils_1.msg)(`${this.value}`, { type: this.value }); } case 'a11y-label': { return (0, utils_1.msg)(`[label=${this.value}]`, { a11y_label: this.value }); } case 'shallow-a11y-label': { return (0, utils_1.msg)(`[label=${this.value}]`, { shallow_a11y_label: this.value }); } case 'content-desc': { return (0, utils_1.msg)(JSON.stringify(this.value), { content_desc: true }); } default: { return (0, utils_1.msg)('?', { type: this.type }); } } } } exports.ExactMatcher = ExactMatcher; class CompositeMatcher { matchers; type; extraValue; constructor(matchers, type, extraValue) { this.matchers = matchers; this.type = type; this.extraValue = extraValue; } toJSON() { switch (this.type) { case 'and': { return (0, utils_1.concat)(this.matchers[0], (0, utils_1.msg)('and'), this.matchers[1]); } case 'or': { return (0, utils_1.concat)(this.matchers[0], (0, utils_1.msg)('or'), this.matchers[1]); } case 'not': { return (0, utils_1.concat)((0, utils_1.msg)('not'), this.matchers[0]); } case 'with ancestor': case 'with descendant': { return (0, utils_1.concat)(this.matchers[0], (0, utils_1.msg)(this.type), this.matchers[1]); } case 'at index': { return (0, utils_1.concat)(this.matchers[0], (0, utils_1.msg)(`at index ${this.extraValue}`)); } default: { return (0, utils_1.msg)(''); } } } } exports.CompositeMatcher = CompositeMatcher; class StateMatcher { type; value; extraValue; constructor(type, value, extraValue) { this.type = type; this.value = value; this.extraValue = extraValue; } toJSON() { switch (this.type) { case 'toggleable': { return (0, utils_1.msg)(`to be ${this.value ? 'checked' : 'unchecked'}`); } case 'null': { return (0, utils_1.msg)(this.value ? 'to be null' : 'not to be null'); } case 'visible': { return (0, utils_1.msg)(`to be >=${this.value}% visible`, { amount: this.value }); } case 'not visible': { return (0, utils_1.msg)('not to be visible'); } case 'focus': { return (0, utils_1.msg)('to be focused'); } case 'class': { return (0, utils_1.msg)(`to be of class "${this.value}"`, { class: this.value }); } case 'slider': { return (0, utils_1.msg)(`to have slider position ${this.value}${this.extraValue})`, { position: this.value, tolerance: this.extraValue, }); } case 'anything': { return (0, utils_1.msg)('to match anything'); } default: { return (0, utils_1.msg)(''); } } } } exports.StateMatcher = StateMatcher; class TestIdMatcher extends ExactMatcher { constructor(id) { super(id, 'id'); } } class TestIdRegexMatcher extends RegexMatcher { constructor(pattern) { super(pattern, 'id'); } } class TestIdMatcherResult extends DualMatcherResult { constructor(id, isRegex) { super(id, isRegex, (v) => new TestIdMatcher(v), (v) => new TestIdRegexMatcher(v)); } } exports.TestIdMatcherResult = TestIdMatcherResult; class TextMatcher extends ExactMatcher { constructor(text) { super(text, 'text'); } } class TextRegexMatcher extends RegexMatcher { constructor(pattern) { super(pattern, 'text'); } } class TextMatcherResult extends DualMatcherResult { constructor(text, isRegex) { super(text, isRegex, (v) => new TextMatcher(v), (v) => new TextRegexMatcher(v)); } } exports.TextMatcherResult = TextMatcherResult; class AccessibilityLabelMatcher extends ExactMatcher { constructor(label) { super(label, 'a11y-label'); } } class AccessibilityLabelRegexMatcher extends RegexMatcher { constructor(pattern) { super(pattern, 'a11y-label'); } } class AccessibilityLabelMatcherResult extends DualMatcherResult { constructor(label, isRegex) { super(label, isRegex, (v) => new AccessibilityLabelMatcher(v), (v) => new AccessibilityLabelRegexMatcher(v)); } } exports.AccessibilityLabelMatcherResult = AccessibilityLabelMatcherResult; class ShallowAccessibilityLabelMatcher extends ExactMatcher { constructor(label) { super(label, 'shallow-a11y-label'); } } class ShallowAccessibilityLabelRegexMatcher extends RegexMatcher { constructor(pattern) { super(pattern, 'shallow-a11y-label'); } } class ShallowAccessibilityLabelMatcherResult extends DualMatcherResult { constructor(label, isRegex) { super(label, isRegex, (v) => new ShallowAccessibilityLabelMatcher(v), (v) => new ShallowAccessibilityLabelRegexMatcher(v)); } } exports.ShallowAccessibilityLabelMatcherResult = ShallowAccessibilityLabelMatcherResult; class ContentDescriptionMatcher extends ExactMatcher { constructor(description) { super(description, 'content-desc'); } } class ContentDescriptionRegexMatcher extends RegexMatcher { constructor(pattern) { super(pattern, 'content-desc'); } } class ContentDescriptionMatcherResult extends DualMatcherResult { constructor(description, isRegex = false) { super(description, isRegex, (v) => new ContentDescriptionMatcher(v), (v) => new ContentDescriptionRegexMatcher(v)); } } exports.ContentDescriptionMatcherResult = ContentDescriptionMatcherResult; class AndMatcherResult extends CompositeMatcher { constructor(matcher1, matcher2) { super([matcher1, matcher2], 'and'); } } exports.AndMatcherResult = AndMatcherResult; class OrMatcherResult extends CompositeMatcher { constructor(matcher1, matcher2) { super([matcher1, matcher2], 'or'); } } exports.OrMatcherResult = OrMatcherResult; class NotMatcherResult extends CompositeMatcher { constructor(matcher) { super([matcher], 'not'); } } exports.NotMatcherResult = NotMatcherResult; class AncestorMatcherResult extends CompositeMatcher { constructor(matcher, ancestorMatcher) { super([matcher, ancestorMatcher], 'with ancestor'); } } exports.AncestorMatcherResult = AncestorMatcherResult; class DescendantMatcherResult extends CompositeMatcher { constructor(matcher, descendantMatcher) { super([matcher, descendantMatcher], 'with descendant'); } } exports.DescendantMatcherResult = DescendantMatcherResult; class IndexMatcherResult extends CompositeMatcher { constructor(index, innerMatcher) { super([innerMatcher], 'at index', index); } } exports.IndexMatcherResult = IndexMatcherResult; class ToggleableMatcherResult extends StateMatcher { constructor(value) { super('toggleable', value); } } exports.ToggleableMatcherResult = ToggleableMatcherResult; class NullMatcherResult extends StateMatcher { constructor(isNull) { super('null', isNull); } } exports.NullMatcherResult = NullMatcherResult; class VisibilityMatcherResult extends StateMatcher { constructor(percentVisible) { super('visible', percentVisible); } } exports.VisibilityMatcherResult = VisibilityMatcherResult; class NotVisibleMatcherResult extends StateMatcher { constructor() { super('not visible'); } } exports.NotVisibleMatcherResult = NotVisibleMatcherResult; class FocusMatcherResult extends StateMatcher { constructor() { super('focus'); } } exports.FocusMatcherResult = FocusMatcherResult; class ClassMatcherResult extends StateMatcher { constructor(className) { super('class', className); } } exports.ClassMatcherResult = ClassMatcherResult; class AnythingMatcherResult extends StateMatcher { constructor() { super('anything'); } } exports.AnythingMatcherResult = AnythingMatcherResult; class SliderPositionMatcherResult extends StateMatcher { constructor(position, tolerance) { super('slider', position, tolerance); } } exports.SliderPositionMatcherResult = SliderPositionMatcherResult; //# sourceMappingURL=DetoxMatcherResults.js.map