Skip to content

Commit

Permalink
Update Account Settings with personal layout + write tests
Browse files Browse the repository at this point in the history
+ add related KibanaLogic branch coverage
  • Loading branch information
cee-chen committed Jun 18, 2021
1 parent 7f42518 commit 6c305e5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
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', () => {
mountKibanaLogic({ ...mockKibanaValues, security: undefined } as any);

expect(KibanaLogic.values.security).toEqual({});
});

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', () => {
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>
);
};

0 comments on commit 6c305e5

Please sign in to comment.