Skip to content

Commit

Permalink
added test for application launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
pnaik1 committed Apr 8, 2024
1 parent fee2688 commit 838ba2d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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();
});
});
34 changes: 34 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/appLauncher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Contextual } from './components/Contextual';

class ApplicationLauncherMenuGroup extends Contextual<HTMLElement> {
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();
8 changes: 7 additions & 1 deletion frontend/src/app/AppLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const AppLauncher: React.FC = () => {
const renderApplicationLauncherGroup = (section: Section, sectionIndex: number) => {
const appItems = section.actions.map((action) => (
<ApplicationLauncherItem
data-testid="application-launcher-item"
key={action.label}
href={action.href}
isExternal
Expand All @@ -144,13 +145,18 @@ const AppLauncher: React.FC = () => {
appItems.push(<ApplicationLauncherSeparator key={`separator-${sectionIndex}`} />);
}
return (
<ApplicationLauncherGroup key={section.label} label={section.label}>
<ApplicationLauncherGroup
key={section.label}
label={section.label}
data-testid="application-launcher-group"
>
{appItems}
</ApplicationLauncherGroup>
);
};
return (
<ApplicationLauncher
data-testid="application-launcher"
aria-label="Application launcher"
onSelect={onSelect}
onToggle={onToggle}
Expand Down

0 comments on commit 838ba2d

Please sign in to comment.