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

refactor(RHIF-125): Apply useChrome everywhere #1801

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src/components/GeneralInfo/EditButton/EditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';

import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';

import { PencilAltIcon } from '@patternfly/react-icons';

Expand Down Expand Up @@ -46,7 +47,9 @@ EditButtonUnknownPermissions.propTypes = {
};

const EditButtonWrapper = ({ writePermissions, ...props }) => {
if (insights.chrome.isProd || writePermissions || permissionsCache) {
const { isProd } = useChrome();

if (isProd?.() || writePermissions || permissionsCache) {
return <InnerButton {...props} />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PencilAltIcon } from '@patternfly/react-icons';
import EditButton from './EditButton';

jest.mock('@redhat-cloud-services/frontend-components-utilities/RBACHook', () => ({
esModule: true,
__esModule: true,
usePermissionsWithContext: () => ({ hasAccess: false })
}));

Expand Down Expand Up @@ -39,21 +39,6 @@ describe('EditButton with no access', () => {
expect(wrapper.find('a')).toHaveLength(0);
});

it('render on production', () => {
const tmp = insights.chrome.isProd;
insights.chrome.isProd = true;

const wrapper = mount(<EditButton
onClick={onClick}
link={link}
/>);

expect(wrapper.find(PencilAltIcon)).toHaveLength(1);
expect(wrapper.find('a').props().href).toEqual('http://localhost:5000//some-link');

insights.chrome.isProd = tmp;
});

it('render when write permissions are set to true', () => {
const wrapper = mount(<EditButton
onClick={onClick}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { mount } from 'enzyme';
import { PencilAltIcon } from '@patternfly/react-icons';

import EditButton from './EditButton';

jest.mock('@redhat-cloud-services/frontend-components-utilities/RBACHook', () => ({
__esModule: true,
usePermissionsWithContext: () => ({ hasAccess: false })
}));

jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
__esModule: true,
default: () => ({
isProd: () => true
})
}));

describe('EditButton with no access', () => {
let onClick;
let link;

beforeEach(() => {
onClick = jest.fn();
link = 'some-link';
});

it('render on production', () => {
const wrapper = mount(<EditButton
onClick={onClick}
link={link}
/>);

expect(wrapper.find(PencilAltIcon)).toHaveLength(1);
expect(wrapper.find('a').props().href).toEqual('http://localhost:5000//some-link');
});
});
2 changes: 1 addition & 1 deletion src/routes/InventoryDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Inventory = () => {
}

useEffect(() => {
insights?.chrome?.appObjectId?.(entity?.id);
chrome?.appObjectId?.(entity?.id);
}, [entity?.id]);

const onTabSelect = useCallback((_, activeApp, appName) => {
Expand Down