Skip to content

Commit

Permalink
fix(ESSNTL-4196): Tie URLs to chrome isBeta (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored Mar 30, 2023
1 parent 487d9cb commit 7c686e5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
23 changes: 23 additions & 0 deletions src/Utilities/ChromeLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';

const ChromeLoader = ({ children }) => {
const chrome = useChrome();

return <>
{React.Children.map(children, child => {
if (React.isValidElement(child)) {
return React.cloneElement(child, { chrome });
}

return child;
})}
</>;
};

ChromeLoader.propTypes = {
children: PropTypes.any
};

export default ChromeLoader;
47 changes: 23 additions & 24 deletions src/components/InventoryGroupDetail/GroupDetailInfo.cy.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import { mount } from '@cypress/react';
import React from 'react';
import GroupDetailInfo from './GroupDetailInfo';
import { GroupDetailInfo } from './GroupDetailInfo';

const mountPage = () =>
const mountPage = (params) =>
mount(
<GroupDetailInfo />
<GroupDetailInfo {...params}/>
);

before(() => {
cy.window().then(
(window) =>
(window.insights = {
chrome: {
isProd: false,
auth: {
getUser: () => {
return Promise.resolve({});
}
}
}
})
);
});

describe('group detail information page', () => {
it('Title is rendered', () => {
mountPage();
beforeEach(() => {
mountPage({ chrome: { isBeta: () => false } });
});

it('title is rendered', () => {
cy.get('div[class="pf-c-card__title pf-c-title pf-m-lg card-title"]').should('have.text', 'User access configuration');
});

it('button is present', () => {
mountPage();
cy.get('button[class="pf-c-button pf-m-secondary"]').should('have.text', 'Manage access');
cy.get('a[class="pf-c-button pf-m-secondary"]').should('have.text', 'Manage access');
});

it('card text is present', () => {
mountPage();
cy.get('div[class="pf-c-card__body"]').should
('have.text', 'Manage your inventory group user access configuration under Identity & Access Management > User Access.');
});

describe('links', () => {
it('in stable environment', () => {
mountPage({ chrome: { isBeta: () => false } });
cy.get('a').should('have.attr', 'href', '/iam/user-access');
});

it('in beta environment', () => {
mountPage({ chrome: { isBeta: () => true } });
cy.get('a').should('have.attr', 'href', '/beta/iam/user-access');
});
});
});
35 changes: 23 additions & 12 deletions src/components/InventoryGroupDetail/GroupDetailInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,41 @@ import {
CardHeader,
CardActions } from '@patternfly/react-core';
import React from 'react';
import PropTypes from 'prop-types';
import ChromeLoader from '../../Utilities/ChromeLoader';

const GroupDetailInfo = () => {
const address = window.location.href.includes('beta') ? '/beta/iam/user-access' : '/iam/user-access';
const GroupDetailInfo = ({ chrome }) => {
const path = `${chrome.isBeta() ? '/beta' : ''}/iam/user-access`;

return (
<Card>
<CardHeader>
<CardActions>
<Button variant="secondary" >
<a
href={`${window.location.origin}/iam/user-access`}
>Manage access</a>
<Button component="a" href={path} variant="secondary">
Manage access
</Button>
</CardActions>
<CardTitle className="pf-c-title pf-m-lg card-title">User access configuration</CardTitle>
<CardTitle className="pf-c-title pf-m-lg card-title">
User access configuration
</CardTitle>
</CardHeader>
<CardBody>
Manage your inventory group user access configuration under
<a
href={`${window.location.origin}${address}`}
> Identity & Access Management {'>'} User Access.</a>
Manage your inventory group user access configuration under
<a href={path}> Identity & Access Management {'>'} User Access.</a>
</CardBody>
</Card>
);
};

export default GroupDetailInfo;
GroupDetailInfo.propTypes = {
chrome: PropTypes.object
};

const GroupDetailInfoWithChrome = () => (
<ChromeLoader>
<GroupDetailInfo />
</ChromeLoader>
);

export { GroupDetailInfo };
export default GroupDetailInfoWithChrome;

0 comments on commit 7c686e5

Please sign in to comment.