-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
157 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/lens/public/react_embeddable/initializers/initialize_edit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { faker } from '@faker-js/faker'; | ||
import { initializeEditApi } from './initialize_edit'; | ||
import { | ||
getLensApiMock, | ||
getLensInternalApiMock, | ||
getLensRuntimeStateMock, | ||
makeEmbeddableServices, | ||
} from '../mocks'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { ApplicationStart } from '@kbn/core/public'; | ||
import { LensEmbeddableStartServices } from '../types'; | ||
|
||
function createEditApi(servicesOverrides: Partial<LensEmbeddableStartServices> = {}) { | ||
const internalApi = getLensInternalApiMock(); | ||
const runtimeState = getLensRuntimeStateMock(); | ||
const api = getLensApiMock(); | ||
const services = { | ||
...makeEmbeddableServices(new BehaviorSubject<string>(''), undefined, { | ||
visOverrides: { id: 'lnsXY' }, | ||
dataOverrides: { id: 'formBased' }, | ||
}), | ||
...servicesOverrides, | ||
}; | ||
return initializeEditApi( | ||
faker.string.uuid(), | ||
runtimeState, | ||
() => runtimeState, | ||
internalApi, | ||
api, | ||
api, | ||
() => false, // DSL based | ||
services, | ||
{ getAppContext: () => ({ currentAppId: 'lens' }), viewMode: new BehaviorSubject('edit') } | ||
); | ||
} | ||
|
||
describe('edit features', () => { | ||
it('should be editable if visualize library privileges allow it', () => { | ||
const editApi = createEditApi(); | ||
expect(editApi.api.isEditingEnabled()).toBe(true); | ||
}); | ||
|
||
it('should not be editable if visualize library privileges do not allow it', () => { | ||
const editApi = createEditApi({ | ||
capabilities: { | ||
visualize: { | ||
// cannot save | ||
save: false, | ||
saveQuery: true, | ||
// cannot see the visualization | ||
show: true, | ||
createShortUrl: true, | ||
}, | ||
dashboard: { | ||
// cannot edit in dashboard | ||
showWriteControls: false, | ||
}, | ||
} as unknown as ApplicationStart['capabilities'], | ||
}); | ||
|
||
expect(editApi.api.isEditingEnabled()).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters