@bigbinary/neeto-playwright-commons 1.7.2 → 1.8.1

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.d.ts CHANGED
@@ -140,6 +140,7 @@ declare class OrganizationPage {
140
140
  page: Page;
141
141
  neetoPlaywrightUtilities: CustomCommands;
142
142
  constructor(page: Page, neetoPlaywrightUtilities: CustomCommands);
143
+ baseUrlGenerator: (appName: string) => string;
143
144
  createOrganization: ({ email, businessName, subdomainName, firstName, lastName, appName, }: CreateOrganizationProps) => Promise<void>;
144
145
  setupOrganization: (product: string) => Promise<void>;
145
146
  updateSubdomainIfExists: (appName: string) => Promise<void>;
@@ -450,8 +451,10 @@ type Hyphenize = (input: number | string) => string;
450
451
  type JoinHyphenCase = (args: string) => string;
451
452
  declare const joinString: JoinString;
452
453
  declare const readFileSyncIfExists: ReadFileSyncIfExists;
454
+ declare const getGlobalUserState: () => Record<string, string>;
453
455
  declare const writeDataToFile: WriteDataToFile;
454
456
  declare const updateCredentials: UpdateCredentials;
457
+ declare const removeCredentialFile: ClearCredentials;
455
458
  declare const clearCredentials: ClearCredentials;
456
459
  declare const hyphenize: Hyphenize;
457
460
  declare const joinHyphenCase: JoinHyphenCase;
@@ -460,6 +463,7 @@ declare const skipTest: {
460
463
  forReviewEnv: () => void;
461
464
  forAllExceptStagingEnv: () => void;
462
465
  };
466
+ declare const shouldSkipSetupAndTeardown: () => boolean | "";
463
467
 
464
468
  interface LoginProps {
465
469
  page: Page;
@@ -509,4 +513,4 @@ interface Overrides {
509
513
  }
510
514
  declare const definePlaywrightConfig: (overrides: Overrides) => _playwright_test.PlaywrightTestConfig<{}, {}>;
511
515
 
512
- export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, type CustomFixture, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, skipTest, updateCredentials, writeDataToFile };
516
+ export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, type CustomFixture, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, updateCredentials, writeDataToFile };
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import test, { expect, test as test$1, defineConfig, devices } from '@playwright/test';
2
2
  import * as require$$0 from 'fs';
3
3
  import require$$0__default from 'fs';
4
- import { isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll, mergeLeft } from 'ramda';
4
+ import { isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll } from 'ramda';
5
5
  import { faker } from '@faker-js/faker';
6
6
  import MailosaurClient from 'mailosaur';
7
7
  import dayjs from 'dayjs';
@@ -44,6 +44,7 @@ const readFileSyncIfExists = (path = STORAGE_STATE) => {
44
44
  return {};
45
45
  }
46
46
  };
