From a33504b8da9cb87beb447bdd6ca3931b465cf2c4 Mon Sep 17 00:00:00 2001 From: Thomas Heymann <190132+thomheymann@users.noreply.github.com> Date: Mon, 13 Jul 2020 11:59:26 +0100 Subject: [PATCH] Clone role button going to edit page (#70768) (#71218) * Clone role button going to edit page * Added unit tests * Fixed types Co-authored-by: Elastic Machine --- .../public/application/scoped_history.mock.ts | 4 +++- .../roles/roles_grid/roles_grid_page.test.tsx | 22 ++++++++++++------- .../roles/roles_grid/roles_grid_page.tsx | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/core/public/application/scoped_history.mock.ts b/src/core/public/application/scoped_history.mock.ts index 56de97e630bf0..41c72306a99f9 100644 --- a/src/core/public/application/scoped_history.mock.ts +++ b/src/core/public/application/scoped_history.mock.ts @@ -27,7 +27,8 @@ const createMock = ({ hash = '', key, state, -}: Partial = {}) => { + ...overrides +}: Partial = {}) => { const mock: ScopedHistoryMock = { block: jest.fn(), createHref: jest.fn(), @@ -38,6 +39,7 @@ const createMock = ({ listen: jest.fn(), push: jest.fn(), replace: jest.fn(), + ...overrides, action: 'PUSH', length: 1, location: { diff --git a/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.test.tsx b/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.test.tsx index 743510d45107e..d83d5ef3f6468 100644 --- a/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.test.tsx +++ b/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.test.tsx @@ -45,7 +45,9 @@ describe('', () => { let history: ScopedHistory; beforeEach(() => { - history = (scopedHistoryMock.create() as unknown) as ScopedHistory; + history = (scopedHistoryMock.create({ + createHref: jest.fn((location) => location.pathname!), + }) as unknown) as ScopedHistory; apiClientMock = rolesAPIClientMock.create(); apiClientMock.getRoles.mockResolvedValue([ { @@ -135,15 +137,19 @@ describe('', () => { }); expect(wrapper.find(PermissionDenied)).toHaveLength(0); - expect( - wrapper.find('EuiButtonIcon[data-test-subj="edit-role-action-test-role-1"]') - ).toHaveLength(1); - expect( - wrapper.find('EuiButtonIcon[data-test-subj="edit-role-action-disabled-role"]') - ).toHaveLength(1); + + const editButton = wrapper.find('EuiButtonIcon[data-test-subj="edit-role-action-test-role-1"]'); + expect(editButton).toHaveLength(1); + expect(editButton.prop('href')).toBe('/edit/test-role-1'); + + const cloneButton = wrapper.find( + 'EuiButtonIcon[data-test-subj="clone-role-action-test-role-1"]' + ); + expect(cloneButton).toHaveLength(1); + expect(cloneButton.prop('href')).toBe('/clone/test-role-1'); expect( - wrapper.find('EuiButtonIcon[data-test-subj="clone-role-action-test-role-1"]') + wrapper.find('EuiButtonIcon[data-test-subj="edit-role-action-disabled-role"]') ).toHaveLength(1); expect( wrapper.find('EuiButtonIcon[data-test-subj="clone-role-action-disabled-role"]') diff --git a/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.tsx b/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.tsx index 051c16f03d342..c2ea119100722 100644 --- a/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.tsx +++ b/x-pack/plugins/security/public/management/roles/roles_grid/roles_grid_page.tsx @@ -262,7 +262,7 @@ export class RolesGridPage extends Component { iconType={'copy'} {...reactRouterNavigate( this.props.history, - getRoleManagementHref('edit', role.name) + getRoleManagementHref('clone', role.name) )} /> );