Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workplace Search] Convert Sources pages to new page template (+ personal dashboard) #102592

Merged
merged 15 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ describe('KibanaLogic', () => {
expect(KibanaLogic.values.config).toEqual({});
});

it('gracefully handles disabled security', () => {
yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved
mountKibanaLogic({ ...mockKibanaValues, security: undefined } as any);
yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved

yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved
expect(KibanaLogic.values.security).toEqual({});
});
yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved

it('gracefully handles non-cloud installs', () => {
mountKibanaLogic({ ...mockKibanaValues, cloud: undefined } as any);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 '../../../__mocks__/shallow_useeffect.mock';
import { mockKibanaValues } from '../../../__mocks__/kea_logic';

import React from 'react';

import { shallow } from 'enzyme';

import { AccountSettings } from './';

describe('AccountSettings', () => {
yakhinvadim marked this conversation as resolved.
Show resolved Hide resolved
const {
security: {
authc: { getCurrentUser },
uiApi: {
components: { getPersonalInfo, getChangePassword },
},
},
} = mockKibanaValues;

const mockCurrentUser = (user?: unknown) =>
(getCurrentUser as jest.Mock).mockReturnValue(Promise.resolve(user));

beforeAll(() => {
mockCurrentUser();
});

it('gets the current user on mount', () => {
shallow(<AccountSettings />);

expect(getCurrentUser).toHaveBeenCalled();
});

it('does not render if the current user does not exist', async () => {
mockCurrentUser(null);
const wrapper = await shallow(<AccountSettings />);

expect(wrapper.isEmptyRender()).toBe(true);
});

it('renders the security UI components when the user exists', async () => {
mockCurrentUser({ username: 'mock user' });
(getPersonalInfo as jest.Mock).mockReturnValue(<div data-test-subj="PersonalInfo" />);
(getChangePassword as jest.Mock).mockReturnValue(<div data-test-subj="ChangePassword" />);

const wrapper = await shallow(<AccountSettings />);

expect(wrapper.childAt(0).dive().find('[data-test-subj="PersonalInfo"]')).toHaveLength(1);
expect(wrapper.childAt(1).dive().find('[data-test-subj="ChangePassword"]')).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useValues } from 'kea';

import type { AuthenticatedUser } from '../../../../../../security/public';
import { KibanaLogic } from '../../../shared/kibana/kibana_logic';
import { PersonalDashboardLayout } from '../../components/layout';
import { ACCOUNT_SETTINGS_TITLE } from '../../constants';

export const AccountSettings: React.FC = () => {
const { security } = useValues(KibanaLogic);
Expand All @@ -31,9 +33,9 @@ export const AccountSettings: React.FC = () => {
}

return (
<>
<PersonalDashboardLayout pageChrome={[ACCOUNT_SETTINGS_TITLE]}>
<PersonalInfo user={currentUser} />
<ChangePassword user={currentUser} />
</>
</PersonalDashboardLayout>
);
};