@bigbinary/neeto-playwright-commons 1.26.13 → 1.26.14

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
@@ -306,14 +306,18 @@ const ENVIRONMENT = {
306
306
  review: "review",
307
307
  };
308
308
  const EXAMPLE_URL = "https://example.com";
309
- const IS_STAGING_ENV = process.env.TEST_ENV === "staging";
309
+ const IS_STAGING_ENV = process.env.TEST_ENV === ENVIRONMENT.staging;
310
+ const IS_DEV_ENV = process.env.TEST_ENV === ENVIRONMENT.development;
310
311
  const STORAGE_STATE = "./e2e/auth/user.json";
311
312
  const GLOBAL_TRANSLATIONS_PATTERN = "../node_modules/@bigbinary/**/translations/en.json";
312
313
  const PROJECT_TRANSLATIONS_PATH = "../app/javascript/src/translations/en.json";
313
314
  const CREDENTIALS = {
315
+ firstName: "Oliver",
316
+ lastName: "Smith",
314
317
  name: "Oliver Smith",
315
318
  email: "oliver@example.com",
316
319
  password: "welcome",
320
+ subdomainName: "spinkart",
317
321
  };
318
322
  const OTP_EMAIL_PATTERN = "is your login code";
319
323
  const SLACK_DEFAULT_CHANNEL = "general";
@@ -4850,23 +4854,26 @@ const generateStagingData = (product = "invoice") => {
4850
4854
  const timestamp = jobCompletionIndex
4851
4855
  ? `${dateTimeString}-${jobCompletionIndex}`
4852
4856
  : dateTimeString;
4853
- const firstName = "André";
4854
- const lastName = "O'Reilly";
4857
+ const firstName = IS_STAGING_ENV ? "André" : CREDENTIALS.firstName;
4858
+ const lastName = IS_STAGING_ENV ? "O'Reilly" : CREDENTIALS.lastName;
4855
4859
  const otpBypassKey = process.env.OTP_BYPASS_KEY;
4856
- const stagingOrganization = `cpt-${product}-${timestamp}`;
4860
+ const isGlobalSetup = !getGlobalUserState(); // For dev global setup staging data, we use the default subdomain `spinkart`.
4861
+ const shouldKeepDefaultDataForDevEnv = isGlobalSetup && IS_DEV_ENV;
4862
+ const stagingOrganization = shouldKeepDefaultDataForDevEnv
4863
+ ? CREDENTIALS.subdomainName
4864
+ : `cpt-${product}-${timestamp}`;
4865
+ const email = shouldKeepDefaultDataForDevEnv
4866
+ ? CREDENTIALS.email
4867
+ : `cpt${otpBypassKey}+${product}+${timestamp}@bigbinary.com`;
4857
4868
  return {
4858
4869
  firstName,
4859
4870
  lastName,
4860
4871
  otp: 111111,
4861
- domain: `neeto${product}.net`,
4862
- currentUserName: IS_STAGING_ENV
4863
- ? joinString(firstName, lastName)
4864
- : CREDENTIALS.name,
4872
+ domain: IS_STAGING_ENV ? `neeto${product}.net` : `lvh.me`,
4873
+ currentUserName: joinString(firstName, lastName),
4865
4874
  businessName: stagingOrganization,
4866
- subdomainName: IS_STAGING_ENV ? stagingOrganization : "spinkart",
4867
- email: IS_STAGING_ENV
4868
- ? `cpt${otpBypassKey}+${product}+${timestamp}@bigbinary.com`
4869
- : CREDENTIALS.email,
4875
+ subdomainName: stagingOrganization,
4876
+ email,
4870
4877
  };
4871
4878
  };
4872
4879
 
@@ -4907,7 +4914,7 @@ const removeCredentialFile = () => {
4907
4914
  require$$0__namespace.unlink(STORAGE_STATE, error => {
4908
4915
  if (!error)
4909
4916
  return;
4910
- console.error(error);
4917
+ console.log(error);
4911
4918
  });
4912
4919
  };
