package.cjs.cypress-utils.utils.common.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
"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(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var getCountFromText = function getCountFromText(countText) {
return Number(countText.text().trim().split(" ")[0]);
};
var env = exports.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
};
env.isNightlyRun = env.isProduction || env.isStaging;
env.tld = env.isProduction ? "com" : "net";
var isStagingEnv = exports.isStagingEnv = Cypress.env("configFile") === _constants.environment.staging;
var dataCy = exports.dataCy = function dataCy(value) {
var suffix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
return "[data-cy='".concat(value, "']").concat(suffix);
};
var dataTestId = exports.dataTestId = function dataTestId(value) {
var suffix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
return "[data-testid='".concat(value, "']").concat(suffix);
};
var setListCount = exports.setListCount = function setListCount(countSelector, alias) {
return cy.get(countSelector).then(function (countText) {
cy.wrap(getCountFromText(countText)).as(alias);
});
};
var verifyListCount = exports.verifyListCount = function verifyListCount(countSelector, count) {
return cy.get(countSelector).then(function (countText) {
cy.wrap(getCountFromText(countText)).should("eq", count);
});
};
var getUrl = exports.getUrl = function getUrl(path) {
return "/api/v1/".concat(path);
};
var getTestTitle = exports.getTestTitle = function getTestTitle() {
var ctx = Cypress.mocha.getRunner().suite.ctx;
return ctx.currentTest.parent.title;
};
var joinHyphenCase = exports.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();
};
var hyphenize = exports.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;
};
var initializeCredentials = exports.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);
});
};
//# sourceMappingURL=common.js.map