@bigbinary/neeto-commons-frontend 2.0.108 → 2.0.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  const { defineConfig } = require("cypress");
2
2
 
3
3
  const defineCypressConfig = (overrides = {}) => {
4
- const globalState = { skipSetup: false };
5
-
6
4
  const { e2e: e2eOverrides = {}, ...otherProps } = overrides;
7
5
 
8
6
  return defineConfig({
@@ -18,13 +16,6 @@ const defineCypressConfig = (overrides = {}) => {
18
16
  retries: { runMode: 1, openMode: 0 },
19
17
  e2e: {
20
18
  setupNodeEvents(on, config) {
21
- on("task", {
22
- getGlobalState: key => (key ? globalState[key] || null : globalState),
23
- updateGlobalState: ({ key, value }) => (globalState[key] = value),
24
- bulkUpdateGlobalState: newState =>
25
- Object.assign(globalState, newState),
26
- });
27
-
28
19
  return require("./plugins")(on, config);
29
20
  },
30
21
  specPattern: "cypress/e2e/**/*.spec.js",
@@ -20,6 +20,8 @@ const getConfigurationByFile = file => {
20
20
  return file && fs.readJsonSync(path.join(process.cwd(), pathToConfigFile));
21
21
  };
22
22
 
23
+ const globalState = "globalState.txt";
24
+
23
25
  const merge = (target, source = {}) => {
24
26
  Object.keys(source).forEach(key => {
25
27
  if (source[key] && typeof source[key] === "object") {
@@ -61,5 +63,43 @@ module.exports = (on, config) => {
61
63
  return launchOptions;
62
64
  });
63
65
 
66
+ const readFileSyncIfExists = filePath => {
67
+ try {
68
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
69
+ } catch (error) {
70
+ if (error.code === "ENOENT") {
71
+ return {};
72
+ }
73
+ console.log(error); // eslint-disable-line
74
+ }
75
+
76
+ return {};
77
+ };
78
+
79
+ const writeDataToFile = (filePath, data) => {
80
+ try {
81
+ fs.writeFileSync(filePath, data, "utf8");
82
+ } catch (err) {
83
+ console.log(err); // eslint-disable-line
84
+ }
85
+
86
+ return true;
87
+ };
88
+
89
+ on("task", {
90
+ getGlobalState: key =>
91
+ key
92
+ ? readFileSyncIfExists(globalState)?.[key] ?? null
93
+ : readFileSyncIfExists(globalState),
94
+ updateGlobalState: ({ key, value }) => {
95
+ const data = readFileSyncIfExists(globalState);
96
+ data[key] = value;
97
+
98
+ return writeDataToFile(globalState, JSON.stringify(data));
99
+ },
100
+ bulkUpdateGlobalState: newState =>
101
+ writeDataToFile(globalState, JSON.stringify(newState)),
102
+ });
103
+
64
104
  return config, newEnvironment;
65
105
  };
@@ -1089,31 +1089,37 @@ var memberUtils = {
1089
1089
  clickOnColumnIcon: clickOnColumnIcon
1090
1090
  };
1091
1091
 
1092
- var updateSubdomainIfExists = function updateSubdomainIfExists(appName, subdomainName) {
1092
+ var extractSubdomainFromError = function extractSubdomainFromError(inputString) {
1093
+ var regex = /cypresstest[a-zA-Z0-9-]+/g;
1094
+ var matches = inputString.match(regex);
1095
+ return matches[1];
1096
+ };
1097
+ var updateSubdomainIfExists = function updateSubdomainIfExists(appName) {
1093
1098
  cy.ifExist(signUpSelectors.subdomainError, function () {
1094
- var lastDigit = Number(subdomainName.charAt(subdomainName.length - 1));
1095
- var newOrganizationName = subdomainName.slice(0, -1) + (lastDigit + 1);
1096
- cy.intercept({
1097
- url: requestApis.subdomainAvailability,
1098
- times: 1
1099
- }).as("subdomainRequest");
1100
- cy.clearAndType(signUpSelectors.subdomainNameTextField, newOrganizationName);
1101
- cy.wait("@subdomainRequest");
1102
- cy.ifNotExist(signUpSelectors.subdomainError, function () {
1103
- cy.task("updateGlobalState", {
1104
- key: "subdomainName",
1105
- value: newOrganizationName
1106
- });
1107
- cy.task("updateGlobalState", {
1108
- key: "businessName",
1109
- value: newOrganizationName
1099
+ cy.get(signUpSelectors.subdomainError).invoke("text").then(function (text) {
1100
+ cy.intercept({
1101
+ url: requestApis.subdomainAvailability,
1102
+ times: 1
1103
+ }).as("subdomainRequest");
1104
+ var newOrganizationName = extractSubdomainFromError(text);
1105
+ cy.clearAndType(signUpSelectors.subdomainNameTextField, newOrganizationName);
1106
+ cy.wait("@subdomainRequest");
1107
+ cy.ifNotExist(signUpSelectors.subdomainError, function () {
1108
+ cy.task("updateGlobalState", {
1109
+ key: "subdomainName",
1110
+ value: newOrganizationName
1111
+ });
1112
+ cy.task("updateGlobalState", {
1113
+ key: "businessName",
1114
+ value: newOrganizationName
1115
+ });
1116
+ var newBaseUrl = "https://".concat(newOrganizationName, ".").concat(appName, ".").concat(env.tld);
1117
+ Cypress.config("baseUrl", newBaseUrl);
1118
+ cy.clearAndType(signUpSelectors.organizationNameTextField, newOrganizationName);
1110
1119
  });
1111
- var newBaseUrl = "https://".concat(newOrganizationName, ".").concat(appName, ".").concat(env.tld);
1112
- Cypress.config("baseUrl", newBaseUrl);
1113
- cy.clearAndType(signUpSelectors.organizationNameTextField, newOrganizationName);
1114
1120
  });
1115
1121
  cy.ifExist(signUpSelectors.subdomainError, function () {
1116
- return updateSubdomainIfExists(appName, newOrganizationName);
1122
+ return updateSubdomainIfExists(appName);
1117
1123
  });
1118
1124
  });
1119
1125
  };
@@ -1129,7 +1135,7 @@ var createOrganization = function createOrganization(_ref) {
1129
1135
  var appNameInLowerCase = appName.toLowerCase();
1130
1136
  var isNeetoAuth = appNameInLowerCase === "neetoauth";
1131
1137
  if (isNeetoAuth) cy.visit("https://app.neetoauth.".concat(env.tld, "/signups/new"));else {
1132
- var startingUrl = "https://www.neeto.com/".concat(appNameInLowerCase).concat(env.isProduction ? "?env=staging" : "");
1138
+ var startingUrl = "https://www.neeto.com/".concat(appNameInLowerCase).concat(env.isStaging ? "?env=staging" : "");
1133
1139
  cy.visit(startingUrl);
1134
1140
  cy.get(signUpSelectors.tryFreeButton).invoke("removeAttr", "target").click();
1135
1141
  }
@@ -1158,7 +1164,7 @@ var createOrganization = function createOrganization(_ref) {
1158
1164
  cy.clearAndType(signUpSelectors.organizationNameTextField, businessName);
1159
1165
  cy.clearAndType(signUpSelectors.subdomainNameTextField, subdomainName);
1160
1166
  cy.wait("@subdomainRequest");
1161
- updateSubdomainIfExists(appNameInLowerCase, subdomainName);
1167
+ updateSubdomainIfExists(appNameInLowerCase);
1162
1168
  cy.intercept({
1163
1169
  url: requestApis.signUp,
1164
1170
  times: 1