Skip to content

Commit c442029

Browse files
committed
Add new fn to match text
Signed-off-by: Nandini Chandra <[email protected]>
1 parent a9b15c7 commit c442029

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

cypress/e2e/models/migration/applicationinventory/analysis.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ import {
2424
clickWithinByText,
2525
doesExistSelector,
2626
inputText,
27-
matchText,
2827
next,
2928
selectAnalysisMode,
3029
selectCheckBox,
3130
selectFormItems,
3231
sidedrawerTab,
3332
uploadApplications,
3433
uploadFile,
34+
verifySelectorText,
3535
} from "../../../../utils/utils";
3636
import {
3737
AnalysisStatuses,
3838
analyzeAppButton,
3939
analyzeButton,
40-
appInventoryKebab,
40+
appInventoryKebab as kebab,
4141
button,
4242
clearAllFilters,
4343
Languages,
@@ -87,7 +87,7 @@ import {
8787
tabsPanel,
8888
} from "../../../views/analysis.view";
8989
import { bulkApplicationSelectionCheckBox } from "../../../views/applicationinventory.view";
90-
import { successAlertMessage } from "../../../views/common.view";
90+
import { actionMenuItem, successAlertMessage } from "../../../views/common.view";
9191
import { CustomMigrationTargetView } from "../../../views/custom-migration-target.view";
9292
import { Application } from "./application";
9393

@@ -496,13 +496,26 @@ export class Analysis extends Application {
496496
.within(() => {
497497
clickWithin(kebabTopMenuButton, button);
498498
});
499-
matchText(appInventoryKebab.import, rbacRules["Top action menu"]["Import"]);
500-
matchText(
501-
appInventoryKebab.manageImports,
499+
verifySelectorText(
500+
kebab.import,
501+
actionMenuItem,
502+
rbacRules["Top action menu"]["Import"]
503+
);
504+
verifySelectorText(
505+
kebab.manageImports,
506+
actionMenuItem,
502507
rbacRules["Top action menu"]["Manage application imports"]
503508
);
504-
matchText("Manage credentials", rbacRules["Top action menu"]["Manage credentials"]);
505-
matchText("Delete", rbacRules["Top action menu"]["Delete"]);
509+
verifySelectorText(
510+
kebab.manageCredentials,
511+
actionMenuItem,
512+
rbacRules["Top action menu"]["Manage credentials"]
513+
);
514+
verifySelectorText(
515+
kebab.delete,
516+
actionMenuItem,
517+
rbacRules["Top action menu"]["Delete"]
518+
);
506519
}
507520
}
508521

cypress/e2e/types/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,6 @@ export enum TaskFilter {
248248
export enum appInventoryKebab {
249249
manageImports = "Manage application imports",
250250
import = "Import applications from CSV",
251+
manageCredentials = "Manage credentials",
252+
delete = "Delete",
251253
}

cypress/utils/utils.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,31 @@ export function doesExistButton(str: string, toBePresent: boolean): void {
15991599
cy.contains(button, str).should(toBePresent ? "exist" : "not.exist");
16001600
}
16011601

1602-
export function matchText(str: string, toBePresent: boolean): void {
1603-
const escapedStr = str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1604-
cy.contains(new RegExp(`^${escapedStr}$`)).should(toBePresent ? "exist" : "not.exist");
1602+
/**
1603+
* Verifies that at least one element matching the selector has the exact expected text.
1604+
* Unlike doesExistText which uses cy.contains() for partial/regex matching,
1605+
* this function performs exact text comparison on elements selected by a CSS selector.
1606+
*
1607+
* @param expectedText - The exact text to match (after trimming whitespace)
1608+
* @param selector - CSS selector to find elements
1609+
* @param shouldExist - true to assert text exists, false to assert it doesn't exist
1610+
*/
1611+
export function verifySelectorText(
1612+
expectedText: string,
1613+
selector: string,
1614+
shouldExist: boolean
1615+
): void {
1616+
cy.get(selector).should(($elements) => {
1617+
const texts = Array.from($elements).map((el) => el.textContent?.trim() ?? "");
1618+
const matched = texts.includes(expectedText);
1619+
1620+
if (shouldExist) {
1621+
expect(matched, `Expected one of the elements to have exact text "${shouldExist}"`).to
1622+
.be.true;
1623+
} else {
1624+
expect(matched, `Expected no element to have exact text "${shouldExist}"`).to.be.false;
1625+
}
1626+
});
16051627
}
16061628

16071629
export function enableSwitch(selector: string): void {

0 commit comments

Comments
 (0)