47
+ const getGlobalUserState = () => { var _a; return (_a = readFileSyncIfExists()) === null || _a === void 0 ? void 0 : _a.user; };
47
48
  const writeDataToFile = data => {
48
49
  try {
49
50
  require$$0.writeFileSync(STORAGE_STATE, data, "utf8");
@@ -58,13 +59,18 @@ const updateCredentials = ({ key, value }) => {
58
59
  data["user"][key] = value;
59
60
  return writeDataToFile(JSON.stringify(data));
60
61
  };
61
- const clearCredentials = () => {
62
+ const removeCredentialFile = () => {
62
63
  require$$0.unlink(STORAGE_STATE, error => {
63
64
  if (!error)
64
65
  return;
65
66
  console.log(error); // eslint-disable-line
66
67
  });
67
68
  };
69
+ const clearCredentials = () => {
70
+ if (shouldSkipSetupAndTeardown())
71
+ return;
72
+ removeCredentialFile();
73
+ };
68
74
  const hyphenize = input => {
69
75
  const fallbackString = "";
70
76
  if (typeof input === "number")
@@ -84,6 +90,7 @@ const skipTest = {
84
90
  forReviewEnv: () => test.skip(process.env.TEST_ENV === ENVIRONMENT.review),
85
91
  forAllExceptStagingEnv: () => test.skip(process.env.TEST_ENV !== ENVIRONMENT.staging),
86
92
  };
93
+ const shouldSkipSetupAndTeardown = () => { var _a; return ((_a = getGlobalUserState()) === null || _a === void 0 ? void 0 : _a.isLoggedIn) && process.env.SKIP_SETUP === "true"; };
87
94
 
88
95
  const COMMON_SELECTORS = {
89
96
  spinner: ".neeto-ui-spinner",
@@ -176,7 +183,7 @@ class CustomCommands {
176
183
  await this.recursiveMethod(callback, condition, timeout, startTime);
177
184
  };
178
185
  this.verifySuccessToast = async ({ message = "", closeAfterVerification = true, } = {}) => {
179
- if (isEmpty$1(message)) {
186
+ if (!isEmpty$1(message)) {
180
187
  await expect(this.page.getByTestId(COMMON_SELECTORS.toastMessage)).toContainText(message);
181
188
  }
182
189
  else {
@@ -7407,6 +7414,8 @@ class HelpAndProfilePage {
7407
7414
  }));
7408
7415
  };
7409
7416
  this.verifyLogout = async () => {
7417
+ if (shouldSkipSetupAndTeardown())
7418
+ return;
7410
7419
  await test$1.step("Step 1: Open Profile popup and verify", this.openProfilePopup);
7411
7420
  await test$1.step("Step 2: Click logout and verify", async () => {
7412
7421
  await this.page
@@ -7452,9 +7461,15 @@ const extractSubdomainFromError = (errorString) => {
7452
7461
 
7453
7462
  class OrganizationPage {
7454
7463
  constructor(page, neetoPlaywrightUtilities) {
7464
+ this.baseUrlGenerator = (appName) => {
7465
+ const { subdomainName } = getGlobalUserState();
7466
+ return `https://${subdomainName}.${appName}.net`;
7467
+ };
7455
7468
  this.createOrganization = async ({ email, businessName, subdomainName, firstName, lastName, appName, }) => {
7456
7469
  if (!IS_STAGING_ENV)
7457
7470
  return;
7471
+ if (shouldSkipSetupAndTeardown())
7472
+ return;
7458
7473
  const defaultOtp = "123456";
7459
7474
  const appNameInLowerCase = appName.toLowerCase();
7460
7475
  const isNeetoAuth = appNameInLowerCase === "neetoauth";
@@ -7507,6 +7522,8 @@ class OrganizationPage {
7507
7522
  this.setupOrganization = async (product) => {
7508
7523
  if (!IS_STAGING_ENV)
7509
7524
  return;
7525
+ if (shouldSkipSetupAndTeardown())
7526
+ return;
7510
7527
  const { user } = readFileSyncIfExists();
7511
7528
  await this.createOrganization({
7512
7529
  businessName: user.businessName,
@@ -7524,6 +7541,11 @@ class OrganizationPage {
7524
7541
  userCredentials,
7525
7542
  ]);
7526
7543
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7544
+ updateCredentials({ key: "isLoggedIn", value: "true" });
7545
+ updateCredentials({
7546
+ key: "baseUrl",
7547
+ value: this.baseUrlGenerator(`neeto${product}`),
7548
+ });
7527
7549
  };
7528
7550
  this.updateSubdomainIfExists = async (appName) => {
7529
7551
  const subdomainError = this.page.getByTestId(SIGNUP_SELECTORS.subdomainError);
@@ -7545,8 +7567,7 @@ class OrganizationPage {
7545
7567
  key: "businessName",
7546
7568
  value: newOrganizationName,
7547
7569
  });
7548
- const newBaseUrl = `https://${newOrganizationName}.${appName}.net`;
7549
- process.env.BASE_URL = newBaseUrl;
7570
+ process.env.BASE_URL = this.baseUrlGenerator(appName);
7550
7571
  await this.page
7551
7572
  .getByTestId(SIGNUP_SELECTORS.organizationNameTextField)
7552
7573
  .fill(newOrganizationName);
@@ -7690,17 +7711,35 @@ const MERGE_TAGS_SELECTORS = {
7690
7711
  };
7691
7712
 
7692
7713
  const initializeCredentials = (product) => {
7693
- const { user } = readFileSyncIfExists();
7714
+ var _a;
7715
+ if (process.env.SKIP_SETUP === "true" && getGlobalUserState()) {
7716
+ const { email } = getGlobalUserState();
7717
+ if (IS_STAGING_ENV) {
7718
+ email.endsWith("example.com") && removeCredentialFile();
7719
+ }
7720
+ else {
7721
+ email.endsWith("bigbinary.com") && removeCredentialFile();
7722
+ }
7723
+ readFileSyncIfExists();
7724
+ }
7725
+ const skipSetup = shouldSkipSetupAndTeardown();
7726
+ if (skipSetup) {
7727
+ if (IS_STAGING_ENV) {
7728
+ process.env.BASE_URL = (_a = getGlobalUserState()) === null || _a === void 0 ? void 0 : _a.baseUrl;
7729
+ }
7730
+ return;
7731
+ }
7694
7732
  const stagingData = generateStagingData(product);
7695
- const newUserState = mergeLeft(user, stagingData);
7696
- writeDataToFile(JSON.stringify({ user: newUserState }, null, 2));
7733
+ writeDataToFile(JSON.stringify({ user: stagingData }, null, 2));
7697
7734
  if (IS_STAGING_ENV) {
7698
- const baseUrl = `https://${newUserState.subdomainName}.${stagingData.domain}`;
7735
+ const baseUrl = `https://${stagingData.subdomainName}.${stagingData.domain}`;
7699
7736
  process.env.BASE_URL = baseUrl;
7700
7737
  }
7701
7738
  };
7702
7739
 
7703
7740
  const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/", }) => {
7741
+ if (shouldSkipSetupAndTeardown())
7742
+ return;
7704
7743
  await page.goto(loginPath);
7705
7744
  await page.getByTestId("login-email-text-field").fill(CREDENTIALS.email);
7706
7745
  await page
@@ -7715,6 +7754,7 @@ const loginWithoutSSO = async ({ page, neetoPlaywrightUtilities, loginPath = "/"
7715
7754
  await page.context().storageState({ path: STORAGE_STATE });
7716
7755
  const mergedCredentials = mergeAll([readFileSyncIfExists(), userCredentials]);
7717
7756
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
7757
+ updateCredentials({ key: "isLoggedIn", value: "true" });
7718
7758
  };
7719
7759
  const login = async ({ page, neetoPlaywrightUtilities, loginPath, }) => !IS_STAGING_ENV &&
7720
7760
  (await loginWithoutSSO({ page, neetoPlaywrightUtilities, loginPath }));
@@ -8301,5 +8341,5 @@ const definePlaywrightConfig = (overrides) => {
8301
8341
  });
8302
8342
  };
8303
8343
 
8304
- export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, skipTest, updateCredentials, writeDataToFile };
8344
+ export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, IS_STAGING_ENV, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, STORAGE_STATE, TAGS_SELECTORS, USER_AGENTS, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, updateCredentials, writeDataToFile };
8305
8345
  //# sourceMappingURL=index.js.map