Skip to content

Commit

Permalink
Clone role button going to edit page (#70768) (#71218)
Browse files Browse the repository at this point in the history
* Clone role button going to edit page

* Added unit tests

* Fixed types

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
thomheymann and elasticmachine authored Jul 13, 2020
1 parent aaf0abe commit a33504b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/core/public/application/scoped_history.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const createMock = ({
hash = '',
key,
state,
}: Partial<Location> = {}) => {
...overrides
}: Partial<Location & ScopedHistoryMock> = {}) => {
const mock: ScopedHistoryMock = {
block: jest.fn(),
createHref: jest.fn(),
Expand All @@ -38,6 +39,7 @@ const createMock = ({
listen: jest.fn(),
push: jest.fn(),
replace: jest.fn(),
...overrides,
action: 'PUSH',
length: 1,
location: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('<RolesGridPage />', () => {
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([
{
Expand Down Expand Up @@ -135,15 +137,19 @@ describe('<RolesGridPage />', () => {
});

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"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class RolesGridPage extends Component<Props, State> {
iconType={'copy'}
{...reactRouterNavigate(
this.props.history,
getRoleManagementHref('edit', role.name)
getRoleManagementHref('clone', role.name)
)}
/>
);
Expand Down

0 comments on commit a33504b

Please sign in to comment.