-
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
1 parent
e6e8eb9
commit d013587
Showing
6 changed files
with
87 additions
and
45 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
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/fleet/public/applications/fleet/mock/fleet_start_services.tsx
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,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
import { coreMock } from '../../../../../../../src/core/public/mocks'; | ||
import { createStartDepsMock } from './plugin_dependencies'; | ||
import { IStorage, Storage } from '../../../../../../../src/plugins/kibana_utils/public'; | ||
import { MockedKeys } from '../../../../../../../packages/kbn-utility-types/jest/index'; | ||
import { setHttpClient } from '../hooks/use_request'; | ||
import { MockedFleetStartServices } from './types'; | ||
|
||
// Taken from core. See: src/plugins/kibana_utils/public/storage/storage.test.ts | ||
const createMockStore = (): MockedKeys<IStorage> => { | ||
let store: Record<string, any> = {}; | ||
return { | ||
getItem: jest.fn().mockImplementation((key) => store[key]), | ||
setItem: jest.fn().mockImplementation((key, value) => (store[key] = value)), | ||
removeItem: jest.fn().mockImplementation((key: string) => delete store[key]), | ||
clear: jest.fn().mockImplementation(() => (store = {})), | ||
}; | ||
}; | ||
|
||
const configureStartServices = (services: MockedFleetStartServices): void => { | ||
// Store the http for use by useRequest | ||
setHttpClient(services.http); | ||
|
||
// Set Fleet available capabilities | ||
services.application.capabilities = { | ||
...services.application.capabilities, | ||
fleet: { | ||
read: true, | ||
write: true, | ||
}, | ||
}; | ||
|
||
// Setup the `i18n.Context` component | ||
services.i18n.Context.mockImplementation(({ children }: { children: React.ReactNode }) => ( | ||
<I18nProvider>{children}</I18nProvider> | ||
)); | ||
}; | ||
|
||
export const createStartServices = (basePath: string = '/mock'): MockedFleetStartServices => { | ||
const startServices: MockedFleetStartServices = { | ||
...coreMock.createStart({ basePath }), | ||
...createStartDepsMock(), | ||
storage: new Storage(createMockStore()) as jest.Mocked<Storage>, | ||
}; | ||
|
||
configureStartServices(startServices); | ||
|
||
return startServices; | ||
}; |
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
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/fleet/public/applications/fleet/mock/types.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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { MockedKeys } from '../../../../../../../packages/kbn-utility-types/jest/index'; | ||
import { FleetSetupDeps, FleetStartDeps, FleetStartServices } from '../../../plugin'; | ||
|
||
export type MockedFleetStartServices = MockedKeys<FleetStartServices>; | ||
|
||
export type MockedFleetSetupDeps = MockedKeys<FleetSetupDeps>; | ||
|
||
export type MockedFleetStartDeps = MockedKeys<FleetStartDeps>; |
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