From 602be5b39078d5216bde0bcd01ed838585838ada Mon Sep 17 00:00:00 2001 From: Derrick Hawkins Date: Tue, 28 Nov 2023 14:41:21 -0800 Subject: [PATCH] look for exact match when selecting domain name from popper menu --- .../management-cluster-provision.cy.ts | 3 ++- utils/__tests__/exactWordRegex.test.ts | 14 ++++++++++++++ utils/exactWordRegex.ts | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 utils/__tests__/exactWordRegex.test.ts create mode 100644 utils/exactWordRegex.ts diff --git a/cypress/e2e/1-create-cluster/management-cluster-provision.cy.ts b/cypress/e2e/1-create-cluster/management-cluster-provision.cy.ts index 599a8cd4..2766594a 100644 --- a/cypress/e2e/1-create-cluster/management-cluster-provision.cy.ts +++ b/cypress/e2e/1-create-cluster/management-cluster-provision.cy.ts @@ -1,5 +1,6 @@ import { InstallationType } from '../../../types/redux'; import { GitProvider } from '../../../types'; +import { exactWordRegex } from '../../../utils/exactWordRegex'; const GIT_PROVIDER = Cypress.env('GIT_PROVIDER'); const CLOUD_PROVIDER = Cypress.env('CLOUD_PROVIDER'); @@ -201,7 +202,7 @@ describe('provision management cluster using any git provider, cloud provider, a cy.get("[name='domainName']").click(); // click domainName multiselect to open menu cy.get('.MuiAutocomplete-popper').then((popper) => { - cy.wrap(popper).contains(DOMAIN_NAME_FINAL).click(); + cy.wrap(popper).contains(exactWordRegex(DOMAIN_NAME_FINAL)).click(); }); if (DNS_PROVIDER === 'Cloudflare' && SUB_DOMAIN) { diff --git a/utils/__tests__/exactWordRegex.test.ts b/utils/__tests__/exactWordRegex.test.ts new file mode 100644 index 00000000..8e55ed60 --- /dev/null +++ b/utils/__tests__/exactWordRegex.test.ts @@ -0,0 +1,14 @@ +import { exactWordRegex } from '../exactWordRegex'; + +describe('utils/exactWordRegex', () => { + it('will return a regex that will look for the exact string passed in', () => { + const domainOne = 'freegitopsmagic.com'; + const domainTwo = 'gitopsmagic.com'; + const domainThree = 'FreeGitOpsMagic.com'; + + const domainOneExactRegex = exactWordRegex(domainOne); + expect(domainOneExactRegex.test(domainTwo)).toBeFalsy(); + expect(domainOneExactRegex.test(domainThree)).toBeFalsy(); + expect(domainOneExactRegex.test(domainOne)).toBeTruthy(); + }); +}); diff --git a/utils/exactWordRegex.ts b/utils/exactWordRegex.ts new file mode 100644 index 00000000..7035298b --- /dev/null +++ b/utils/exactWordRegex.ts @@ -0,0 +1,3 @@ +export function exactWordRegex(word: string) { + return new RegExp(`^${word}$`); +}