From 8c6c15ac67a59a338cefae2628bea46ef4343fbd Mon Sep 17 00:00:00 2001 From: Thomas Heymann <190132+thomheymann@users.noreply.github.com> Date: Thu, 9 Jul 2020 10:13:35 +0100 Subject: [PATCH] Clone role button going to edit page (#70768) * Clone role button going to edit page * Added unit tests * Fixed types --- .../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) )} /> );