Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import type { OnSaveProps } from '@kbn/saved-objects-plugin/public';
import { AddPanelToLibraryActionApi, AddToLibraryAction } from './library_add_action';
import { BehaviorSubject } from 'rxjs';

jest.mock('@kbn/saved-objects-plugin/public', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { render } = require('@testing-library/react');
const MockSavedObjectSaveModal = ({ onSave }: { onSave: (props: OnSaveProps) => void }) => {
onSave({
newTitle: 'Library panel one',
newCopyOnSave: true,
isTitleDuplicateConfirmed: false,
onTitleDuplicate: () => {},
newDescription: '',
});
return null;
};
return {
SavedObjectSaveModal: MockSavedObjectSaveModal,
showSaveModal: (saveModal: React.ReactElement) => {
render(saveModal);
},
};
});

describe('AddToLibraryAction', () => {
const action = new AddToLibraryAction();
const saveToLibraryMock = jest.fn(async () => 'libraryId1');
const replacePanelMock = jest.fn();
const embeddableApi = {
checkForDuplicateTitle: async () => {},
canLinkToLibrary: async () => true,
canUnlinkFromLibrary: async () => false,
getSerializedStateByReference: () => ({ rawState: { savedObjectId: 'libraryId1' } }),
getSerializedStateByValue: () => ({ rawState: {} }),
parentApi: {
replacePanel: replacePanelMock,
viewMode$: new BehaviorSubject('edit'),
},
saveToLibrary: saveToLibraryMock,
type: 'testEmbeddable',
uuid: '1',
} as AddPanelToLibraryActionApi;

beforeEach(() => {
jest.clearAllMocks();
});

describe('execute', () => {
test('should save panel to library and replace panel with library panel', async () => {
await action.execute({ embeddable: embeddableApi });
expect(saveToLibraryMock).toHaveBeenCalled();
expect(replacePanelMock).toHaveBeenCalledWith('1', {
panelType: 'testEmbeddable',
serializedState: {
rawState: {
savedObjectId: 'libraryId1',
title: 'Library panel one',
},
references: undefined,
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { BehaviorSubject } from 'rxjs';
import { UnlinkFromLibraryAction, UnlinkPanelFromLibraryActionApi } from './library_unlink_action';

describe('AddToLibraryAction', () => {
const action = new UnlinkFromLibraryAction();
const replacePanelMock = jest.fn();
const embeddableApi = {
defaultTitle$: new BehaviorSubject('Panel one'),
checkForDuplicateTitle: async () => {},
canLinkToLibrary: async () => false,
canUnlinkFromLibrary: async () => true,
getSerializedStateByReference: () => ({ rawState: {} }),
getSerializedStateByValue: () => ({ rawState: { key1: 'value1' } }),
parentApi: {
replacePanel: replacePanelMock,
viewMode$: new BehaviorSubject('edit'),
},
saveToLibrary: async () => 'libraryId1',
type: 'testEmbeddable',
uuid: '1',
} as UnlinkPanelFromLibraryActionApi;

beforeEach(() => {
jest.clearAllMocks();
});

describe('execute', () => {
test('should replace panel with by value panel', async () => {
await action.execute({ embeddable: embeddableApi });
expect(replacePanelMock).toHaveBeenCalledWith('1', {
panelType: 'testEmbeddable',
serializedState: {
rawState: {
key1: 'value1',
// should get default title from by reference embeddable
title: 'Panel one',
},
references: undefined,
},
});
});
});
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
// The dashboard_snapshot test below requires the timestamped URL which breaks the view_edit test.
// If we don't use the timestamp in the URL, the colors in the charts will be different.
loadTestFile(require.resolve('./dashboard_snapshots'));
loadTestFile(require.resolve('./embeddable_library'));
loadTestFile(require.resolve('./dashboard_esql_chart'));
loadTestFile(require.resolve('./dashboard_esql_no_data'));
});
Expand Down