Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Oct 4, 2021
1 parent 7f332b8 commit 2b569a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ describe('Lens App', () => {
};
}

const makeDefaultServicesForApp = () => makeDefaultServices(sessionIdSubject, 'sessionId-1');

async function mountWith({
props = makeDefaultProps(),
services = makeDefaultServices(sessionIdSubject, 'sessionId-1'),
services = makeDefaultServicesForApp(),
preloadedState,
}: {
props?: jest.Mocked<LensAppProps>;
Expand Down Expand Up @@ -150,7 +152,7 @@ describe('Lens App', () => {
});

it('updates global filters with store state', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
const indexPattern = { id: 'index1' } as unknown as IndexPattern;
const pinnedField = { name: 'pinnedField' } as unknown as FieldSpec;
const pinnedFilter = esFilters.buildExistsFilter(pinnedField, indexPattern);
Expand Down Expand Up @@ -222,7 +224,7 @@ describe('Lens App', () => {

it('sets originatingApp breadcrumb when the document title changes', async () => {
const props = makeDefaultProps();
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
props.incomingState = { originatingApp: 'coolContainer' };
services.getOriginatingAppName = jest.fn(() => 'The Coolest Container Ever Made');

Expand Down Expand Up @@ -268,7 +270,7 @@ describe('Lens App', () => {

describe('TopNavMenu#showDatePicker', () => {
it('shows date picker if any used index pattern isTimeBased', async () => {
const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const customServices = makeDefaultServicesForApp();
customServices.data.indexPatterns.get = jest
.fn()
.mockImplementation((id) =>
Expand All @@ -281,7 +283,7 @@ describe('Lens App', () => {
);
});
it('shows date picker if active datasource isTimeBased', async () => {
const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const customServices = makeDefaultServicesForApp();
customServices.data.indexPatterns.get = jest
.fn()
.mockImplementation((id) =>
Expand All @@ -296,7 +298,7 @@ describe('Lens App', () => {
);
});
it('does not show date picker if index pattern nor active datasource is not time based', async () => {
const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const customServices = makeDefaultServicesForApp();
customServices.data.indexPatterns.get = jest
.fn()
.mockImplementation((id) =>
Expand Down Expand Up @@ -343,7 +345,7 @@ describe('Lens App', () => {
);
});
it('handles rejected index pattern', async () => {
const customServices = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const customServices = makeDefaultServicesForApp();
customServices.data.indexPatterns.get = jest
.fn()
.mockImplementation((id) => Promise.reject({ reason: 'Could not locate that data view' }));
Expand Down Expand Up @@ -391,7 +393,7 @@ describe('Lens App', () => {
: undefined,
};

const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.attributeService.wrapAttributes = jest
.fn()
.mockImplementation(async ({ savedObjectId }) => ({
Expand Down Expand Up @@ -425,7 +427,7 @@ describe('Lens App', () => {
}

it('shows a disabled save button when the user does not have permissions', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.application = {
...services.application,
capabilities: {
Expand Down Expand Up @@ -475,7 +477,7 @@ describe('Lens App', () => {

it('Shows Save and Return and Save As buttons in create by value mode with originating app', async () => {
const props = makeDefaultProps();
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.dashboardFeatureFlag = { allowByValueEmbeddables: true };
props.incomingState = {
originatingApp: 'ultraDashboard',
Expand Down Expand Up @@ -624,7 +626,7 @@ describe('Lens App', () => {
const mockedConsoleDir = jest.spyOn(console, 'dir'); // mocked console.dir to avoid messages in the console when running tests
mockedConsoleDir.mockImplementation(() => {});

const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.attributeService.wrapAttributes = jest
.fn()
.mockRejectedValue({ message: 'failed' });
Expand Down Expand Up @@ -698,7 +700,7 @@ describe('Lens App', () => {
});

it('checks for duplicate title before saving', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.attributeService.wrapAttributes = jest
.fn()
.mockReturnValue(Promise.resolve({ savedObjectId: '123' }));
Expand Down Expand Up @@ -765,7 +767,7 @@ describe('Lens App', () => {
});

it('should still be enabled even if the user is missing save permissions', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.application = {
...services.application,
capabilities: {
Expand Down Expand Up @@ -805,7 +807,7 @@ describe('Lens App', () => {
});

it('should open inspect panel', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
const { instance } = await mountWith({ services, preloadedState: { isSaveable: true } });

await runInspect(instance);
Expand Down Expand Up @@ -949,7 +951,7 @@ describe('Lens App', () => {

describe('saved query handling', () => {
it('does not allow saving when the user is missing the saveQuery permission', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.application = {
...services.application,
capabilities: {
Expand Down Expand Up @@ -1186,7 +1188,7 @@ describe('Lens App', () => {
});

it('does not confirm if the user is missing save permissions', async () => {
const services = makeDefaultServices(sessionIdSubject, 'sessionId-1');
const services = makeDefaultServicesForApp();
services.application = {
...services.application,
capabilities: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function getVisualizeFieldSuggestions({
datasourceMap,
datasourceStates,
visualizationMap,
activeVisualization: visualizationMap?.[Object.keys(visualizationMap)[0]] || null,
activeVisualization,
visualizationState: undefined,
visualizeTriggerFieldContext,
});
Expand Down

0 comments on commit 2b569a2

Please sign in to comment.