From 838ba2d134206519da2ffd0c8b05d20b27983eb4 Mon Sep 17 00:00:00 2001 From: pnaik1 Date: Mon, 8 Apr 2024 17:44:52 +0530 Subject: [PATCH] added test for application launcher --- .../cypress/e2e/appLauncher/AppLauncher.cy.ts | 22 ++++++++++++ .../cypress/cypress/pages/appLauncher.ts | 34 +++++++++++++++++++ frontend/src/app/AppLauncher.tsx | 8 ++++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 frontend/src/__tests__/cypress/cypress/e2e/appLauncher/AppLauncher.cy.ts create mode 100644 frontend/src/__tests__/cypress/cypress/pages/appLauncher.ts diff --git a/frontend/src/__tests__/cypress/cypress/e2e/appLauncher/AppLauncher.cy.ts b/frontend/src/__tests__/cypress/cypress/e2e/appLauncher/AppLauncher.cy.ts new file mode 100644 index 0000000000..916ffc6f7f --- /dev/null +++ b/frontend/src/__tests__/cypress/cypress/e2e/appLauncher/AppLauncher.cy.ts @@ -0,0 +1,22 @@ +import { mockDashboardConfig, mockDscStatus, mockStatus } from '~/__mocks__'; +import { mockComponents } from '~/__mocks__/mockComponents'; +import { applicationLauncher } from '~/__tests__/cypress/cypress/pages/appLauncher'; + +describe('App launcher', () => { + beforeEach(() => { + cy.intercept('/api/dsc/status', mockDscStatus({})); + cy.intercept('/api/status', mockStatus()); + cy.intercept('/api/config', mockDashboardConfig({})); + cy.intercept('/api/components', mockComponents()); + applicationLauncher.visit(); + }); + it('Validate clicking on App Launcher opens menu', () => { + applicationLauncher.visit(); + applicationLauncher.toggleAppLauncherButton(); + const applicationLauncherMenuGroup = applicationLauncher.getApplicationLauncherMenuGroup( + 'Open Data Hub Applications', + ); + applicationLauncherMenuGroup.shouldHaveApplicationLauncherItem('OpenShift Cluster Manager'); + applicationLauncher.toggleAppLauncherButton(); + }); +}); diff --git a/frontend/src/__tests__/cypress/cypress/pages/appLauncher.ts b/frontend/src/__tests__/cypress/cypress/pages/appLauncher.ts new file mode 100644 index 0000000000..c50ccc5f11 --- /dev/null +++ b/frontend/src/__tests__/cypress/cypress/pages/appLauncher.ts @@ -0,0 +1,34 @@ +import { Contextual } from './components/Contextual'; + +class ApplicationLauncherMenuGroup extends Contextual { + shouldHaveApplicationLauncherItem(name: string) { + this.find().findAllByTestId('application-launcher-item').contains(name).should('exist'); + return this; + } +} + +class ApplicationLauncher { + visit() { + cy.visit('/explore'); + this.wait(); + } + + private wait() { + cy.findByTestId('explore-applications').should('be.visible'); + cy.testA11y(); + } + + toggleAppLauncherButton() { + cy.findByTestId('application-launcher') + .findByRole('button', { name: 'Application launcher' }) + .click(); + } + + getApplicationLauncherMenuGroup(name: string) { + return new ApplicationLauncherMenuGroup(() => + cy.findAllByTestId('application-launcher-group').contains(name).parents(), + ); + } +} + +export const applicationLauncher = new ApplicationLauncher(); diff --git a/frontend/src/app/AppLauncher.tsx b/frontend/src/app/AppLauncher.tsx index 6051d1dd2b..21aef92a30 100644 --- a/frontend/src/app/AppLauncher.tsx +++ b/frontend/src/app/AppLauncher.tsx @@ -130,6 +130,7 @@ const AppLauncher: React.FC = () => { const renderApplicationLauncherGroup = (section: Section, sectionIndex: number) => { const appItems = section.actions.map((action) => ( { appItems.push(); } return ( - + {appItems} ); }; return (