Skip to content

Commit

Permalink
Add test for useApplicationCapabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Mar 16, 2022
1 parent 23285f7 commit 9775343
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const KibanaServices = {
getKibanaVersion: jest.fn(() => '8.0.0'),
getConfig: jest.fn(() => null),
};

export const useKibana = jest.fn().mockReturnValue({
services: createStartServicesMock(),
});
Expand Down Expand Up @@ -46,6 +47,9 @@ export const useNavigation = jest.fn().mockReturnValue({
navigateTo: jest.fn(),
});

export const useKibanaCapabilities = jest.fn().mockReturnValue({
visualize: true,
export const useApplicationCapabilities = jest.fn().mockReturnValue({
actions: { crud: true, read: true },
generalCases: { crud: true, read: true },
visualize: { crud: true, read: true },
dashboard: { crud: true, read: true },
});
32 changes: 32 additions & 0 deletions x-pack/plugins/cases/public/common/lib/kibana/hooks.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 React from 'react';
import { renderHook } from '@testing-library/react-hooks';

import { useApplicationCapabilities } from './hooks';
import { TestProviders } from '../../mock';

describe('hooks', () => {
describe('useApplicationCapabilities', () => {
it('should return the correct capabilities', async () => {
const { result } = renderHook<{}, ReturnType<typeof useApplicationCapabilities>>(
() => useApplicationCapabilities(),
{
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
}
);

expect(result.current).toEqual({
actions: { crud: true, read: true },
generalCases: { crud: true, read: true },
visualize: { crud: true, read: true },
dashboard: { crud: true, read: true },
});
});
});
});
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/common/lib/kibana/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export const useApplicationCapabilities = (): UseApplicationCapabilities => {
},
visualize: { crud: !!capabilities.visualize?.save, read: !!capabilities.visualize?.show },
dashboard: {
crud: !!capabilities.dashboard?.show,
read: !!capabilities.dashboard?.createNew,
crud: !!capabilities.dashboard?.createNew,
read: !!capabilities.dashboard?.show,
},
}),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export const createStartServicesMock = (): StartServices => {
new Map([['testAppId', { category: { label: 'Test' } } as unknown as PublicAppInfo]])
);

services.application.capabilities = {
...services.application.capabilities,
actions: { save: true, show: true },
generalCases: { crud_cases: true, read_cases: true },
visualize: { save: true, show: true },
dashboard: { show: true, createNew: true },
};

return services;
};

Expand Down

0 comments on commit 9775343

Please sign in to comment.