Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
Signed-off-by: at670475 <andrea.tabone@broadcom.com>
  • Loading branch information
taban03 committed Jul 25, 2023
1 parent cc62067 commit a1bcf62
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
margin-right: auto;
background: #FFFFFF;
border: 1px solid #C9C8C5;
.MuiFormControl-root {
display: flex;
}
}

#grid-container ,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export default class DetailPage extends Component {
handleLinkClick = (e, id) => {
e.preventDefault();
const elementToView = document.querySelector(id);
elementToView.scrollIntoView();
if (elementToView) {
elementToView.scrollIntoView();
}
};

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,51 @@ describe('>>> Detailed Page component tests', () => {
);
expect(wrapper.find('#right-resources-menu').exists()).toEqual(true);
});

it('should click', () => {
process.env.REACT_APP_API_PORTAL = true;
const fetchTilesStart = jest.fn();
const fetchNewTiles = jest.fn();
const history = {
push: jest.fn(),
pathname: jest.fn(),
};
const mockHandleLinkClick = jest.fn();
const mockEvent = { preventDefault: jest.fn() };
const mockElementToView = { scrollIntoView: jest.fn() };
document.querySelector = jest.fn().mockReturnValue(mockElementToView);
const wrapper = shallow(
<DetailPage
tiles={[tile]}
services={tile.services}
currentTileId="apicatalog"
handleLinkClick={mockHandleLinkClick}
fetchTilesStart={fetchTilesStart}
fetchNewTiles={fetchNewTiles}
fetchTilesStop={jest.fn()}
match={match}
history={history}
/>
);
// Simulate a click event on the Link component, providing the id as the second argument
wrapper.instance().handleLinkClick(mockEvent, '#swagger-label');
expect(mockEvent.preventDefault).toHaveBeenCalled();
expect(document.querySelector).toHaveBeenCalledWith('#swagger-label');
expect(mockElementToView.scrollIntoView).toHaveBeenCalled();

wrapper.instance().handleLinkClick(mockEvent, '#use-cases-label');
expect(mockEvent.preventDefault).toHaveBeenCalled();
expect(document.querySelector).toHaveBeenCalledWith('#use-cases-label');
expect(mockElementToView.scrollIntoView).toHaveBeenCalled();

wrapper.instance().handleLinkClick(mockEvent, '#videos-label');
expect(mockEvent.preventDefault).toHaveBeenCalled();
expect(document.querySelector).toHaveBeenCalledWith('#videos-label');
expect(mockElementToView.scrollIntoView).toHaveBeenCalled();

wrapper.instance().handleLinkClick(mockEvent, '#tutorials-label');
expect(mockEvent.preventDefault).toHaveBeenCalled();
expect(document.querySelector).toHaveBeenCalledWith('#tutorials-label');
expect(mockElementToView.scrollIntoView).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ body .detail-content {
#right-resources-menu {
position: relative;
float: right;
display: flex;
// Hidden for the timebeing until we won't have additional content
display: none;
//display: flex;
flex-direction: column;
align-items: flex-start;
border-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,15 @@ describe('>>> ServiceVersionDiff component tests', () => {
serviceVersionDiff.find('[data-testid="diff-button"]').first().simulate('click');
expect(getDiff.mock.calls.length).toBe(1);
});

it('should set current tile id with default version', () => {
const getDiff = jest.fn();
const serviceVersionDiff = shallow(
<ServiceVersionDiff getDiff={getDiff} serviceId="service" versions={['v1', 'v2']} version2="v2" />
);
serviceVersionDiff.setState({ defaultVersion: 'v1' });

serviceVersionDiff.find('[data-testid="diff-button"]').first().simulate('click');
expect(getDiff.mock.calls.length).toBe(1);
});
});

0 comments on commit a1bcf62

Please sign in to comment.