All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.cjs.cypress-utils.utils.common.js Maven / Gradle / Ivy

Go to download

A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.

There is a newer version: 4.12.3
Show newest version
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.verifyListCount = exports.setListCount = exports.joinHyphenCase = exports.isStagingEnv = exports.initializeCredentials = exports.hyphenize = exports.getUrl = exports.getTestTitle = exports.env = exports.dataTestId = exports.dataCy = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _constants = require("../constants");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var getCountFromText = function getCountFromText(countText) {
  return Number(countText.text().trim().split(" ")[0]);
};
var env = {
  isDevelopment: Cypress.env("configFile") === _constants.environment.development,
  isReview: Cypress.env("configFile") === _constants.environment.review,
  isStaging: Cypress.env("configFile") === _constants.environment.staging,
  isProduction: Cypress.env("configFile") === _constants.environment.production
};
exports.env = env;
env.isNightlyRun = env.isProduction || env.isStaging;
env.tld = env.isProduction ? "com" : "net";
var isStagingEnv = Cypress.env("configFile") === _constants.environment.staging;
exports.isStagingEnv = isStagingEnv;
var dataCy = function dataCy(value) {
  var suffix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
  return "[data-cy='".concat(value, "']").concat(suffix);
};
exports.dataCy = dataCy;
var dataTestId = function dataTestId(value) {
  var suffix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
  return "[data-testid='".concat(value, "']").concat(suffix);
};
exports.dataTestId = dataTestId;
var setListCount = function setListCount(countSelector, alias) {
  return cy.get(countSelector).then(function (countText) {
    cy.wrap(getCountFromText(countText)).as(alias);
  });
};
exports.setListCount = setListCount;
var verifyListCount = function verifyListCount(countSelector, count) {
  return cy.get(countSelector).then(function (countText) {
    cy.wrap(getCountFromText(countText)).should("eq", count);
  });
};
exports.verifyListCount = verifyListCount;
var getUrl = function getUrl(path) {
  return "/api/v1/".concat(path);
};
exports.getUrl = getUrl;
var getTestTitle = function getTestTitle() {
  var ctx = Cypress.mocha.getRunner().suite.ctx;
  return ctx.currentTest.parent.title;
};
exports.getTestTitle = getTestTitle;
var joinHyphenCase = function joinHyphenCase() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }
  return args.join(" ").replace(/\s+/g, "-").toLowerCase();
};
exports.joinHyphenCase = joinHyphenCase;
var hyphenize = function hyphenize(input) {
  var fallbackString = "";
  if (typeof input === "number") return String(input);
  if (input && typeof input === "string" && input.replace) {
    return input.replace(/[\s_]/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").replace(/-+/g, "-").toLowerCase();
  }
  return fallbackString;
};
exports.hyphenize = hyphenize;
var initializeCredentials = function initializeCredentials(stagingData) {
  cy.task("getGlobalState").then(function (state) {
    var newState = _objectSpread(_objectSpread({}, state), {}, {
      businessName: state.businessName || stagingData.businessName,
      currentUserName: state.currentUserName || stagingData.currentUserName,
      email: state.email || stagingData.email,
      firstName: state.firstName || stagingData.firstName,
      lastName: state.lastName || stagingData.lastName,
      subdomainName: state.subdomainName || stagingData.subdomainName,
      skipSetup: state.skipSetup
    });
    if (isStagingEnv) {
      var baseUrl = "https://".concat(newState.subdomainName, ".").concat(stagingData.domain);
      Cypress.config("baseUrl", baseUrl);
    }
    cy.task("bulkUpdateGlobalState", newState);
  });
};
exports.initializeCredentials = initializeCredentials;
//# sourceMappingURL=common.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy