Skip to content

Commit

Permalink
Merge pull request #267 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Oct 11, 2024
2 parents 711b485 + d4544c9 commit 60d57a5
Show file tree
Hide file tree
Showing 27 changed files with 1,264 additions and 47 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

### [2.3.0](https://github.com/eea/volto-eea-website-theme/compare/2.2.2...2.3.0) - 9 September 2024
### [2.4.0](https://github.com/eea/volto-eea-website-theme/compare/2.3.0...2.4.0) - 11 October 2024

#### :bug: Bug Fixes

- fix: add subsite_css class when not undefined [nileshgulia1 - [`db3f80f`](https://github.com/eea/volto-eea-website-theme/commit/db3f80f9dac34f528030d1d2a2f858555059879e)]

#### :hammer_and_wrench: Others

- Increase test coverage [dobri1408 - [`e2d46a9`](https://github.com/eea/volto-eea-website-theme/commit/e2d46a981c6f50980f0b0bf1f35b2d03121f3c88)]
- Update package.json [Ichim David - [`24ea8f0`](https://github.com/eea/volto-eea-website-theme/commit/24ea8f0ef7c474bcf171f4720465e12a0d600b46)]
### [2.3.0](https://github.com/eea/volto-eea-website-theme/compare/2.2.2...2.3.0) - 13 September 2024

#### :house: Internal changes

Expand Down
70 changes: 67 additions & 3 deletions cypress/e2e/01-block-basics.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ describe('Blocks Tests', () => {
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser .title').contains('Media').click();
cy.get('.content.active.media .button.image').contains('Image').click();
cy.get('.block.image .ui.input input[type="text"]').type("https://eea.github.io/volto-eea-design-system/img/eea_icon.png{enter}");
cy.get('.block.image .ui.input input[type="text"]').type(
'https://eea.github.io/volto-eea-design-system/img/eea_icon.png{enter}',
);

cy.get('.align-buttons .ui.basic.icon.button').first().click();
cy.get('#blockform-fieldset-styling').click();
Expand All @@ -36,11 +38,73 @@ describe('Blocks Tests', () => {
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// check banner rss link
cy.get('.button.rssfeed').should('have.attr', 'href', '/cypress/my-page/rss');
cy.get('.button.rssfeed').should(
'have.attr',
'href',
'/cypress/my-page/rss',
);
cy.get('.button.rssfeed').contains('RSS');

// then the page view should contain our changes
cy.contains('My Add-on Page');
cy.get('.block.image.align.left img.top').should('have.attr', 'src', 'https://eea.github.io/volto-eea-design-system/img/eea_icon.png');
cy.get('.block.image.align.left img.top').should(
'have.attr',
'src',
'https://eea.github.io/volto-eea-design-system/img/eea_icon.png',
);
});

//Fails because we don't add navigation block by default

it('Add Navigation Block', () => {
// Change page title
cy.clearSlateTitle();
cy.getSlateTitle().type('My Add-on Page');

cy.get('.documentFirstHeading').contains('My Add-on Page');

cy.getSlate().click();

// Add Navigation block
cy.get('.ui.basic.icon.button.block-add-button').first().click();
cy.get('.blocks-chooser input').type('Navigation');
cy.get('.blocks-chooser .contextNavigation').click();
cy.get('#field-name').type('Nav title');
cy.get(
'.field-wrapper-includeTop > .grid > :nth-child(1) > .twelve > .wrapper > .ui > label',
).click();
// cy.get(
// '.field-wrapper-currentFolderOnly > .grid > :nth-child(1) > .twelve > .wrapper > .ui > label',
// ).click();
cy.get(
'.field-wrapper-no_icons > .grid > :nth-child(1) > .twelve > .wrapper > .ui > label',
).click();
cy.get(
'.field-wrapper-no_thumbs > .grid > :nth-child(1) > .twelve > .wrapper > .ui > label',
).click();

// Save
cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// // then the page view should contain our changes
cy.get('.context-navigation-header').contains('Nav title');

// Edit to select Accordion variation
cy.get('.toolbar-actions .edit').click();
cy.get('.block-editor-contextNavigation').click();
cy.get(
'#sidebar-properties .field-wrapper-variation .react-select__value-container',
).click();
cy.get('.field-wrapper-variation .react-select__option')
.contains('Accordion')
.click();

cy.get('#toolbar-save').click();
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');

// then the page view should contain our changes
cy.get('.accordion-header').contains('Nav title');
cy.get('.accordion-header').click();
});
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-eea-website-theme",
"version": "2.3.0",
"version": "2.4.0",
"description": "@eeacms/volto-eea-website-theme: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand All @@ -14,6 +14,7 @@
"react"
],
"addons": [
"@eeacms/volto-block-toc",
"@eeacms/volto-group-block",
"@eeacms/volto-eea-design-system",
"volto-subsites"
Expand All @@ -23,6 +24,7 @@
"url": "[email protected]:eea/volto-eea-website-theme.git"
},
"dependencies": {
"@eeacms/volto-block-toc": "*",
"@eeacms/volto-block-style": "*",
"@eeacms/volto-eea-design-system": "*",
"@eeacms/volto-group-block": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { EditSchema } from './schema';
import { SidebarPortal } from '@plone/volto/components';
import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm';

import ContextNavigationView from './ContextNavigationView';

const ContextNavigationFillEdit = (props) => {
const contentTypes = props.properties?.['@components']?.types;
const availableTypes = React.useMemo(
() => contentTypes?.map((type) => [type.id, type.title || type.name]),
[contentTypes],
);

const schema = React.useMemo(
() => EditSchema({ availableTypes }),
[availableTypes],
);

return (
<>
<h3>Context navigation</h3>
<ContextNavigationView {...props} mode="edit" />{' '}
<SidebarPortal selected={props.selected}>
<BlockDataForm
schema={schema}
title={schema.title}
onChangeField={(id, value) => {
props.onChangeBlock(props.block, {
...props.data,
[id]: value,
});
}}
onChangeBlock={props.onChangeBlock}
formData={props.data}
block={props.block}
navRoot={props.navRoot}
contentType={props.contentType}
/>
</SidebarPortal>
</>
);
};

export default ContextNavigationFillEdit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import ContextNavigationEdit from './ContextNavigationEdit';
import { Router } from 'react-router-dom';
import { Provider } from 'react-intl-redux';
import configureStore from 'redux-mock-store';
import { createMemoryHistory } from 'history';
import '@testing-library/jest-dom/extend-expect';

jest.mock('@plone/volto/components', () => ({
InlineForm: ({ onChangeField }) => (
<div>
<p>InlineForm</p>
<input id="test" onChange={onChangeField} />
</div>
),
SidebarPortal: ({ children, selected }) =>
selected ? (
<div>
<div>SidebarPortal</div>
{children}
</div>
) : null,
}));

jest.mock('@plone/volto/components/theme/Navigation/ContextNavigation', () => {
return {
__esModule: true,
default: ({ params }) => {
return <div>ConnectedContextNavigation {params.root_path}</div>;
},
};
});

jest.mock('@plone/volto/helpers', () => ({
withBlockExtensions: jest.fn((Component) => Component),
emptyBlocksForm: jest.fn(),
getBlocksLayoutFieldname: () => 'blocks_layout',
withVariationSchemaEnhancer: jest.fn((Component) => Component),
}));

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

describe('ContextNavigationEdit', () => {
it('renders corectly', () => {
const history = createMemoryHistory();
const { getByText, queryByText } = render(
<Provider store={store}>
<Router history={history}>
<ContextNavigationEdit selected={false} />
</Router>
,
</Provider>,
);

expect(getByText('Context navigation')).toBeInTheDocument();
expect(getByText('ConnectedContextNavigation')).toBeInTheDocument();
expect(queryByText('InlineForm')).toBeNull();
expect(queryByText('SidebarPortal')).toBeNull();
});

it('renders corectly', () => {
const history = createMemoryHistory();
const { container, getByText } = render(
<Provider store={store}>
<Router history={history}>
<ContextNavigationEdit selected={true} onChangeBlock={() => {}} />
</Router>
,
</Provider>,
);

expect(getByText('Context navigation')).toBeInTheDocument();
expect(getByText('ConnectedContextNavigation')).toBeInTheDocument();
expect(getByText('InlineForm')).toBeInTheDocument();
expect(getByText('SidebarPortal')).toBeInTheDocument();

fireEvent.change(container.querySelector('#test'), {
target: { value: 'test' },
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { flattenToAppURL, withBlockExtensions } from '@plone/volto/helpers';
import DefaultTemplate from './variations/Default';

const ContextNavigationView = (props = {}) => {
const { variation, data = {} } = props;
const navProps = { ...data };
const root_path = data?.root_node?.[0]?.['@id'];
if (root_path) navProps['root_path'] = flattenToAppURL(root_path);
const Renderer = variation?.view ?? DefaultTemplate;
return <Renderer params={navProps} mode={props.mode} />;
};

export default withBlockExtensions(ContextNavigationView);
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { render } from '@testing-library/react';
import ContextNavigationView from './ContextNavigationView';
import { Router } from 'react-router-dom';
import { Provider } from 'react-intl-redux';
import configureStore from 'redux-mock-store';
import { createMemoryHistory } from 'history';
import '@testing-library/jest-dom/extend-expect';

jest.mock('@plone/volto/components/theme/Navigation/ContextNavigation', () => {
return {
__esModule: true,
default: ({ params }) => {
return <div>ConnectedContextNavigation {params.root_path}</div>;
},
};
});

jest.mock('@plone/volto/helpers', () => ({
withBlockExtensions: jest.fn((Component) => Component),
emptyBlocksForm: jest.fn(),
getBlocksLayoutFieldname: () => 'blocks_layout',
flattenToAppURL: () => '',
}));

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

describe('ContextNavigationView', () => {
let history;
beforeEach(() => {
history = createMemoryHistory();
});

it('renders corectly', () => {
const { container } = render(
<Provider store={store}>
<Router history={history}>
<ContextNavigationView />
</Router>
</Provider>,
);

expect(container.firstChild).toHaveTextContent(
'ConnectedContextNavigation',
);
});

it('renders corectly', () => {
const { container } = render(
<Provider store={store}>
<Router history={history}>
<ContextNavigationView
data={{
navProps: { root_path: 'https://localhost:3000/test' },
root_node: [{ '@id': 'root_node' }],
}}
/>
</Router>
</Provider>,
);
expect(container.firstChild).toHaveTextContent(
'ConnectedContextNavigation',
);
});
});
30 changes: 30 additions & 0 deletions src/components/manage/Blocks/ContextNavigation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import codeSVG from '@plone/volto/icons/code.svg';
import ContextNavigationEdit from './ContextNavigationEdit';
import ContextNavigationView from './ContextNavigationView';
import BlockSettingsSchema from '@plone/volto/components/manage/Blocks/Block/Schema';
import variations from './variations';

const applyConfig = (config) => {
config.blocks.blocksConfig.contextNavigation = {
id: 'contextNavigation',
title: 'Navigation',
icon: codeSVG,
group: 'common',
view: ContextNavigationView,
edit: ContextNavigationEdit,
schema: BlockSettingsSchema,
restricted: false,
variations,
mostUsed: false,
blockHasOwnFocusManagement: true,
sidebarTab: 1,
security: {
addPermission: [],
view: [],
},
};

return config;
};

export default applyConfig;
Loading

0 comments on commit 60d57a5

Please sign in to comment.