@globisnv/cypress-core 2.1.0 → 2.1.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.
@@ -207,16 +207,16 @@ declare global {
207
207
  /**
208
208
  * Command to open the workflow menu and to click a desired workflow in the main program datacontrol section.
209
209
  *
210
- * @param {string} buttonName - The workflow entry to be selected.
211
- * @param {exactMatchFlag} [exactMatch] - Indicates whether to search for an exact match (equalBool) or not. Default is disabled.
210
+ * @param {string} buttonName - The workflow entry to be selected. An entry with exactly this text is preferred over entries that only contain it.
211
+ * @param {exactMatchFlag} [exactMatch] - Only accept an exact match (equalBool). Default: disabled, falls back to the first entry containing the text when no entry matches exactly.
212
212
  */
213
213
  GLO_selectMenuButton(buttonName: string, exactMatch?: exactMatchFlag): void;
214
214
  /**
215
215
  * Command to open the workflow menu and to click a desired workflow in the datacontrol viewer section.
216
216
  *
217
217
  * @param {string} tabName - The name of the tab containing the datacontrol viewer section.
218
- * @param {string} buttonName - The workflow entry to be selected.
219
- * @param {exactMatchFlag} [exactMatch] - Indicates whether to search for an exact match (equalBool) or not). Default: is disabled.
218
+ * @param {string} buttonName - The workflow entry to be selected. An entry with exactly this text is preferred over entries that only contain it.
219
+ * @param {exactMatchFlag} [exactMatch] - Only accept an exact match (equalBool). Default: disabled, falls back to the first entry containing the text when no entry matches exactly.
220
220
  *
221
221
  * @example - cy.GLO_selectMenuButtonControlView('salesorder', 'Confirm');
222
222
  */
@@ -473,19 +473,15 @@ Cypress.Commands.add('GLO_clickDatacontrolViewerButton', (pageName, buttonName,
473
473
  });
474
474
  });
475
475
  Cypress.Commands.add('GLO_checkDatacontrolCounter', (buttonName, greyCount, redCount, timeOut = defaultTimeout) => {
476
- const button = `globiscomponents-data-control[name="datacontrol"]:visible #${buttonName}`;
477
- // Without the button in view a 'not.exist' check below would pass for the wrong reason.
478
- cy.get(button, { timeout: timeOut }).should('exist');
476
+ const button = () => cy.get(`globiscomponents-data-control[name="datacontrol"]:visible [id="${buttonName}"]`, { timeout: timeOut });
477
+ button().should('exist');
479
478
  const checkBadge = (selector, count) => {
480
- if (count > 0) {
481
- cy.get(selector, { timeout: timeOut }).should('have.text', count.toString());
482
- }
483
- else {
484
- cy.get(selector, { timeout: timeOut }).should('not.exist');
485
- }
479
+ button()
480
+ .find(selector, { timeout: timeOut })
481
+ .should(count > 0 ? 'have.text' : 'not.exist', ...(count > 0 ? [count.toString()] : []));
486
482
  };
487
- checkBadge(`${button} [counter-muted]`, greyCount);
488
- checkBadge(`${button} [counter]:not([counter-muted])`, redCount);
483
+ checkBadge('[counter-muted]', greyCount);
484
+ checkBadge('[counter]:not([counter-muted])', redCount);
489
485
  });
490
486
  Cypress.Commands.add('GLO_selectCompany', (companyName) => {
491
487
  cy.GLO_addInput(['ng2$svy_nav_login', 'company'], companyName);
@@ -747,27 +743,41 @@ Cypress.Commands.add('GLO_selectTab', (selector, tabName, openOrClose) => {
747
743
  }
748
744
  });
749
745
  });
750
- Cypress.Commands.add('GLO_selectMenuButton', (buttonName, exactMatch = noEqualBool) => {
751
- const searchParam = exactMatch ? new RegExp(`^\\s*${Cypress._.escapeRegExp(buttonName)}\\s*$`) : buttonName;
752
- cy.GLO_clickDatacontrolBrowserButton('btnMenu');
746
+ // True when the workflow menu has an entry whose text equals the button text.
747
+ const checkForExactMatch = ($menu, exactText) => $menu
748
+ .find('.dx-menu-item-text')
749
+ .toArray()
750
+ .some((element) => exactText.test(element.textContent ?? ''));
751
+ // Clicks a workflow entry in the open workflow menu. An entry whose text equals buttonName wins over entries
752
+ // that only contain it (e.g. 'Confirm' over a 'Confirm with discrepancies - ...' status change listed above it);
753
+ // without an exact entry it falls back to the first entry containing buttonName, unless exactMatch is set.
754
+ // The choice is made inside .filter(), a query that Cypress retries on the live menu, so it is never decided on a
755
+ // menu that is still rendering or on a snapshot of it.
756
+ const clickWorkflowMenuItem = (buttonName, exactMatch) => {
757
+ const exactText = new RegExp(`^\\s*${Cypress._.escapeRegExp(buttonName)}\\s*$`);
753
758
  cy.GLO_getVisible('.dx-submenu', 10000)
754
- .contains(searchParam)
759
+ .find('.dx-menu-item-text')
760
+ .filter((_index, element) => {
761
+ const text = element.textContent ?? '';
762
+ if (exactMatch || checkForExactMatch(Cypress.$(element).closest('.dx-submenu'), exactText)) {
763
+ return exactText.test(text);
764
+ }
765
+ return text.includes(buttonName);
766
+ })
767
+ .first()
755
768
  .click()
756
769
  .then(() => {
757
770
  cy.GLO_checkLoadingIndicator();
758
771
  });
759
772
  cy.GLO_log(` - Used workflow button '${buttonName}'`);
773
+ };
774
+ Cypress.Commands.add('GLO_selectMenuButton', (buttonName, exactMatch = noEqualBool) => {
775
+ cy.GLO_clickDatacontrolBrowserButton('btnMenu');
776
+ clickWorkflowMenuItem(buttonName, exactMatch);
760
777
  });
761
778
  Cypress.Commands.add('GLO_selectMenuButtonControlView', (tabName, buttonName, exactMatch = noEqualBool) => {
762
- const searchParam = exactMatch ? new RegExp(`^\\s*${Cypress._.escapeRegExp(buttonName)}\\s*$`) : buttonName;
763
779
  cy.GLO_clickDatacontrolViewerButton(tabName, 'btnMenu');
764
- cy.GLO_getVisible('.dx-submenu', 10000)
765
- .contains(searchParam)
766
- .click()
767
- .then(() => {
768
- cy.GLO_checkLoadingIndicator();
769
- });
770
- cy.GLO_log(` - Used workflow button '${buttonName}'`);
780
+ clickWorkflowMenuItem(buttonName, exactMatch);
771
781
  });
772
782
  const navItem = (topBottom, programName, tabNumber, mode) => {
773
783
  if (topBottom !== top && topBottom !== bottom)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globisnv/cypress-core",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Core building blocks for Globis Cypress E2E tests",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",