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

Update FooterSitesButton.jsx to use UniversalLink #452

Merged
merged 2 commits into from
Aug 29, 2024
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
86 changes: 51 additions & 35 deletions src/ui/Footer/Footer.stories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { render } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import { Default } from './Footer.stories';
import { Provider } from 'react-redux';
import Footer from './Footer';
import '@testing-library/jest-dom/extend-expect';
import configureStore from 'redux-mock-store';

describe('Default', () => {
let history;
Expand All @@ -22,11 +24,21 @@ describe('Default', () => {
});
});

const mockStore = configureStore();
const store = mockStore({
intl: {
locale: 'en',
messages: {},
},
});

it('renders correctly', () => {
const { container } = render(
<Router history={history}>
<Default {...Default.args} />
</Router>,
<Provider store={store}>
<Router history={history}>
<Default {...Default.args} />
</Router>
</Provider>,
);

expect(container.querySelector('#footer')).toBeInTheDocument();
Expand All @@ -49,21 +61,23 @@ describe('Default', () => {

it('renders correctly', () => {
const { container, getByText } = render(
<Router history={history}>
<Footer>
<Footer.SubFooter {...Default.args}>
<div>SubFooter test</div>
</Footer.SubFooter>
<Footer.Header>{Default.args.header}</Footer.Header>
<Footer.Sites sites={Default.args.sites}>
<div>Sites test</div>
</Footer.Sites>
<Footer.Actions
actions={Default.args.actions}
copyright={Default.args.copyright}
/>
</Footer>
</Router>,
<Provider store={store}>
<Router history={history}>
<Footer>
<Footer.SubFooter {...Default.args}>
<div>SubFooter test</div>
</Footer.SubFooter>
<Footer.Header>{Default.args.header}</Footer.Header>
<Footer.Sites sites={Default.args.sites}>
<div>Sites test</div>
</Footer.Sites>
<Footer.Actions
actions={Default.args.actions}
copyright={Default.args.copyright}
/>
</Footer>
</Router>
</Provider>,
);

expect(container.querySelector('#footer')).toBeInTheDocument();
Expand All @@ -82,23 +96,25 @@ describe('Default', () => {

it('renders correctly', () => {
const { container, getByText } = render(
<Router history={history}>
<Footer>
<Footer.SubFooter
{...Default.args}
description={'test description'}
social={undefined}
/>
<Footer.Header>{Default.args.header}</Footer.Header>
<Footer.Sites sites={Default.args.sites} />
<Footer.Actions
actions={Default.args.actions}
copyright={Default.args.copyright}
>
<div>Actions test</div>
</Footer.Actions>
</Footer>
</Router>,
<Provider store={store}>
<Router history={history}>
<Footer>
<Footer.SubFooter
{...Default.args}
description={'test description'}
social={undefined}
/>
<Footer.Header>{Default.args.header}</Footer.Header>
<Footer.Sites sites={Default.args.sites} />
<Footer.Actions
actions={Default.args.actions}
copyright={Default.args.copyright}
>
<div>Actions test</div>
</Footer.Actions>
</Footer>
</Router>
</Provider>,
);

expect(container.querySelector('#footer')).toBeInTheDocument();
Expand Down
19 changes: 5 additions & 14 deletions src/ui/Footer/FooterSitesButton.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import { Button } from 'semantic-ui-react';
import PropTypes from 'prop-types';
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
import { UniversalLink } from '@plone/volto/components';

const SitesButton = (props) => {
if (props.children) {
Expand All @@ -11,20 +9,13 @@ const SitesButton = (props) => {
//fallback to props
return (
<div className="theme-sites">
<Button
<UniversalLink
href={props.hrefButton}
className="theme-sites-button"
onClick={() => {
if (__CLIENT__ && window) {
window.location.assign(
isInternalURL(props.hrefButton)
? flattenToAppURL(props.hrefButton)
: props.hrefButton,
);
}
}}
openLinkInNewTab={false}
>
{props.buttonName}
</Button>
</UniversalLink>
</div>
);
};
Expand Down
Loading