E2E: Fixed so openPanelMenuItem flow works with new/old panel chrome without breaking changes (#66118)

Fixed so the openPanelMenuItem works with both angular and react panels.
This commit is contained in:
Marcus Andersson
2023-04-14 09:11:15 +02:00
committed by GitHub
parent 46742f6d96
commit c3fee5881f
4 changed files with 51 additions and 22 deletions

View File

@@ -17,7 +17,7 @@ e2e.scenario({
e2e.flows.openDashboard({ uid: 'TkZXxlNG3' }); e2e.flows.openDashboard({ uid: 'TkZXxlNG3' });
e2e().wait('@query'); e2e().wait('@query');
e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Edit, PANEL_UNDER_TEST, true); e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Edit, PANEL_UNDER_TEST);
// New panel editor opens when navigating from Panel menu // New panel editor opens when navigating from Panel menu
e2e.components.PanelEditor.General.content().should('be.visible'); e2e.components.PanelEditor.General.content().should('be.visible');

View File

@@ -37,7 +37,7 @@ e2e.scenario({
e2e.flows.openDashboard({ uid: 'wfTJJL5Wz' }); e2e.flows.openDashboard({ uid: 'wfTJJL5Wz' });
// testing opening inspect drawer directly by clicking on Inspect in header menu // testing opening inspect drawer directly by clicking on Inspect in header menu
e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Inspect, PANEL_UNDER_TEST, true); e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Inspect, PANEL_UNDER_TEST);
expectDrawerTabsAndContent(); expectDrawerTabsAndContent();
@@ -49,7 +49,7 @@ e2e.scenario({
expectSubMenuScenario('Query'); expectSubMenuScenario('Query');
expectSubMenuScenario('Panel JSON', 'JSON'); expectSubMenuScenario('Panel JSON', 'JSON');
e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Edit, PANEL_UNDER_TEST, true); e2e.flows.openPanelMenuItem(e2e.flows.PanelMenuItems.Edit, PANEL_UNDER_TEST);
e2e.components.QueryTab.queryInspectorButton().should('be.visible').click(); e2e.components.QueryTab.queryInspectorButton().should('be.visible').click();

View File

@@ -7,26 +7,51 @@ export enum PanelMenuItems {
Extensions = 'Extensions', Extensions = 'Extensions',
} }
export const openPanelMenuItem = (menu: PanelMenuItems, panelTitle = 'Panel Title', isReactPanel = false) => { export const openPanelMenuItem = (menu: PanelMenuItems, panelTitle = 'Panel Title') => {
// we changed the way we open the panel menu in react panels with the new panel header // we changed the way we open the panel menu in react panels with the new panel header
if (isReactPanel) { detectPanelType(panelTitle, (isAngularPanel) => {
e2e.components.Panels.Panel.menu(panelTitle).click({ force: true }); // force click because menu is hidden and show on hover if (isAngularPanel) {
e2e.components.Panels.Panel.menuItems(menu).should('be.visible').click(); e2e.components.Panels.Panel.title(panelTitle).should('be.visible').click();
} else { e2e.components.Panels.Panel.headerItems(menu).should('be.visible').click();
// this is the old way of opening the panel menu from the title } else {
e2e.components.Panels.Panel.title(panelTitle).should('be.visible').click(); e2e.components.Panels.Panel.menu(panelTitle).click({ force: true }); // force click because menu is hidden and show on hover
e2e.components.Panels.Panel.headerItems(menu).should('be.visible').click(); e2e.components.Panels.Panel.menuItems(menu).should('be.visible').click();
} }
});
}; };
export const openPanelMenuExtension = (extensionTitle: string, panelTitle = 'Panel Title') => { export const openPanelMenuExtension = (extensionTitle: string, panelTitle = 'Panel Title') => {
e2e.components.Panels.Panel.title(panelTitle).should('be.visible').click(); const menuItem = PanelMenuItems.Extensions;
// we changed the way we open the panel menu in react panels with the new panel header
e2e.components.Panels.Panel.headerItems(PanelMenuItems.Extensions) detectPanelType(panelTitle, (isAngularPanel) => {
.should('be.visible') if (isAngularPanel) {
.parent() e2e.components.Panels.Panel.title(panelTitle).should('be.visible').click();
.parent() e2e.components.Panels.Panel.headerItems(menuItem)
.invoke('addClass', 'open'); .should('be.visible')
.parent()
e2e.components.Panels.Panel.headerItems(extensionTitle).should('be.visible').click(); .parent()
.invoke('addClass', 'open');
e2e.components.Panels.Panel.headerItems(extensionTitle).should('be.visible').click();
} else {
e2e.components.Panels.Panel.menu(panelTitle).click({ force: true }); // force click because menu is hidden and show on hover
e2e.components.Panels.Panel.menuItems(menuItem).trigger('mouseover', { force: true });
e2e.components.Panels.Panel.menuItems(extensionTitle).click({ force: true });
}
});
}; };
function detectPanelType(panelTitle: string, detected: (isAngularPanel: boolean) => void) {
e2e.components.Panels.Panel.title(panelTitle).then((el) => {
const isAngularPanel = el.find('plugin-component.ng-scope').length > 0;
if (isAngularPanel) {
Cypress.log({
name: 'detectPanelType',
displayName: 'detector',
message: 'Angular panel detected, will use legacy selectors.',
});
}
detected(isAngularPanel);
});
}

View File

@@ -197,7 +197,11 @@ export class PanelChromeAngularUnconnected extends PureComponent<Props, State> {
}); });
return ( return (
<div className={containerClassNames} aria-label={selectors.components.Panels.Panel.containerByTitle(panel.title)}> <div
className={containerClassNames}
data-testid={selectors.components.Panels.Panel.title(panel.title)}
aria-label={selectors.components.Panels.Panel.containerByTitle(panel.title)}
>
<PanelHeader <PanelHeader
panel={panel} panel={panel}
dashboard={dashboard} dashboard={dashboard}