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
Expand Up @@ -51,14 +51,32 @@ test('throws error when provided validation function returns invalid', async ()
}).rejects.toThrow('Dashboard failed saved object result validation');
});

test('returns undefined when provided validation function returns redireted', async () => {
test('returns undefined when provided validation function returns redirected', async () => {
const creationOptions: DashboardCreationOptions = {
validateLoadedSavedObject: jest.fn().mockImplementation(() => 'redirected'),
};
const dashboard = await createDashboard(creationOptions, 0, 'test-id');
expect(dashboard).toBeUndefined();
});

/**
* Because the getInitialInput function may have side effects, we only want to call it once we are certain that the
* the loaded saved object passes validation.
*
* This is especially relevant in the Dashboard App case where calling the getInitialInput function removes the _a
* param from the URL. In alais match situations this caused a bug where the state from the URL wasn't properly applied
* after the redirect.
*/
test('does not get initial input when provided validation function returns redirected', async () => {
const creationOptions: DashboardCreationOptions = {
validateLoadedSavedObject: jest.fn().mockImplementation(() => 'redirected'),
getInitialInput: jest.fn(),
};
const dashboard = await createDashboard(creationOptions, 0, 'test-id');
expect(dashboard).toBeUndefined();
expect(creationOptions.getInitialInput).not.toHaveBeenCalled();
});

test('pulls state from dashboard saved object when given a saved object id', async () => {
pluginServices.getServices().dashboardContentManagement.loadDashboardState = jest
.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const initializeDashboard = async ({
useUnifiedSearchIntegration,
useSessionStorageIntegration,
} = creationOptions ?? {};
const overrideInput = getInitialInput?.();

// --------------------------------------------------------------------------------------
// Run validation.
Expand All @@ -161,6 +160,7 @@ export const initializeDashboard = async ({
// --------------------------------------------------------------------------------------
// Combine input from saved object, session storage, & passed input to create initial input.
// --------------------------------------------------------------------------------------
const overrideInput = getInitialInput?.();
const initialInput: DashboardContainerInput = cloneDeep({
...DEFAULT_DASHBOARD_INPUT,
...(loadDashboardReturn?.dashboardInput ?? {}),
Expand Down