import { NavItem, pageTitles } from '../support/constants/PageTitle'; import { consentButton, navigation, waits } from '../support/pageObjects/global-po'; import { goToApplicationsPagePo } from '../support/pageObjects/pages-po'; export class Common { static openAppStudioBaseURL() { cy.visit(Cypress.expose('KONFLUX_BASE_URL')); } static navigateTo(link: NavItem) { for (const item in NavItem) { cy.get(navigation.sideNavigation) .contains('a', NavItem[item], { timeout: 30000 }) .should('be.visible'); } // Fail fast with a clear signal if the click didn't actually navigate. cy.location('pathname').then((previousPath) => { cy.get(navigation.sideNavigation).contains('a', link).click(); cy.location('pathname', { timeout: 10000 }).should('not.eq', previousPath); }); Common.waitForLoad(); } static openURL(URL: string) { cy.url().then(($url) => { if ($url !== URL) { cy.visit(URL); } }); } static generateAppName(prefix = 'test-app') { const name = `${prefix}-${new Date().getTime()}`; return name.substring(0, name.length - 4); } static openApplicationURL(applicationName: string) { const workspacePathMatcher = new RegExp(/ns\/([^/]+)/); cy.url().then((url) => { const [, namespace = ''] = url.match(workspacePathMatcher) || []; Common.openURL( `${Cypress.expose( 'KONFLUX_BASE_URL', )}/ns/${namespace}/applications/${applicationName.replace('.', '-')}`, ); Common.verifyPageTitle(applicationName); Common.waitForLoad(); }); } static waitForLoad(timeout = 120000) { for (const item of Object.values(waits)) { cy.get(item, { timeout }).should('not.exist'); } } static verifyPageTitle(title: string) { cy.contains('h1', title, { timeout: 180000 }).scrollIntoView().should('be.visible'); } static clickOnConsentButton() { cy.get('body') .find(consentButton) .its('length') .then((res) => { if (res > 0) { cy.get(consentButton).click(); } }); } static cleanNamespace() { if (Cypress.expose('CLEAN_NAMESPACE') === 'true') { cy.exec('export KUBECONFIG=~/.kube/appstudio-config && ./delete-script.sh', { timeout: 600000, }) .its('stdout') .should('contain', 'Done running the script'); } } static getOrigin() { return new URL(Cypress.expose('KONFLUX_BASE_URL')).origin; } static checkRowValues(locator: string, valuesToAssert: string[]) { for (const value of valuesToAssert) { cy.contains(`[data-id="${locator}"]`, value, { timeout: 20000 }).should('exist'); } } static getGitHub2FAOTP(): Cypress.Chainable { return cy .env(['GH_SETUP_KEY']) .then(({ GH_SETUP_KEY }) => require('otplib').authenticator.generate(GH_SETUP_KEY)); } }