Skip to content

Commit

Permalink
Fix action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cqliu1 committed Jun 3, 2024
1 parent e998eba commit 4b90167
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ describe('Expand panel action', () => {
let action: ExpandPanelAction;
let context: { embeddable: ExpandPanelActionApi };

let updateExpandPanelId: (id?: string) => void;

beforeEach(() => {
const expandPanelIdSubject = new BehaviorSubject<string | undefined>(undefined);
updateExpandPanelId = (id) => expandPanelIdSubject.next(id);
action = new ExpandPanelAction();
context = {
embeddable: {
uuid: 'superId',
parentApi: {
expandPanel: jest.fn(),
expandedPanelId: new BehaviorSubject<string | undefined>(undefined),
expandedPanelId: expandPanelIdSubject,
},
},
};
Expand All @@ -37,19 +41,22 @@ describe('Expand panel action', () => {
expect(await action.isCompatible(emptyContext)).toBe(false);
});

it('calls onChange when expandedPanelId changes', async () => {
const onChange = jest.fn();
updateExpandPanelId('superPanelId');
action.subscribeToCompatibilityChanges(context, onChange);
expect(onChange).toHaveBeenCalledWith(true, action);
});

it('returns the correct icon based on expanded panel id', async () => {
expect(await action.getIconType(context)).toBe('expand');
context.embeddable.parentApi.expandedPanelId = new BehaviorSubject<string | undefined>(
'superPanelId'
);
updateExpandPanelId('superPanelId');
expect(await action.getIconType(context)).toBe('minimize');
});

it('returns the correct display name based on expanded panel id', async () => {
expect(await action.getDisplayName(context)).toBe('Maximize');
context.embeddable.parentApi.expandedPanelId = new BehaviorSubject<string | undefined>(
'superPanelId'
);
updateExpandPanelId('superPanelId');
expect(await action.getDisplayName(context)).toBe('Minimize');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ describe('filters notification action', () => {
expect(await action.isCompatible(context)).toBe(true);
});

it('is incompatible when api is in view mode', async () => {
it('is available when api is in view mode', async () => {
updateFilters([getMockPhraseFilter('SuperField', 'SuperValue')]);
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
updateViewMode('view');
expect(await action.isCompatible(context)).toBe(false);
expect(await action.isCompatible(context)).toBe(true);
});

it('calls onChange when view mode changes', () => {
Expand All @@ -99,7 +99,7 @@ describe('filters notification action', () => {
updateQuery({ esql: 'FROM test_dataview' } as AggregateQuery);
action.subscribeToCompatibilityChanges(context, onChange);
updateViewMode('view');
expect(onChange).toHaveBeenCalledWith(false, action);
expect(onChange).toHaveBeenCalledWith(true, action);
});

it('calls onChange when filters change', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ export const PresentationPanelContextMenu = ({
[contextMenuActions]
);

console.log({ quickActions, hoverActionPanels });

const notificationElements = useMemo(() => {
if (!showNotifications || !api) return [];
return notifications?.map((notification) => {
Expand Down

0 comments on commit 4b90167

Please sign in to comment.