Skip to content

Commit

Permalink
Merge branch 'main' into telemetry-schema-validation/allow-null-on-st…
Browse files Browse the repository at this point in the history
…rings
  • Loading branch information
dmlemeshko authored Aug 9, 2023
2 parents a89b7ec + 6673e9d commit 944fb2f
Show file tree
Hide file tree
Showing 220 changed files with 6,770 additions and 3,087 deletions.
4 changes: 1 addition & 3 deletions .buildkite/disabled_jest_configs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[
"x-pack/plugins/watcher/jest.config.js"
]
[]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/plugins/security_solution/server/lib/timeline @elastic/security-threat-hunting-investigations

## Security Solution sub teams - Threat Hunting Explore
/x-pack/plugins/security_solution/common/api/tags @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/api/risk_score @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/search_strategy/security_solution/hosts @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/common/search_strategy/security_solution/matrix_histogram @elastic/security-threat-hunting-explore
Expand Down
3 changes: 3 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ vis_type_timeseries.readOnly: true
vis_type_vislib.readOnly: true
vis_type_xy.readOnly: true
input_control_vis.readOnly: true

# Disable cases in stack management
xpack.cases.stack.enabled: false
31 changes: 20 additions & 11 deletions packages/kbn-check-mappings-update-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,6 @@
}
}
},
"search": {
"dynamic": false,
"properties": {
"title": {
"type": "text"
},
"description": {
"type": "text"
}
}
},
"alert": {
"dynamic": false,
"properties": {
Expand Down Expand Up @@ -931,6 +920,17 @@
}
}
},
"search": {
"dynamic": false,
"properties": {
"title": {
"type": "text"
},
"description": {
"type": "text"
}
}
},
"visualization": {
"dynamic": false,
"properties": {
Expand Down Expand Up @@ -1657,6 +1657,9 @@
"auth_type": {
"type": "keyword"
},
"connection_type": {
"type": "keyword"
},
"username": {
"type": "keyword"
},
Expand Down Expand Up @@ -1743,6 +1746,12 @@
},
"broker_buffer_size": {
"type": "integer"
},
"required_acks": {
"type": "integer"
},
"channel_buffer_size": {
"type": "integer"
}
}
},
Expand Down
13 changes: 12 additions & 1 deletion packages/kbn-user-profile-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export { getUserDisplayName } from './src/user_profile';
export type {
UserProfile,
UserProfileUserInfo,
UserProfileAvatarData,
GetUserDisplayNameParams,
} from './src/user_profile';
export type {
UserProfileData,
UserSettingsData,
DarkModeValue,
UserProfileAvatarData,
} from './src/types';
export { useUpdateUserProfile, type UpdateUserProfileHook } from './src/hooks';
export {
UserProfilesKibanaProvider,
UserProfilesProvider,
type UserProfilesKibanaDependencies,
} from './src/services';
9 changes: 9 additions & 0 deletions packages/kbn-user-profile-components/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { useUpdateUserProfile, type UpdateUserProfileHook } from './use_update_user_profile';
Original file line number Diff line number Diff line change
@@ -1,58 +1,82 @@
/*
* 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.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { act, renderHook } from '@testing-library/react-hooks';
import { BehaviorSubject, first, lastValueFrom } from 'rxjs';

import { coreMock } from '@kbn/core/public/mocks';

import { getUseUpdateUserProfile } from './use_update_user_profile';
import { UserProfileAPIClient } from './user_profile_api_client';
import React from 'react';
import { act, renderHook, type WrapperComponent } from '@testing-library/react-hooks';
import { BehaviorSubject, first, lastValueFrom, of } from 'rxjs';

const { notifications, http } = coreMock.createStart();
const userProfileApiClient = new UserProfileAPIClient(http);
const useUpdateUserProfile = getUseUpdateUserProfile({
apiClient: userProfileApiClient,
notifications,
});
import { coreMock } from '@kbn/core/public/mocks';

describe('useUpdateUserProfile', () => {
let spy: jest.SpyInstance;
import { useUpdateUserProfile } from './use_update_user_profile';
import { UserProfilesKibanaProvider } from '../services';

const core = coreMock.createStart();
const security = {
authc: {},
navControlService: {},
userProfiles: {
getCurrent: jest.fn(),
bulkGet: jest.fn(),
suggest: jest.fn(),
update: jest.fn(),
userProfile$: of({}),
},
uiApi: {},
};

const { http, notifications } = core;

const wrapper: WrapperComponent<void> = ({ children }) => (
<UserProfilesKibanaProvider
core={core}
security={security}
toMountPoint={() => () => () => undefined}
>
{children}
</UserProfilesKibanaProvider>
);

describe('useUpdateUserProfile() hook', () => {
const updateUserProfiles = jest.fn();

beforeEach(() => {
spy = jest.spyOn(userProfileApiClient, 'update');
security.userProfiles = {
...security.userProfiles,
update: updateUserProfiles,
userProfile$: of({}),
};

updateUserProfiles.mockReset().mockResolvedValue({});
http.get.mockReset();
http.post.mockReset().mockResolvedValue(undefined);
notifications.toasts.addSuccess.mockReset();
});

afterEach(() => {
spy.mockRestore();
});

test('should call the apiClient with the updated user profile data', async () => {
const { result } = renderHook(() => useUpdateUserProfile());
const { result } = renderHook(() => useUpdateUserProfile(), { wrapper });
const { update } = result.current;

await act(async () => {
update({ userSettings: { darkMode: 'dark' } });
});

expect(spy).toHaveBeenCalledWith({ userSettings: { darkMode: 'dark' } });
expect(updateUserProfiles).toHaveBeenCalledWith({ userSettings: { darkMode: 'dark' } });
});

test('should update the isLoading state while updating', async () => {
const { result, waitForNextUpdate } = renderHook(() => useUpdateUserProfile());
const { update } = result.current;
const httpPostDone = new BehaviorSubject(false);

http.post.mockImplementationOnce(async () => {
await lastValueFrom(httpPostDone.pipe(first((v) => v === true)));
const updateDone = new BehaviorSubject(false);
updateUserProfiles.mockImplementationOnce(async () => {
await lastValueFrom(updateDone.pipe(first((v) => v === true)));
});

const { result, waitForNextUpdate } = renderHook(() => useUpdateUserProfile(), { wrapper });
const { update } = result.current;

expect(result.current.isLoading).toBeFalsy();

await act(async () => {
Expand All @@ -61,16 +85,18 @@ describe('useUpdateUserProfile', () => {

expect(result.current.isLoading).toBeTruthy();

httpPostDone.next(true); // Resolve the http.post promise
updateDone.next(true); // Resolve the http.post promise
await waitForNextUpdate();

expect(result.current.isLoading).toBeFalsy();
});

test('should show a success notification by default', async () => {
const { result } = renderHook(() => useUpdateUserProfile());
const { result } = renderHook(() => useUpdateUserProfile(), { wrapper });
const { update } = result.current;

expect(notifications.toasts.addSuccess).not.toHaveBeenCalled();

await act(async () => {
await update({ userSettings: { darkMode: 'dark' } });
});
Expand All @@ -88,11 +114,7 @@ describe('useUpdateUserProfile', () => {
return true;
};

const { result } = renderHook(() =>
useUpdateUserProfile({
pageReloadChecker,
})
);
const { result } = renderHook(() => useUpdateUserProfile({ pageReloadChecker }), { wrapper });
const { update } = result.current;

await act(async () => {
Expand All @@ -114,21 +136,17 @@ describe('useUpdateUserProfile', () => {
const pageReloadChecker = jest.fn();

const initialValue = { foo: 'bar' };
http.get.mockReset().mockResolvedValue({ data: initialValue });
const userProfileApiClient2 = new UserProfileAPIClient(http);
await userProfileApiClient2.getCurrent(); // Sets the initial value of the userProfile$ Observable

const { result } = renderHook(() =>
getUseUpdateUserProfile({
apiClient: userProfileApiClient2,
notifications,
})({
pageReloadChecker,
})
);

security.userProfiles = {
...security.userProfiles,
userProfile$: of(initialValue),
};

const { result } = renderHook(() => useUpdateUserProfile({ pageReloadChecker }), { wrapper });
const { update } = result.current;

const nextValue = { userSettings: { darkMode: 'light' as const } };

await act(async () => {
await update(nextValue);
});
Expand Down
Loading

0 comments on commit 944fb2f

Please sign in to comment.