Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Jul 5, 2021
1 parent aa648ec commit 851df39
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/plugins/embeddable/common/lib/get_all_migrations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { getAllMigrations } from './get_all_migrations';

describe('embeddable getAllMigratons', () => {
const factories = { test: { migrations: { '7.11.0': (state: any) => state } } };
const enhacements = { test: { migrations: { '7.12.0': (state: any) => state } } };
const migrateFn = jest.fn();

test('returns base migrations', () => {
expect(getAllMigrations({}, {}, migrateFn)).toEqual({});
});

test('returns embeddable factory migrations', () => {
expect(getAllMigrations(factories, {}, migrateFn)).toHaveProperty('7.11.0');
});

test('returns enhancement migrations', () => {
expect(getAllMigrations({}, enhacements, migrateFn)).toHaveProperty('7.12.0');
});

test('returns all migrations', () => {
const migrations = getAllMigrations(factories, enhacements, migrateFn);
expect(migrations).toHaveProperty('7.11.0');
expect(migrations).toHaveProperty('7.12.0');
});
});
33 changes: 32 additions & 1 deletion src/plugins/embeddable/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,34 @@ describe('embeddable factory', () => {
my: 'state',
} as any;

const containerEmbeddableFactoryId = 'CONTAINER';
const containerEmbeddableFactory = {
type: containerEmbeddableFactoryId,
create: jest.fn(),
getDisplayName: () => 'Container',
isContainer: true,
isEditable: () => Promise.resolve(true),
extract: jest.fn().mockImplementation((state) => ({ state, references: [] })),
inject: jest.fn().mockImplementation((state) => state),
telemetry: jest.fn().mockResolvedValue({}),
migrations: { '7.12.0': jest.fn().mockImplementation((state) => state) },
};

const containerState = {
id: containerEmbeddableFactoryId,
type: containerEmbeddableFactoryId,
some: 'state',
panels: [
{
...embeddableState,
},
],
} as any;

setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory);
setup.registerEmbeddableFactory(containerEmbeddableFactoryId, containerEmbeddableFactory);

test('cannot register embeddable factory with the same ID', async () => {
setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory);
expect(() =>
setup.registerEmbeddableFactory(embeddableFactoryId, embeddableFactory)
).toThrowError(
Expand All @@ -134,6 +160,11 @@ describe('embeddable factory', () => {
start.getAllMigrations!()['7.11.0']!(embeddableState);
expect(embeddableFactory.migrations['7.11.0']).toBeCalledWith(embeddableState);
});

test('panels inside container get automatically migrated when migrating conta1iner', () => {
start.getAllMigrations!()['7.11.0']!(containerState);
expect(embeddableFactory.migrations['7.11.0']).toBeCalledWith(embeddableState);
});
});

describe('embeddable enhancements', () => {
Expand Down

0 comments on commit 851df39

Please sign in to comment.