UNPKG

terra-toolkit

Version:

Utilities to help when developing terra modules.

103 lines (83 loc) 3.72 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _accessibility = _interopRequireDefault(require("./accessibility")); var _visualRegression = _interopRequireDefault(require("./visual-regression")); var _determineTestOptions = _interopRequireDefault(require("./determine-test-options")); var _logger = _interopRequireDefault(require("../../../../scripts/utils/logger")); var context = '[Terra-Toolkit:terra-service]'; /** * A chai assertion method to assert the page is accessible and the screenshot comparison result is within * the mismatch tolerance. * * This should be used within a Mocha `it` block. * * @param {string} [name=default] - the test case name. * @param {Object} [options] - the test options * @param {Object} [options.axeRules] - the axe rules to use to assert accessibility. * @param {Number} [options.misMatchTolerance] - the mismatch tolerance for the screenshot comparison. * @param {string} [options.selector=browser.options.terra.selector] - the element selector to use for the * screenshot comparison. */ var validatesElement = function validatesElement() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _determineOptions$axe = _determineTestOptions.default.axeOptions(args), rules = _determineOptions$axe.rules; var _determineOptions$scr = _determineTestOptions.default.screenshotOptions(args), name = _determineOptions$scr.name, selector = _determineOptions$scr.selector, misMatchTolerance = _determineOptions$scr.misMatchTolerance; _accessibility.default.runAccessibilityTest({ rules: rules }); _visualRegression.default.runMatchScreenshotTest(selector, { misMatchTolerance: misMatchTolerance, name: name }); }; /** * @deprecated * * Mocha `it` block to assert the page is accessible and the screenshot comparison result is within the * mismatch tolerance. * * @param {string} [name=default] - the test case name. * @param {Object} [options] - the test options * @param {Object} [options.axeRules] - the axe rules to use to assert accessibility. * @param {Number} [options.misMatchTolerance] - the mismatch tolerance for the screenshot comparison. * @param {string} [options.selector=browser.options.terra.selector] - the element selector to use for the screenshot comparison. */ var itValidatesElement = function itValidatesElement() { _logger.default.warn('Terra.it.validatesElement is deprecated. Please use Terra.validates.element inside an `it` block.', { context: context }); for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } var _determineOptions$axe2 = _determineTestOptions.default.axeOptions(args), rules = _determineOptions$axe2.rules; var _determineOptions$scr2 = _determineTestOptions.default.screenshotOptions(args), name = _determineOptions$scr2.name, selector = _determineOptions$scr2.selector, misMatchTolerance = _determineOptions$scr2.misMatchTolerance; global.it("[".concat(name, "] is accessible and is within the mismatch tolerance"), function () { _accessibility.default.runAccessibilityTest({ rules: rules }); _visualRegression.default.runMatchScreenshotTest(selector, { misMatchTolerance: misMatchTolerance, name: name }); }); }; var methods = { validatesElement: validatesElement, itValidatesElement: itValidatesElement }; var _default = methods; exports.default = _default;