Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Feb 10, 2021
1 parent e110be1 commit cdba2e5
Showing 1 changed file with 64 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ describe('embeddable state transfer', () => {

const testAppId = 'testApp';

const buildKey = (appId: string, key: string) => `${appId}-${key}`;

beforeEach(() => {
currentAppId$ = new Subject();
currentAppId$.next(originatingApp);
Expand Down Expand Up @@ -86,8 +84,10 @@ describe('embeddable state transfer', () => {
it('can send an outgoing editor state', async () => {
await stateTransfer.navigateToEditor(destinationApp, { state: { originatingApp } });
expect(store.set).toHaveBeenCalledWith(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(destinationApp, EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'superUltraTestDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
[destinationApp]: {
originatingApp: 'superUltraTestDashboard',
},
},
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
Expand All @@ -104,8 +104,10 @@ describe('embeddable state transfer', () => {
});
expect(store.set).toHaveBeenCalledWith(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
kibanaIsNowForSports: 'extremeSportsKibana',
[buildKey(destinationApp, EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'superUltraTestDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
[destinationApp]: {
originatingApp: 'superUltraTestDashboard',
},
},
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
Expand All @@ -125,9 +127,11 @@ describe('embeddable state transfer', () => {
state: { type: 'coolestType', input: { savedObjectId: '150' } },
});
expect(store.set).toHaveBeenCalledWith(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(destinationApp, EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'coolestType',
input: { savedObjectId: '150' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[destinationApp]: {
type: 'coolestType',
input: { savedObjectId: '150' },
},
},
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
Expand All @@ -144,9 +148,11 @@ describe('embeddable state transfer', () => {
});
expect(store.set).toHaveBeenCalledWith(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
kibanaIsNowForSports: 'extremeSportsKibana',
[buildKey(destinationApp, EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'coolestType',
input: { savedObjectId: '150' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[destinationApp]: {
type: 'coolestType',
input: { savedObjectId: '150' },
},
},
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
Expand All @@ -165,8 +171,10 @@ describe('embeddable state transfer', () => {

it('can fetch an incoming editor state', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'superUltraTestDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
[testAppId]: {
originatingApp: 'superUltraTestDashboard',
},
},
});
const fetchedState = stateTransfer.getIncomingEditorState(testAppId);
Expand All @@ -175,14 +183,16 @@ describe('embeddable state transfer', () => {

it('can fetch an incoming editor state and ignore state for other apps', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey('otherApp1', EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'whoops not me',
},
[buildKey('otherApp2', EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'otherTestDashboard',
},
[buildKey(testAppId, EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'superUltraTestDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
otherApp1: {
originatingApp: 'whoops not me',
},
otherApp2: {
originatingApp: 'otherTestDashboard',
},
[testAppId]: {
originatingApp: 'superUltraTestDashboard',
},
},
});
const fetchedState = stateTransfer.getIncomingEditorState(testAppId);
Expand All @@ -194,8 +204,10 @@ describe('embeddable state transfer', () => {

it('incoming editor state returns undefined when state is not in the right shape', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_EDITOR_STATE_KEY)]: {
helloSportsKibana: 'superUltraTestDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
[testAppId]: {
helloSportsKibana: 'superUltraTestDashboard',
},
},
});
const fetchedState = stateTransfer.getIncomingEditorState(testAppId);
Expand All @@ -204,9 +216,11 @@ describe('embeddable state transfer', () => {

it('can fetch an incoming embeddable package state', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[testAppId]: {
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
},
},
});
const fetchedState = stateTransfer.getIncomingEmbeddablePackage(testAppId);
Expand All @@ -215,13 +229,15 @@ describe('embeddable state transfer', () => {

it('can fetch an incoming embeddable package state and ignore state for other apps', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
},
[buildKey('testApp2', EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'crossCountryEmbeddable',
input: { savedObjectId: '456' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[testAppId]: {
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
},
testApp2: {
type: 'crossCountryEmbeddable',
input: { savedObjectId: '456' },
},
},
});
const fetchedState = stateTransfer.getIncomingEmbeddablePackage(testAppId);
Expand All @@ -236,17 +252,23 @@ describe('embeddable state transfer', () => {

it('embeddable package state returns undefined when state is not in the right shape', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_PACKAGE_STATE_KEY)]: { kibanaIsFor: 'sports' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[testAppId]: {
kibanaIsFor: 'sports',
},
},
});
const fetchedState = stateTransfer.getIncomingEmbeddablePackage(testAppId);
expect(fetchedState).toBeUndefined();
});

it('removes embeddable package key when removeAfterFetch is true', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_PACKAGE_STATE_KEY)]: {
type: 'coolestType',
input: { savedObjectId: '150' },
[EMBEDDABLE_PACKAGE_STATE_KEY]: {
[testAppId]: {
type: 'coolestType',
input: { savedObjectId: '150' },
},
},
iSHouldStillbeHere: 'doing the sports thing',
});
Expand All @@ -258,8 +280,10 @@ describe('embeddable state transfer', () => {

it('removes editor state key when removeAfterFetch is true', async () => {
store.set(EMBEDDABLE_STATE_TRANSFER_STORAGE_KEY, {
[buildKey(testAppId, EMBEDDABLE_EDITOR_STATE_KEY)]: {
originatingApp: 'superCoolFootballDashboard',
[EMBEDDABLE_EDITOR_STATE_KEY]: {
[testAppId]: {
originatingApp: 'superCoolFootballDashboard',
},
},
iSHouldStillbeHere: 'doing the sports thing',
});
Expand Down

0 comments on commit cdba2e5

Please sign in to comment.