@bigbinary/neeto-playwright-commons 1.1.3 → 1.2.0

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.
package/index.cjs.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var test = require('@playwright/test');
6
+ var dayjs = require('dayjs');
6
7
  var require$$0$3 = require('fs');
7
8
  var require$$2 = require('os');
8
9
  var require$$0 = require('path');
@@ -10,7 +11,6 @@ var require$$0$1 = require('util');
10
11
  var require$$0$2 = require('stream');
11
12
  var require$$0$4 = require('events');
12
13
  var ramda = require('ramda');
13
- var dayjs = require('dayjs');
14
14
  var require$$3 = require('crypto');
15
15
 
16
16
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -33,6 +33,7 @@ function _interopNamespace(e) {
33
33
  return Object.freeze(n);
34
34
  }
35
35
 
36
+ var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
36
37
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
37
38
  var require$$0__namespace = /*#__PURE__*/_interopNamespace(require$$0$3);
38
39
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
@@ -40,7 +41,6 @@ var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
40
41
  var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
41
42
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
42
43
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
43
- var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
44
44
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
45
45
 
46
46
  const COMMON_SELECTORS = {
@@ -56,6 +56,115 @@ const COMMON_SELECTORS = {
56
56
  subheaderText: "subheader-left",
57
57
  };
58
58
 
59
+ class CustomCommands {
60
+ constructor(page, request) {
61
+ this.interceptMultipleResponses = ({ responseUrl = "", times = 1, baseUrl, }) => Promise.all([...new Array(times)].map(() => this.page.waitForResponse((response) => {
62
+ var _a, _b, _c;
63
+ if (response.request().resourceType() === "xhr" &&
64
+ response.status() === 200 &&
65
+ response.url().includes(responseUrl) &&
66
+ response
67
+ .url()
68
+ .startsWith((_a = baseUrl !== null && baseUrl !== void 0 ? baseUrl : process.env.BASE_URL) !== null && _a !== void 0 ? _a : "") &&
69
+ !this.responses.includes((_b = response.headers()) === null || _b === void 0 ? void 0 : _b["x-request-id"])) {
70
+ this.responses.push((_c = response.headers()) === null || _c === void 0 ? void 0 : _c["x-request-id"]);
71
+ return true;
72
+ }
73
+ return false;
74
+ }, { timeout: 10000 })));
75
+ this.recursiveMethod = async (callback, condition, timeout, startTime) => {
76
+ if (Date.now() - timeout >= startTime) {
77
+ return false;
78
+ }
79
+ else if (await condition()) {
80
+ return await callback();
81
+ }
82
+ return await this.recursiveMethod(callback, condition, timeout, startTime);
83
+ };
84
+ this.executeRecursively = async ({ callback, condition, timeout = 5000, }) => {
85
+ const startTime = Date.now();
86
+ await this.recursiveMethod(callback, condition, timeout, startTime);
87
+ };
88
+ this.verifySuccessToast = async ({ message, closeAfterVerification = true, }) => {
89
+ if (message) {
90
+ await test.expect(this.page.getByTestId(COMMON_SELECTORS.toastMessage)).toHaveValue(message);
91
+ }
92
+ else {
93
+ await test.expect(this.page.locator(COMMON_SELECTORS.toastIcon)).toHaveValue("👍");
94
+ closeAfterVerification &&
95
+ (await this.page
96
+ .getByTestId(COMMON_SELECTORS.toastCloseButton)
97
+ .click());
98
+ }
99
+ };
100
+ this.reloadAndWait = async (requestCount) => {
101
+ const reloadRequests = this.interceptMultipleResponses({
102
+ times: requestCount,
103
+ });
104
+ await this.page.reload();
105
+ await reloadRequests;
106
+ };
107
+ this.apiRequest = async ({ url, headers: additionalHeaders, body: data, method = "get", params = {}, ...otherOptions }) => {
108
+ const csrfToken = await this.page
109
+ .locator("[name='csrf-token']")
110
+ .getAttribute("content");
111
+ const requestOptions = {
112
+ headers: {
113
+ ...additionalHeaders,
114
+ "accept-encoding": "gzip",
115
+ "x-csrf-token": csrfToken !== null && csrfToken !== void 0 ? csrfToken : "",
116
+ },
117
+ data,
118
+ params,
119
+ ...otherOptions,
120
+ };
121
+ const httpMethodsHandlers = {
122
+ get: () => this.request.get(url, requestOptions),
123
+ post: () => this.request.post(url, requestOptions),
124
+ put: () => this.request.put(url, requestOptions),
125
+ delete: () => this.request.delete(url, requestOptions),
126
+ };
127
+ return await httpMethodsHandlers[method]();
128
+ };
129
+ this.verifyFieldValue = values => {
130
+ const verifyEachFieldValue = ({ field, value, }) => test.expect(this.page.getByTestId(field)).toHaveValue(value);
131
+ return Array.isArray(values)
132
+ ? Promise.all(values.map(value => verifyEachFieldValue(value)))
133
+ : verifyEachFieldValue(values);
134
+ };
135
+ this.page = page;
136
+ this.responses = [];
137
+ this.request = request;
138
+ }
139
+ }
140
+
141
+ const commands = {
142
+ neetoPlaywrightUtilities: async ({ page, request }, use) => {
143
+ const commands = new CustomCommands(page, request);
144
+ await use(commands);
145
+ },
146
+ page: async ({ page }, use) => {
147
+ await page.goto("/");
148
+ await page.waitForLoadState();
149
+ await use(page);
150
+ },
151
+ };
152
+
153
+ const ENVIRONMENT = {
154
+ development: "development",
155
+ staging: "staging",
156
+ review: "review",
157
+ };
158
+ const IS_STAGING_ENV = process.env.TEST_ENV === "staging";
159
+ const STORAGE_STATE = "./e2e/auth/user.json";
160
+ const GLOBAL_TRANSLATIONS_PATTERN = "../node_modules/@bigbinary/**/translations/en.json";
161
+ const PROJECT_TRANSLATIONS_PATH = "../app/javascript/src/translations/en.json";
162
+ const CREDENTIALS = {
163
+ name: "Oliver Smith",
164
+ email: "oliver@example.com",
165
+ password: "welcome",
166
+ };
167
+
59
168
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
60
169
 
61
170
  var tasks = {};
@@ -6754,17 +6863,6 @@ function assertPatternsInput(input) {
6754
6863
  }
6755
6864
  var out = FastGlob;
6756
6865
 
6757
- const ENVIRONMENT = {
6758
- development: "development",
6759
- staging: "staging",
6760
- review: "review",
6761
- };
6762
- const IS_STAGING_ENV = process.env.TEST_ENV === "staging";
6763
- const STORAGE_STATE = "./e2e/auth/user.json";
6764
- const GLOBAL_TRANSLATIONS_PATTERN = "../node_modules/@bigbinary/**/translations/en.json";
6765
- const PROJECT_TRANSLATIONS_PATH = "../app/javascript/src/translations/en.json";
6766
- const CREDENTIALS = { email: "oliver@example.com", password: "welcome" };
6767
-
6768
6866
  const joinString = (string1, string2, string3 = "", separator = " ") => {
6769
6867
  if (string3 === "") {
6770
6868
  return string1 + separator + string2;
@@ -6810,112 +6908,26 @@ const readTranslations = () => {
6810
6908
  return translations;
6811
6909
  };
6812
6910
 
6813
- class CustomCommands {
6814
- constructor(page, request) {
6815
- this.interceptMultipleResponses = ({ responseUrl = "", times = 1, baseUrl, }) => Promise.all([...new Array(times)].map(() => this.page.waitForResponse(response => {
6816
- var _a, _b, _c;
6817
- if (response.request().resourceType() === "xhr" &&
6818
- response.status() === 200 &&
6819
- response.url().includes(responseUrl) &&
6820
- response
6821
- .url()
6822
- .startsWith((_a = baseUrl !== null && baseUrl !== void 0 ? baseUrl : process.env.BASE_URL) !== null && _a !== void 0 ? _a : "") &&
6823
- !this.responses.includes((_b = response.headers()) === null || _b === void 0 ? void 0 : _b["x-request-id"])) {
6824
- this.responses.push((_c = response.headers()) === null || _c === void 0 ? void 0 : _c["x-request-id"]);
6825
- return true;
6826
- }
6827
- return false;
6828
- }, { timeout: 10000 })));
6829
- this.recursiveMethod = async (callback, condition, timeout, startTime) => {
6830
- if (Date.now() - timeout >= startTime) {
6831
- return false;
6832
- }
6833
- else if (await condition()) {
6834
- return await callback();
6835
- }
6836
- return await this.recursiveMethod(callback, condition, timeout, startTime);
6837
- };
6838
- this.executeRecursively = async ({ callback, condition, timeout = 5000, }) => {
6839
- const startTime = Date.now();
6840
- await this.recursiveMethod(callback, condition, timeout, startTime);
6841
- };
6842
- this.verifySuccessToast = async ({ message, closeAfterVerification = true, }) => {
6843
- if (message) {
6844
- await test.expect(this.page.getByTestId(COMMON_SELECTORS.toastMessage)).toHaveValue(message);
6845
- }
6846
- else {
6847
- await test.expect(this.page.locator(COMMON_SELECTORS.toastIcon)).toHaveValue("👍");
6848
- closeAfterVerification &&
6849
- (await this.page
6850
- .getByTestId(COMMON_SELECTORS.toastCloseButton)
6851
- .click());
6852
- }
6853
- };
6854
- this.reloadAndWait = async (requestCount) => {
6855
- const reloadRequests = this.interceptMultipleResponses({
6856
- times: requestCount,
6857
- });
6858
- await this.page.reload();
6859
- await reloadRequests;
6860
- };
6861
- this.apiRequest = async ({ url, headers: additionalHeaders, body: data, method = "get", params = {}, ...otherOptions }) => {
6862
- const { headers } = readFileSyncIfExists();
6863
- const requestOptions = {
6864
- headers: { ...headers, ...additionalHeaders, "accept-encoding": "gzip" },
6865
- data,
6866
- params,
6867
- ...otherOptions,
6868
- };
6869
- const httpMethodsHandlers = {
6870
- get: () => this.request.get(url, requestOptions),
6871
- post: () => this.request.post(url, requestOptions),
6872
- put: () => this.request.put(url, requestOptions),
6873
- delete: () => this.request.delete(url, requestOptions),
6874
- };
6875
- return await httpMethodsHandlers[method.toLowerCase()]();
6876
- };
6877
- this.verifyFieldValue = values => {
6878
- const verifyEachFieldValue = ({ field, value, }) => test.expect(this.page.getByTestId(field)).toHaveValue(value);
6879
- return Array.isArray(values)
6880
- ? Promise.all(values.map(value => verifyEachFieldValue(value)))
6881
- : verifyEachFieldValue(values);
6882
- };
6883
- this.page = page;
6884
- this.responses = [];
6885
- this.request = request;
6886
- }
6887
- }
6888
-
6889
- const commands = {
6890
- neetoPlaywrightUtilities: async ({ page, request }, use) => {
6891
- const commands = new CustomCommands(page, request);
6892
- await use(commands);
6893
- },
6894
- page: async ({ page }, use) => {
6895
- await page.goto("/");
6896
- await page.waitForLoadState();
6897
- await use(page);
6898
- },
6899
- };
6900
-
6901
- const timestamp = dayjs__default["default"]().format("YYYYMMDDHH");
6902
- const firstName = "André";
6903
- const lastName = "O'Reilly";
6904
- const stagingOrganization = `cypresstest-invoice-${timestamp}`;
6905
- const otpBypassKey = process.env.OTP_BYPASS_KEY;
6906
- const stagingData = {
6907
- firstName,
6908
- lastName,
6909
- otp: 111111,
6910
- domain: "neetoinvoice.net",
6911
- currentUserName: IS_STAGING_ENV
6912
- ? joinString(firstName, lastName)
6913
- : "Oliver Smith",
6914
- businessName: stagingOrganization,
6915
- subdomainName: IS_STAGING_ENV ? stagingOrganization : "spinkart",
6916
- email: IS_STAGING_ENV
6917
- ? `cypresstest${otpBypassKey}+invoice+${timestamp}-playwright@bigbinary.com`
6918
- : "oliver@example.com",
6911
+ const generateStagingData = (product = "invoice") => {
6912
+ const timestamp = dayjs__default["default"]().format("YYYYMMDDHH");
6913
+ const firstName = "André";
6914
+ const lastName = "O'Reilly";
6915
+ const otpBypassKey = process.env.OTP_BYPASS_KEY;
6916
+ const stagingOrganization = `cypresstest-${product}-${timestamp}`;
6917
+ return {
6918
+ firstName,
6919
+ lastName,
6920
+ otp: 111111,
6921
+ domain: `neeto${product}.net`,
6922
+ currentUserName: IS_STAGING_ENV
6923
+ ? joinString(firstName, lastName)
6924
+ : CREDENTIALS.name,
6925
+ businessName: stagingOrganization,
6926
+ subdomainName: IS_STAGING_ENV ? stagingOrganization : "spinkart",
6927
+ email: IS_STAGING_ENV
6928
+ ? `cypresstest${otpBypassKey}+${product}+${timestamp}-playwright@bigbinary.com`
6929
+ : "oliver@example.com",
6930
+ };
6919
6931
  };
6920
6932
 
6921
6933
  const i18n = {
@@ -7020,10 +7032,9 @@ class OrganizationPage {
7020
7032
  await this.page.getByTestId(SIGNUP_SELECTORS.profileSubmitButton).click();
7021
7033
  await submitProfile;
7022
7034
  };
7023
- this.setupOrganization = async () => {
7035
+ this.setupOrganization = async (product) => {
7024
7036
  if (!IS_STAGING_ENV)
7025
7037
  return;
7026
- let headers = {};
7027
7038
  const { user } = readFileSyncIfExists();
7028
7039
  await this.createOrganization({
7029
7040
  businessName: user.businessName,
@@ -7031,20 +7042,15 @@ class OrganizationPage {
7031
7042
  firstName: user.firstName,
7032
7043
  lastName: user.lastName,
7033
7044
  subdomainName: user.subdomainName,
7034
- appName: "neetoInvoice",
7035
- });
7036
- await this.page.route(`**${ROUTES.neetoApps}`, async (route) => {
7037
- headers = await route.request().allHeaders();
7038
- await route.continue();
7045
+ appName: `neeto${product}`,
7039
7046
  });
7040
7047
  await test.expect(this.page.locator(COMMON_SELECTORS.spinner)).toBeHidden();
7041
7048
  const userCredentials = readFileSyncIfExists();
7042
7049
  await this.page.context().storageState({ path: STORAGE_STATE });
7043
- const mergedCredentials = {
7044
- ...readFileSyncIfExists(),
7045
- ...userCredentials,
7046
- headers,
7047
- };
7050
+ const mergedCredentials = ramda.mergeAll([
7051
+ readFileSyncIfExists(),
7052
+ userCredentials,
7053
+ ]);
7048
7054
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7049
7055
  };
7050
7056
  this.updateSubdomainIfExists = async (appName) => {
@@ -7098,8 +7104,9 @@ const LOGIN_SELECTORS = {
7098
7104
 
7099
7105
  const COMMON_TEXTS = { edit: "Edit" };
7100
7106
 
7101
- const initializeCredentials = () => {
7107
+ const initializeCredentials = (product) => {
7102
7108
  const { user } = readFileSyncIfExists();
7109
+ const stagingData = generateStagingData(product);
7103
7110
  const newState = {
7104
7111
  ...user,
7105
7112
  businessName: (user === null || user === void 0 ? void 0 : user.businessName) || stagingData.businessName,
@@ -7117,10 +7124,9 @@ const initializeCredentials = () => {
7117
7124
  }
7118
7125
  };
7119
7126
 
7120
- const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, }) => {
7127
+ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/", }) => {
7121
7128
  var _a;
7122
- await page.goto((_a = process.env.BASE_URL) !== null && _a !== void 0 ? _a : "");
7123
- let headers = {};
7129
+ await page.goto((_a = `${process.env.BASE_URL}${loginPath}`) !== null && _a !== void 0 ? _a : "");
7124
7130
  await page.getByTestId("login-email-text-field").fill(CREDENTIALS.email);
7125
7131
  await page
7126
7132
  .getByTestId("login-password-text-field")
@@ -7130,23 +7136,16 @@ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, }) => {
7130
7136
  });
7131
7137
  await page.getByTestId(LOGIN_SELECTORS.submitButton).click();
7132
7138
  await login;
7133
- await page.route(`**${BASE_URL}/**`, async (route) => {
7134
- headers = await route.request().allHeaders();
7135
- await route.continue();
7136
- });
7137
7139
  const userCredentials = readFileSyncIfExists();
7138
7140
  await page.context().storageState({ path: STORAGE_STATE });
7139
- //eslint-disable-next-line
7140
- await page.waitForTimeout(5000); // There is a delay in headers being set from the route.
7141
- const mergedCredentials = {
7142
- ...readFileSyncIfExists(),
7143
- ...userCredentials,
7144
- headers,
7145
- };
7141
+ const mergedCredentials = ramda.mergeAll([
7142
+ readFileSyncIfExists(),
7143
+ userCredentials,
7144
+ ]);
7146
7145
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7147
7146
  };
7148
- const login = async ({ page, neetoPlaywrightUtilities }) => !IS_STAGING_ENV &&
7149
- (await loginWithoutSSO({ page, neetoPlaywrightUtilities }));
7147
+ const login = async ({ page, neetoPlaywrightUtilities, loginPath, }) => !IS_STAGING_ENV &&
7148
+ (await loginWithoutSSO({ page, neetoPlaywrightUtilities, loginPath }));
7150
7149
 
7151
7150
  var main$1 = {exports: {}};
7152
7151
 
@@ -7613,6 +7612,7 @@ exports.STORAGE_STATE = STORAGE_STATE;
7613
7612
  exports.clearCredentials = clearCredentials;
7614
7613
  exports.commands = commands;
7615
7614
  exports.definePlaywrightConfig = definePlaywrightConfig;
7615
+ exports.generateStagingData = generateStagingData;
7616
7616
  exports.i18n = i18n;
7617
7617
  exports.initializeCredentials = initializeCredentials;
7618
7618
  exports.joinString = joinString;
@@ -7620,7 +7620,6 @@ exports.login = login;
7620
7620
  exports.loginWithoutSSO = loginWithoutSSO;
7621
7621
  exports.readFileSyncIfExists = readFileSyncIfExists;
7622
7622
  exports.readTranslations = readTranslations;
7623
- exports.stagingData = stagingData;
7624
7623
  exports.updateCredentials = updateCredentials;
7625
7624
  exports.writeDataToFile = writeDataToFile;
7626
7625
  //# sourceMappingURL=index.cjs.js.map