4913
4920
  const clearCredentials = () => {
@@ -4956,7 +4963,12 @@ const shouldSkipSetupAndTeardown = () => { var _a; return ((_a = getGlobalUserSt
4956
4963
  const shouldSkipCustomDomainSetup = () => process.env.SETUP_CUSTOM_DOMAIN !== "true" || !IS_STAGING_ENV;
4957
4964
  const baseURLGenerator = (product, customSubdomain) => {
4958
4965
  const { subdomainName } = getGlobalUserState();
4959
- return `https://${customSubdomain !== null && customSubdomain !== void 0 ? customSubdomain : subdomainName}.neeto${product.toLowerCase()}.net`;
4966
+ const subdomain = customSubdomain !== null && customSubdomain !== void 0 ? customSubdomain : subdomainName;
4967
+ const railsPort = process.env.RAILS_SERVER_PORT;
4968
+ const baseURL = IS_DEV_ENV
4969
+ ? `http://${subdomain}.lvh.me:${railsPort}`
4970
+ : `https://${subdomain}.neeto${product.toLowerCase()}.net`;
4971
+ return baseURL;
4960
4972
  };
4961
4973
  // trims and replaces multiple whitespace characters in a string with a single space
4962
4974
  const squish = (text) => text.trim().replace(/\s+/g, " ");
@@ -5036,7 +5048,7 @@ const globalShortcuts = (t) => [
5036
5048
  const generatePhoneNumber = () => `${"+91"} 9${faker.faker.string.numeric(4)} ${faker.faker.string.numeric(5)}`;
5037
5049
  const initializeTestData = (product) => {
5038
5050
  const credentials = generateStagingData(product.toLowerCase());
5039
- const baseURL = `https://${credentials.subdomainName}.${credentials.domain}`;
5051
+ const baseURL = baseURLGenerator(product, credentials.subdomainName);
5040
5052
  return { credentials, baseURL };
5041
5053
  };
5042
5054
 
@@ -116672,7 +116684,7 @@ class MicrosoftPage extends IntegrationBase {
116672
116684
  const acceptBtn = this.page.locator(MICROSOFT_LOGIN_SELECTORS.acceptButton);
116673
116685
  await acceptBtn.click();
116674
116686
  await test.expect(acceptBtn).toBeHidden({ timeout: 10000 });
116675
- await this.page.waitForLoadState("load", { timeout: 25000 });
116687
+ await this.page.waitForLoadState("load", { timeout: 50000 });
116676
116688
  };
116677
116689
  this.revokePermissions = async () => {
116678
116690
  await this.page.goto(THIRD_PARTY_ROUTES.microsoft.myApps);
@@ -118499,30 +118511,30 @@ class TeamMembers {
118499
118511
  }
118500
118512
  }
118501
118513
 
118502
- const loginWithoutSSO = async ({ page,
118503
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
118504
- neetoPlaywrightUtilities, loginPath = "/", }) => {
118505
- if (shouldSkipSetupAndTeardown())
118506
- return;
118507
- await page.goto(loginPath, { timeout: 20000 });
118514
+ const fillCredentialsAndSubmit = async ({ page, loginPath = "/", email = CREDENTIALS.email, }) => {
118515
+ await page.goto(loginPath, { timeout: 30000 });
118508
118516
  await page.waitForLoadState("load", { timeout: 35000 });
118509
- await page
118510
- .getByTestId(LOGIN_SELECTORS.emailTextField)
118511
- .fill(CREDENTIALS.email);
118517
+ await page.getByTestId(LOGIN_SELECTORS.emailTextField).fill(email);
118512
118518
  await page
118513
118519
  .getByTestId(LOGIN_SELECTORS.passwordTextField)
118514
118520
  .fill(CREDENTIALS.password);
118515
118521
  const submitButton = page.getByTestId(LOGIN_SELECTORS.submitButton);
118516
118522
  await submitButton.click();
118517
118523
  await test.expect(submitButton).toBeHidden({ timeout: 15000 });
118524
+ await test.expect(page.getByTestId(COMMON_SELECTORS.floatingActionMenuButton)).toBeVisible({ timeout: 60000 });
118525
+ };
118526
+ const loginWithoutSSO = async ({ page, loginPath = "/", email = CREDENTIALS.email, }) => {
118527
+ if (shouldSkipSetupAndTeardown())
118528
+ return;
118529
+ await fillCredentialsAndSubmit({ page, loginPath, email });
118518
118530
  const userCredentials = readFileSyncIfExists();
118519
118531
  await page.context().storageState({ path: STORAGE_STATE });
118520
118532
  const mergedCredentials = ramda.mergeAll([readFileSyncIfExists(), userCredentials]);
118521
118533
  writeDataToFile(JSON.stringify(mergedCredentials, null, 2));
118522
118534
  updateCredentials({ key: "isLoggedIn", value: "true" });
118523
118535
  };
118524
- const login = async ({ page, neetoPlaywrightUtilities, loginPath, }) => !IS_STAGING_ENV &&
118525
- (await loginWithoutSSO({ page, neetoPlaywrightUtilities, loginPath }));
118536
+ const login = async ({ page, neetoPlaywrightUtilities, loginPath, email, }) => IS_DEV_ENV &&
118537
+ (await loginWithoutSSO({ page, loginPath, email }));
118526
118538
  const generateRandomBypassEmail = () => `cpt${process.env.OTP_BYPASS_KEY}+${faker.faker.number.int()}@bigbinary.com`;
118527
118539
 
118528
118540
  const extractSubdomainFromError = (errorString) => {
@@ -118530,13 +118542,43 @@ const extractSubdomainFromError = (errorString) => {
118530
118542
  const matches = errorString.match(regex);
118531
118543
  return matches[1];
118532
118544
  };
118545
+ const createOrganizationViaRake = async ({ email, firstName, lastName, subdomainName, }) => {
118546
+ var _a, _b;
118547
+ const workingDirectory = process.env.RAILS_ROOT || "..";
118548
+ const rakeTaskName = "playwright:create_organization";
118549
+ const childProcess = child_process.spawn("bundle", [
118550
+ "exec",
118551
+ "rake",
118552
+ rakeTaskName,
118553
+ "--",
118554
+ `--first_name=${firstName}`,
118555
+ `--last_name=${lastName}`,
118556
+ `--email=${email}`,
118557
+ `--subdomain=${subdomainName}`,
118558
+ ], {
118559
+ cwd: workingDirectory,
118560
+ stdio: ["ignore", "pipe", "pipe"],
118561
+ });
118562
+ let stdout = "";
118563
+ let stderr = "";
118564
+ (_a = childProcess.stdout) === null || _a === void 0 ? void 0 : _a.on("data", data => {
118565
+ stdout += data.toString("utf-8");
118566
+ });
118567
+ (_b = childProcess.stderr) === null || _b === void 0 ? void 0 : _b.on("data", data => {
118568
+ stderr += data.toString("utf-8");
118569
+ });
118570
+ const exitCode = await new Promise((resolve, reject) => {
118571
+ childProcess.on("error", reject);
118572
+ childProcess.on("close", resolve);
118573
+ });
118574
+ if (exitCode !== 0) {
118575
+ throw new Error(`Failed to create organization: ${stderr || stdout || `Exit code ${exitCode}`}`);
118576
+ }
118577
+ return stdout.trim();
118578
+ };
118533
118579
 
118534
118580
  class OrganizationPage {
118535
118581
  constructor(page, neetoPlaywrightUtilities) {
118536
- this.baseUrlGenerator = (appName) => {
118537
- const { subdomainName } = getGlobalUserState();
118538
- return `https://${subdomainName}.${appName}.net`;
118539
- };
118540
118582
  this.fillOTP = async (otp = faker.faker.string.numeric(6)) => {
118541
118583
  await this.neetoPlaywrightUtilities.waitForPageLoad();
118542
118584
  const otpTextBox = this.page.getByTestId(SIGNUP_SELECTORS.otpTextBox);
@@ -118551,8 +118593,17 @@ class OrganizationPage {
118551
118593
  await test.expect(submitButton).toBeHidden({ timeout: 35000 });
118552
118594
  };
118553
118595
  this.createOrganization = async ({ email, businessName, subdomainName, firstName, lastName, appName, }) => {
118554
- if (!IS_STAGING_ENV || shouldSkipSetupAndTeardown())
118596
+ if (shouldSkipSetupAndTeardown())
118597
+ return;
118598
+ if (IS_DEV_ENV) {
118599
+ await createOrganizationViaRake({
118600
+ email,
118601
+ firstName,
118602
+ lastName,
118603
+ subdomainName,
118604
+ });
118555
118605
  return;
118606
+ }
118556
118607
  const appNameInLowerCase = appName.toLowerCase();
118557
118608
  const isNeetoAuth = appNameInLowerCase === "neetoauth";
118558
118609
  isNeetoAuth
@@ -118588,7 +118639,9 @@ class OrganizationPage {
118588
118639
  subdomainName: user.subdomainName,
118589
118640
  appName: `neeto${product}`,
118590
118641
  });
118591
- await test.expect(this.page.locator(COMMON_SELECTORS.spinner)).toBeHidden();
118642
+ await this.neetoPlaywrightUtilities.waitForPageLoad({
118643
+ customPageContext: this.page,
118644
+ });
118592
118645
  const userCredentials = readFileSyncIfExists();
118593
118646
  await this.page.context().storageState({ path: STORAGE_STATE });
118594
118647
  const mergedCredentials = ramda.mergeAll([
@@ -118599,7 +118652,7 @@ class OrganizationPage {
118599
118652
  updateCredentials({ key: "isLoggedIn", value: "true" });
118600
118653
  updateCredentials({
118601
118654
  key: "baseUrl",
118602
- value: this.baseUrlGenerator(`neeto${product}`),
118655
+ value: baseURLGenerator(product),
118603
118656
  });
118604
118657
  };
118605
118658
  this.updateSubdomainIfExists = async (appName) => {
@@ -118621,7 +118674,7 @@ class OrganizationPage {
118621
118674
  key: "businessName",
118622
118675
  value: newOrganizationName,
118623
118676
  });
118624
- process.env.BASE_URL = this.baseUrlGenerator(appName);
118677
+ process.env.BASE_URL = baseURLGenerator(appName);
118625
118678
  await this.page
118626
118679
  .getByTestId(SIGNUP_SELECTORS.organizationNameTextField)
118627
118680
  .fill(newOrganizationName);
@@ -118652,6 +118705,8 @@ class OrganizationPage {
118652
118705
  await this.fillOTP(otp);
118653
118706
  };
118654
118707
  this.setupProfile = async ({ firstName = faker.faker.person.firstName(), lastName = faker.faker.person.lastName(), country, } = {}) => {
118708
+ if (IS_DEV_ENV)
118709
+ return;
118655
118710
  await this.neetoPlaywrightUtilities.waitForPageLoad();
118656
118711
  await this.page
118657
118712
  .getByTestId(SIGNUP_SELECTORS.firstNameTextField)
@@ -118669,36 +118724,62 @@ class OrganizationPage {
118669
118724
  });
118670
118725
  };
118671
118726
  this.loginAndOnboard = async ({ email, firstName, lastName, country, handleOnboarding, baseURL = process.env.BASE_URL, fetchOtpFromEmail, }) => {
118672
- await this.page.goto(`${baseURL}${ROUTES.admin}`, { timeout: 20000 });
118673
- fetchOtpFromEmail === undefined
118674
- ? await this.loginViaSSO(email)
118675
- : await this.loginWithFastmailEmail({ email, fetchOtpFromEmail });
118676
- await this.setupProfile({ firstName, lastName, country });
118677
- await this.page.waitForURL(new RegExp(getGlobalUserState().domain), {
118678
- waitUntil: "load",
118679
- });
118727
+ if (IS_DEV_ENV) {
118728
+ await fillCredentialsAndSubmit({
118729
+ page: this.page,
118730
+ email,
118731
+ loginPath: `${baseURL}${ROUTES.admin}`,
118732
+ });
118733
+ }
118734
+ else {
118735
+ await this.page.goto(`${baseURL}${ROUTES.admin}`, { timeout: 20000 });
118736
+ fetchOtpFromEmail === undefined
118737
+ ? await this.loginViaSSO(email)
118738
+ : await this.loginWithFastmailEmail({ email, fetchOtpFromEmail });
118739
+ await this.setupProfile({ firstName, lastName, country });
118740
+ await this.page.waitForURL(new RegExp(getGlobalUserState().domain), {
118741
+ waitUntil: "load",
118742
+ });
118743
+ }
118680
118744
  await handleOnboarding();
118681
118745
  };
118682
118746
  this.signUp = async ({ credentials, fetchOtpFromEmail, appName, }) => {
118683
- let otp = "123456";
118684
- await this.page.goto(`${ROUTES.neetoAuthSignup}?redirect_uri=${credentials.domain}`, { timeout: 20000 });
118685
- await this.submitEmail(credentials.email);
118686
- if (fetchOtpFromEmail !== undefined) {
118687
- otp = await fetchOtpFromEmail({
118747
+ if (IS_DEV_ENV) {
118748
+ await createOrganizationViaRake({
118688
118749
  email: credentials.email,
118689
- timeout: 4 * 60 * 1000,
118750
+ firstName: credentials.firstName,
118751
+ lastName: credentials.lastName,
118752
+ subdomainName: credentials.subdomainName,
118753
+ });
118754
+ await fillCredentialsAndSubmit({
118755
+ page: this.page,
118756
+ email: credentials.email,
118757
+ loginPath: `${baseURLGenerator(appName, credentials.subdomainName)}${ROUTES.admin}`,
118690
118758
  });
118691
118759
  }
118692
- await this.fillOTP(otp);
118693
- await this.fillOrganizationDetails({
118694
- credentials,
118695
- appName,
118696
- });
118697
- await this.page.waitForURL(new RegExp(credentials.domain));
118760
+ else {
118761
+ let otp = "123456";
118762
+ await this.page.goto(`${ROUTES.neetoAuthSignup}?redirect_uri=${credentials.domain}`, { timeout: 20000 });
118763
+ await this.submitEmail(credentials.email);
118764
+ if (fetchOtpFromEmail !== undefined) {
118765
+ otp = await fetchOtpFromEmail({
118766
+ email: credentials.email,
118767
+ timeout: 4 * 60 * 1000,
118768
+ });
118769
+ }
118770
+ await this.fillOTP(otp);
118771
+ await this.fillOrganizationDetails({
118772
+ credentials,
118773
+ appName,
118774
+ });
118775
+ await this.page.waitForURL(new RegExp(credentials.domain));
118776
+ }
118698
118777
  const STORAGE_STATE = await this.page.context().storageState();
118699
118778
  return { STORAGE_STATE, baseURL: process.env.BASE_URL };
118700
118779
  };
118701
118780
  this.fillOrganizationDetails = async ({ credentials, appName, }) => {
118781
+ if (IS_DEV_ENV)
118782
+ return;
118702
118783
  const subdomainError = this.page.getByTestId(SIGNUP_SELECTORS.subdomainError);
118703
118784
  const organizationSubmitButton = this.page.getByTestId(SIGNUP_SELECTORS.organizationSubmitButton);
118704
118785
  await this.neetoPlaywrightUtilities.waitForPageLoad();
@@ -119677,10 +119758,7 @@ const initializeCredentials = (product) => {
119677
119758
  }
119678
119759
  const stagingData = generateStagingData(product);
119679
119760
  writeDataToFile(JSON.stringify({ user: stagingData }, null, 2));
119680
- if (IS_STAGING_ENV) {
119681
- const baseUrl = `https://${stagingData.subdomainName}.${stagingData.domain}`;
119682
- process.env.BASE_URL = baseUrl;
119683
- }
119761
+ process.env.BASE_URL = baseURLGenerator(product, stagingData.subdomainName);
119684
119762
  };
119685
119763
 
119686
119764
  const assertColumnHeaderVisibility = async ({ page, columnName, shouldBeVisible, }) => {
@@ -124623,7 +124701,6 @@ const playdashLighthouseConfig = {
124623
124701
  tags: process.env.TAG,
124624
124702
  };
124625
124703
  const isCI = neetoCist.isPresent(process.env.NEETO_CI_JOB_ID);
124626
- const isDevEnv = process.env.TEST_ENV === ENVIRONMENT.development;
124627
124704
  const railsPort = process.env.RAILS_SERVER_PORT;
124628
124705
  const vitePort = process.env.VITE_PORT;
124629
124706
  const definePlaywrightConfig = (overrides) => {
@@ -124666,7 +124743,7 @@ const definePlaywrightConfig = (overrides) => {
124666
124743
  timeout: 5 * 60 * 1000,
124667
124744
  workers: isCI ? 6 : 5,
124668
124745
  reporter: isCI ? reporter : [["line"]],
124669
- ...(isDevEnv && {
124746
+ ...(IS_DEV_ENV && {
124670
124747
  webServer: [
124671
124748
  {
124672
124749
  command: `bundle exec puma -b tcp://0.0.0.0:${railsPort} -C config/puma.rb`,
@@ -124785,6 +124862,7 @@ exports.INTEGRATIONS_TEXTS = INTEGRATIONS_TEXTS;
124785
124862
  exports.INTEGRATION_SELECTORS = INTEGRATION_SELECTORS;
124786
124863
  exports.IPRestrictionsPage = IPRestrictionsPage;
124787
124864
  exports.IP_RESTRICTIONS_SELECTORS = IP_RESTRICTIONS_SELECTORS;
124865
+ exports.IS_DEV_ENV = IS_DEV_ENV;
124788
124866
  exports.IS_STAGING_ENV = IS_STAGING_ENV;
124789
124867
  exports.ImageUploader = ImageUploader;
124790
124868
  exports.IntegrationBase = IntegrationBase;
@@ -124870,12 +124948,14 @@ exports.basicHTMLContent = basicHTMLContent;
124870
124948
  exports.clearCredentials = clearCredentials;
124871
124949
  exports.commands = commands;
124872
124950
  exports.cpuThrottlingUsingCDP = cpuThrottlingUsingCDP;
124951
+ exports.createOrganizationViaRake = createOrganizationViaRake;
124873
124952
  exports.currencyUtils = currencyUtils;
124874
124953
  exports.dataQa = dataQa;
124875
124954
  exports.decodeQRCodeFromFile = decodeQRCodeFromFile;
124876
124955
  exports.definePlaywrightConfig = definePlaywrightConfig;
124877
124956
  exports.executeWithThrottledResources = executeWithThrottledResources;
124878
124957
  exports.extractSubdomainFromError = extractSubdomainFromError;
124958
+ exports.fillCredentialsAndSubmit = fillCredentialsAndSubmit;
124879
124959
  exports.filterUtils = filterUtils;
124880
124960
  exports.generatePhoneNumber = generatePhoneNumber;
124881
124961
  exports.generatePhoneNumberDetails = generatePhoneNumberDetails;