Skip to content

Commit

Permalink
Fix types + failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Jan 4, 2024
1 parent fd5091d commit f22ca1f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import type { TimeRange } from '@kbn/es-query';

import { TimeRangeInput } from './customize_panel_action';
import { Embeddable, IContainer, ContainerInput } from '../../..';
import { TimeRangeInput } from './time_range_helpers';

interface ContainerTimeRangeInput extends ContainerInput<TimeRangeInput> {
timeRange: TimeRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ describe('panel title / description', () => {
expect(customizePanelForm).not.toContainElement(titleDescriptionComponent);
});

test('title input receives focus when `titleFocus` is `true`', async () => {
test('title input receives focus when `focusOnTitle` is `true`', async () => {
const mockEmbeddable = await createEmbeddable({ viewMode: ViewMode.EDIT });
render(
<IntlProvider locale="en">
<CustomizePanelEditor {...DEFAULT_PROPS} embeddable={mockEmbeddable} titleFocus={true} />
<CustomizePanelEditor {...DEFAULT_PROPS} embeddable={mockEmbeddable} focusOnTitle={true} />
</IntlProvider>
);

const customTitleComponent = await screen.findByTestId('customEmbeddablePanelTitleInput');
expect(customTitleComponent).toHaveFocus();
});

test('title input does not receive focus when `titleFocus` is `false`', async () => {
test('title input does not receive focus when `focusOnTitle` is `false`', async () => {
const mockEmbeddable = await createEmbeddable({ viewMode: ViewMode.EDIT });
render(
<IntlProvider locale="en">
<CustomizePanelEditor {...DEFAULT_PROPS} embeddable={mockEmbeddable} titleFocus={false} />
<CustomizePanelEditor {...DEFAULT_PROPS} embeddable={mockEmbeddable} focusOnTitle={false} />
</IntlProvider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { Embeddable, IContainer, ContainerInput } from '../../../lib';
import { TimeRangeInput } from './customize_panel_action';
import { ContainerInput, Embeddable, IContainer } from '../../../lib';
import { TimeRangeInput } from './time_range_helpers';

export function doesInheritTimeRange(embeddable: Embeddable<TimeRangeInput>) {
if (!embeddable.parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,27 @@

import React from 'react';

import { overlayServiceMock } from '@kbn/core-overlays-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
// import userEvent from '@testing-library/user-event';

// import { ViewMode } from '../../lib';
import { applicationServiceMock } from '@kbn/core-application-browser-mocks';
import userEvent from '@testing-library/user-event';
import { ViewMode } from '../../../common';
import {
ContactCardEmbeddable,
ContactCardEmbeddableFactory,
ContactCardEmbeddableInput,
} from '../../lib/test_samples';
import { CustomizePanelAction, EditPanelAction } from '../panel_actions';
import { EditPanelAction } from '../panel_actions';
import * as openCustomizePanel from '../panel_actions/customize_panel_action/open_customize_panel';
import { EmbeddablePanelHeader } from './embeddable_panel_header';

const overlays = overlayServiceMock.createStartContract();
const theme = themeServiceMock.createStartContract();
const editPanelActionMock = { execute: jest.fn() } as unknown as EditPanelAction;
const getEmbeddableFactory = jest.fn();
const application = applicationServiceMock.createStartContract();

const editPanelAction = new EditPanelAction(getEmbeddableFactory, application);
const mockEmbeddableFactory = new ContactCardEmbeddableFactory((() => null) as any, {} as any);
const customizePanelAction = new CustomizePanelAction(overlays, theme, editPanelActionMock);
customizePanelAction.execute = jest.fn();
editPanelAction.execute = jest.fn();

const DEFAULT_PANEL_TITLE = 'Panel title';

Expand Down Expand Up @@ -130,10 +127,10 @@ describe('edit mode', () => {
<EmbeddablePanelHeader
embeddable={mockEmbeddable}
headerId={'headerId'}
universalActions={{ customizePanel: customizePanelAction }}
universalActions={{ editPanel: editPanelAction }}
/>
);
const titleComponent = await screen.findByTestId('dashboardPanelTitle');
const titleComponent = await screen.findByTestId('embeddablePanelTitleInner');
expect(titleComponent).toHaveTextContent('[No Title]');
});

Expand All @@ -146,29 +143,29 @@ describe('edit mode', () => {
<EmbeddablePanelHeader
embeddable={mockEmbeddable}
headerId={'headerId'}
universalActions={{ customizePanel: customizePanelAction }}
universalActions={{ editPanel: editPanelAction }}
/>
);
screen.debug();
const titleComponent = await screen.findByTestId('embeddablePanelHeading-');
const innerTitleComponent = await screen.findByTestId('embeddablePanelTitleInner');
expect(innerTitleComponent).toBeEmptyDOMElement();
const menuComponent = await screen.findByTestId('embeddablePanelToggleMenuIcon');
expect(titleComponent).toContainElement(menuComponent);
});

test('clicking title calls customize panel action', async () => {
test('clicking title opens customize panel flyout', async () => {
const mockEmbeddable = await createEmbeddable({ viewMode: ViewMode.EDIT });
render(
<EmbeddablePanelHeader
embeddable={mockEmbeddable}
headerId={'headerId'}
universalActions={{ customizePanel: customizePanelAction }}
universalActions={{ editPanel: editPanelAction }}
/>
);
screen.debug();
const titleComponent = await screen.findByTestId('embeddablePanelTitleLink');

const spy = jest.spyOn(openCustomizePanel, 'openCustomizePanelFlyout');
userEvent.click(titleComponent);
expect(customizePanelAction.execute).toBeCalled();
expect(spy).toHaveBeenCalled();
});
});

0 comments on commit f22ca1f

Please sign in to comment.