@bigbinary/neeto-playwright-commons 1.16.7 → 1.17.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
@@ -135,6 +135,11 @@ const ZAPIER_TEST_EMAIL = (product) => `neeto-${product}-zapier-test@${process.e
135
135
  // constants for translation
136
136
  const SINGULAR = { count: 1 };
137
137
  const PLURAL = { count: 2 };
138
+ const COLOR = {
139
+ transparent: "rgba(0, 0, 0, 0)",
140
+ softBlue: "rgb(230, 244, 255)",
141
+ };
142
+ const DATE_TEXTS = { now: "Now", nextYear: "next-year" };
138
143
 
139
144
  /* eslint-disable playwright/no-skipped-test */
140
145
  const execCommand = (command) => child_process.execSync(command)
@@ -25297,6 +25302,69 @@ class OrganizationPage {
25297
25302
  }
25298
25303
  }
25299
25304
 
25305
+ const ADMIN_PANEL_SELECTORS = {
25306
+ settingsItemHeading: "settings-item-heading",
25307
+ settingsItemDescription: "settings-item-description",
25308
+ expiryDateInput: "expiry-date-input",
25309
+ };
25310
+
25311
+ class ApiKeysPage {
25312
+ constructor(page, neetoPlaywrightUtilities) {
25313
+ this.fillApiKeyDetails = async ({ label, expiryDate }) => {
25314
+ await this.page
25315
+ .getByTestId(COMMON_SELECTORS.paneBody)
25316
+ .getByTestId(COMMON_SELECTORS.customInputField("label"))
25317
+ .fill(label);
25318
+ if (expiryDate) {
25319
+ await this.page
25320
+ .getByTestId(COMMON_SELECTORS.checkboxInput("never-expires"))
25321
+ .uncheck();
25322
+ await this.page
25323
+ .getByTestId(COMMON_SELECTORS.paneBody)
25324
+ .getByTestId(ADMIN_PANEL_SELECTORS.expiryDateInput)
25325
+ .click();
25326
+ //TODO: Use data-cy labels when this https://github.com/bigbinary/neeto-kb-playwright/issues/47 is resolved
25327
+ await this.page.getByLabel(DATE_TEXTS.nextYear, { exact: true }).click();
25328
+ await this.page.getByText(expiryDate, { exact: true }).click();
25329
+ }
25330
+ await this.page.getByTestId(COMMON_SELECTORS.saveChangesButton).click();
25331
+ await this.neetoPlaywrightUtilities.verifyToast();
25332
+ };
25333
+ this.verifyApiKey = ({ targetRow, label, date, }) => Promise.all([
25334
+ test$1.expect(targetRow.getByRole("cell", { name: label })).toBeVisible(),
25335
+ test$1.expect(targetRow.getByTestId(TAGS_SELECTORS.tagContainer)).toHaveText(this.t("common.active")),
25336
+ test$1.expect(targetRow.getByRole("cell", { name: date })).toBeVisible(),
25337
+ test$1.expect(targetRow.getByRole("cell", {
25338
+ name: this.t("neetoApiKeys.common.never"),
25339
+ })).toBeVisible(),
25340
+ ]);
25341
+ this.editApiKey = async ({ label, expiryDate }) => {
25342
+ //TODO: Use data-cy labels when this https://github.com/bigbinary/neeto-kb-playwright/issues/46 is resolved
25343
+ await this.page
25344
+ .getByTestId(COMMON_SELECTORS.dropdownContainer)
25345
+ .getByRole("button", { name: this.t("common.edit") })
25346
+ .click();
25347
+ await this.fillApiKeyDetails({ label, expiryDate });
25348
+ };
25349
+ this.deleteApiKey = async (targetRow) => {
25350
+ await targetRow.getByTestId(COMMON_SELECTORS.dropdownIcon).click();
25351
+ //TODO: Use data-cy labels when this https://github.com/bigbinary/neeto-kb-playwright/issues/46 is resolved
25352
+ await this.page
25353
+ .getByTestId(COMMON_SELECTORS.dropdownContainer)
25354
+ .getByRole("button", { name: this.t("common.delete") })
25355
+ .click();
25356
+ await this.page
25357
+ .getByTestId(COMMON_SELECTORS.alertModalSubmitButton)
25358
+ .click();
25359
+ await this.neetoPlaywrightUtilities.verifyToast();
25360
+ await test$1.expect(targetRow).toBeHidden();
25361
+ };
25362
+ this.page = page;
25363
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
25364
+ this.t = playwrightI18nextFixture.getI18nInstance().t;
25365
+ }
25366
+ }
25367
+
25300
25368
  class AuditLogsPage {
25301
25369
  constructor(page, neetoPlaywrightUtilities) {
25302
25370
  this.verifyAuditLog = async ({ targetRow, action, date, adminName, }) => {
@@ -25336,6 +25404,141 @@ class AuditLogsPage {
25336
25404
  }
25337
25405
  }
25338
25406
 
25407
+ class RoleApis {
25408
+ constructor(neetoPlaywrightUtilities) {
25409
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
25410
+ this.BASE_URL = "/team_members";
25411
+ this.ORGANIZATION_ROLES_URL = `${this.BASE_URL}/organization_roles`;
25412
+ this.fetch = (endpoint) => this.neetoPlaywrightUtilities.apiRequest({
25413
+ url: `${this.BASE_URL}/${endpoint}`,
25414
+ });
25415
+ this.addRole = (roleName, permissionIds) => this.neetoPlaywrightUtilities.apiRequest({
25416
+ url: this.ORGANIZATION_ROLES_URL,
25417
+ method: "post",
25418
+ data: {
25419
+ organization_role: {
25420
+ name: roleName,
25421
+ permission_ids: permissionIds,
25422
+ },
25423
+ },
25424
+ });
25425
+ this.editRole = (roleId, body) => this.neetoPlaywrightUtilities.apiRequest({
25426
+ url: `${this.ORGANIZATION_ROLES_URL}/${roleId}`,
25427
+ method: "patch",
25428
+ body: { organization_role: body },
25429
+ });
25430
+ this.deleteRole = (roleId, standardRoleId) => this.neetoPlaywrightUtilities.apiRequest({
25431
+ url: `${this.ORGANIZATION_ROLES_URL}/${roleId}`,
25432
+ method: "delete",
25433
+ body: { new_role_id: standardRoleId },
25434
+ });
25435
+ }
25436
+ }
25437
+
25438
+ class RolesPage {
25439
+ constructor(page, neetoPlaywrightUtilities) {
25440
+ this.getPermissionIds = async (targetPermissions) => {
25441
+ const { permissions } = await this.roleApis
25442
+ .fetch("permissions")
25443
+ .then(response => response === null || response === void 0 ? void 0 : response.json());
25444
+ const permissionObjects = targetPermissions.map(permission => neetoCist.findBy({ category: permission }, permissions));
25445
+ return ramda.pluck("id", permissionObjects);
25446
+ };
25447
+ this.getRoleIdAndOrganizationId = async (roleName) => {
25448
+ const roles = await this.roleApis
25449
+ .fetch("organization_roles")
25450
+ .then(response => response === null || response === void 0 ? void 0 : response.json());
25451
+ const { id: roleId, organization_id: organizationId } = neetoCist.findBy({ name: roleName }, roles.organization_roles);
25452
+ return { roleId, organizationId };
25453
+ };
25454
+ this.addCustomRoleViaRequest = async (roleName, targetPermissions) => {
25455
+ const permissionIds = await this.getPermissionIds(targetPermissions);
25456
+ return this.roleApis.addRole(roleName, permissionIds);
25457
+ };
25458
+ this.editRoleViaRequest = async (roleName, targetPermissions) => {
25459
+ const [permissionIds, { roleId, organizationId }] = await Promise.all([
25460
+ this.getPermissionIds(targetPermissions),
25461
+ this.getRoleIdAndOrganizationId(roleName),
25462
+ ]);
25463
+ return this.roleApis.editRole(roleId, {
25464
+ id: roleId,
25465
+ kind: "custom",
25466
+ name: roleName,
25467
+ organization_id: organizationId,
25468
+ permission_ids: permissionIds,
25469
+ });
25470
+ };
25471
+ this.deleteRoleViaRequest = async (roleName) => {
25472
+ const [{ roleId }, { roleId: editorRoleId }] = await Promise.all([roleName, "Editor"].map(this.getRoleIdAndOrganizationId));
25473
+ return this.roleApis.deleteRole(roleId, editorRoleId);
25474
+ };
25475
+ this.addRoleViaUI = async ({ roleName, permissions }) => {
25476
+ await this.page.getByTestId(ROLES_SELECTORS.newButton).click();
25477
+ await this.page.getByTestId(ROLES_SELECTORS.nameTextField).fill(roleName);
25478
+ await this.selectAndSubmitPermissions(permissions);
25479
+ };
25480
+ this.editRoleViaUI = async ({ roleName, permissions }) => {
25481
+ await this.page
25482
+ .getByTestId(ROLES_SELECTORS.tableHeaderRoleName)
25483
+ .filter({ hasText: roleName })
25484
+ .getByTestId(ROLES_SELECTORS.dropDownIcon)
25485
+ .click();
25486
+ await this.page.getByTestId(ROLES_SELECTORS.editRoleButton).click();
25487
+ await this.selectAndSubmitPermissions(permissions);
25488
+ };
25489
+ this.selectAndSubmitPermissions = async (permissions) => {
25490
+ for (const permission of permissions) {
25491
+ await this.page
25492
+ .getByTestId(MEMBER_SELECTORS.checkboxLabel(permission))
25493
+ .check();
25494
+ }
25495
+ await this.page.getByTestId(ROLES_SELECTORS.proceedButton).click();
25496
+ await this.neetoPlaywrightUtilities.verifyToast();
25497
+ };
25498
+ this.verifyAdminPanelCard = ({ cardLocator, title, description, }) => Promise.all([
25499
+ test$1.expect(cardLocator.getByTestId(ADMIN_PANEL_SELECTORS.settingsItemHeading)).toHaveText(title),
25500
+ test$1.expect(cardLocator.getByTestId(ADMIN_PANEL_SELECTORS.settingsItemDescription)).toHaveText(description),
25501
+ test$1.expect(this.page.getByTestId(COMMON_SELECTORS.sidebarSubLink(title))).toHaveCSS("background-color", COLOR.transparent),
25502
+ ]);
25503
+ this.deleteRoleViaUI = async (roleName) => {
25504
+ await this.page
25505
+ .getByTestId(ROLES_SELECTORS.tableHeaderRoleName)
25506
+ .filter({ hasText: roleName })
25507
+ .getByTestId(ROLES_SELECTORS.dropDownIcon)
25508
+ .click();
25509
+ await this.page.getByTestId(ROLES_SELECTORS.deleteRoleButton).click();
25510
+ await this.page
25511
+ .getByTestId(COMMON_SELECTORS.alertModalSubmitButton)
25512
+ .click();
25513
+ await this.neetoPlaywrightUtilities.verifyToast();
25514
+ };
25515
+ this.verifyPermissions = ({ allPermissions, rolePermissions, }) => Promise.all(Object.values(allPermissions).map(async (permission) => rolePermissions.includes(permission)
25516
+ ? await test$1.expect(this.page.getByTestId(permission)).toBeVisible()
25517
+ : await test$1.expect(this.page.getByTestId(permission)).toBeHidden()));
25518
+ this.verifyRoleSpecificLinkAccess = async ({ roleAccessableLinks = [], adminAccessableLinks = [], }) => {
25519
+ if (neetoCist.isNotEqualDeep(roleAccessableLinks, adminAccessableLinks)) {
25520
+ for (const link of adminAccessableLinks) {
25521
+ await this.page.goto(link);
25522
+ await this.neetoPlaywrightUtilities.waitForPageLoad();
25523
+ await test$1.expect(this.page.locator(COMMON_SELECTORS.tableSpinner)).toBeHidden({
25524
+ timeout: 15000,
25525
+ });
25526
+ const unauthorizedHeading = this.page.getByRole("heading", {
25527
+ name: this.t("neetoMolecules.errorPage.unauthorized"),
25528
+ });
25529
+ roleAccessableLinks.includes(link)
25530
+ ? await test$1.expect(unauthorizedHeading).toBeHidden()
25531
+ : await test$1.expect(unauthorizedHeading).toBeVisible();
25532
+ }
25533
+ }
25534
+ };
25535
+ this.page = page;
25536
+ this.neetoPlaywrightUtilities = neetoPlaywrightUtilities;
25537
+ this.roleApis = new RoleApis(neetoPlaywrightUtilities);
25538
+ this.t = playwrightI18nextFixture.getI18nInstance().t;
25539
+ }
25540
+ }
25541
+
25339
25542
  class SidebarSection {
25340
25543
  constructor(page, neetoPlaywrightUtilities) {
25341
25544
  this.clickOnSubLink = (label) => this.page.getByTestId(COMMON_SELECTORS.sidebarSubLink(label)).click();
@@ -158655,15 +158858,18 @@ const definePlaywrightConfig = (overrides) => {
158655
158858
 
158656
158859
  exports.API_ROUTES = API_ROUTES;
158657
158860
  exports.AUDIT_LOGS_TEXTS = AUDIT_LOGS_TEXTS;
158861
+ exports.ApiKeysPage = ApiKeysPage;
158658
158862
  exports.AuditLogsPage = AuditLogsPage;
158659
158863
  exports.BASE_URL = BASE_URL;
158660
158864
  exports.CHANGELOG_WIDGET_SELECTORS = CHANGELOG_WIDGET_SELECTORS;
158661
158865
  exports.CHAT_WIDGET_SELECTORS = CHAT_WIDGET_SELECTORS;
158662
158866
  exports.CHAT_WIDGET_TEXTS = CHAT_WIDGET_TEXTS;
158867
+ exports.COLOR = COLOR;
158663
158868
  exports.COMMON_SELECTORS = COMMON_SELECTORS;
158664
158869
  exports.COMMON_TEXTS = COMMON_TEXTS;
158665
158870
  exports.CREDENTIALS = CREDENTIALS;
158666
158871
  exports.CustomCommands = CustomCommands;
158872
+ exports.DATE_TEXTS = DATE_TEXTS;
158667
158873
  exports.DESCRIPTION_EDITOR_TEXTS = DESCRIPTION_EDITOR_TEXTS;
158668
158874
  exports.EMBED_SELECTORS = EMBED_SELECTORS;
158669
158875
  exports.EMOJI_LABEL = EMOJI_LABEL;
@@ -158708,6 +158914,7 @@ exports.PROFILE_SECTION_SELECTORS = PROFILE_SECTION_SELECTORS;
158708
158914
  exports.PROJECT_TRANSLATIONS_PATH = PROJECT_TRANSLATIONS_PATH;
158709
158915
  exports.ROLES_SELECTORS = ROLES_SELECTORS;
158710
158916
  exports.ROUTES = ROUTES;
158917
+ exports.RolesPage = RolesPage;
158711
158918
  exports.SELECT_COUNTRY = SELECT_COUNTRY;
158712
158919
  exports.SIGNUP_SELECTORS = SIGNUP_SELECTORS;
158713
158920
  exports.SINGULAR = SINGULAR;