Skip to content

Commit

Permalink
Merge pull request #18 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea committed Jul 24, 2023
2 parents e1ff800 + 2b55c8c commit d6cd362
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 7 deletions.
27 changes: 24 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ 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).

### [1.3.0](https://github.com/eea/volto-statistic-block/compare/1.2.1...1.3.0) - 9 June 2023
### [1.3.1](https://github.com/eea/volto-statistic-block/compare/1.3.0...1.3.1) - 24 July 2023

#### :rocket: New Features
#### :bug: Bug Fixes

- fix: link in edit moves page - refs #254291 [dobri1408 - [`04fd659`](https://github.com/eea/volto-statistic-block/commit/04fd659d4110614950306d3b1904962189c05831)]
- fix: Prevent links from leaving page in edit - refs #254291 [dobri1408 - [`1f54dc1`](https://github.com/eea/volto-statistic-block/commit/1f54dc1c1708d46d69567ae66f5f249b95d5d6c8)]

- feat: added text aligment option [Miu Razvan - [`10dc32d`](https://github.com/eea/volto-statistic-block/commit/10dc32ded0890409ec4e316222c9ff6001a25597)]
### [1.3.0](https://github.com/eea/volto-statistic-block/compare/1.2.1...1.3.0) - 12 June 2023

#### :bug: Bug Fixes

Expand All @@ -17,6 +20,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### :house: Internal changes

- chore: [JENKINS] Deprecate circularity website [valentinab25 - [`3dc3490`](https://github.com/eea/volto-statistic-block/commit/3dc34908cf22514318c3fd737d517c8261da7fd4)]

#### :hammer_and_wrench: Others

Expand All @@ -41,16 +45,30 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

- use countup.js@2.5.0 [Miu Razvan - [`9dad099`](https://github.com/eea/volto-statistic-block/commit/9dad099fb6519688752bf4788023712bd9719671)]
- bump version [Miu Razvan - [`e886513`](https://github.com/eea/volto-statistic-block/commit/e886513e63bf480dcdb5c9e0a627b31c6b4e989d)]
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`7cf6d5b`](https://github.com/eea/volto-statistic-block/commit/7cf6d5b1427a9f17bb1c740d019130e323668286)]
### [1.1.0](https://github.com/eea/volto-statistic-block/compare/1.0.1...1.1.0) - 27 March 2023

#### :hammer_and_wrench: Others

- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`1ecdcec`](https://github.com/eea/volto-statistic-block/commit/1ecdcec0ef98c891d9157db9592365fc10760b59)]
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`e5f76cc`](https://github.com/eea/volto-statistic-block/commit/e5f76cc8f90dfa21ba1f2bb25b2491ae0e1b102d)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`439ba7f`](https://github.com/eea/volto-statistic-block/commit/439ba7f0016eb5ba86ef267309e0ddef7b81f379)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`1e72601`](https://github.com/eea/volto-statistic-block/commit/1e72601f1f9a7e8023c9130407d9ce28f1d7b6f9)]
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`9ab65ad`](https://github.com/eea/volto-statistic-block/commit/9ab65ad0f5b300a14590f5f260659749f4831956)]
- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`75e506f`](https://github.com/eea/volto-statistic-block/commit/75e506fd7cf92296871ddf52f9b1c82a053ec931)]
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`9297e9f`](https://github.com/eea/volto-statistic-block/commit/9297e9fb8a638a1564d7d7a6d2ebbea0056d775e)]
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`6dde4aa`](https://github.com/eea/volto-statistic-block/commit/6dde4aae3c87bfe434a28719479e37078db11099)]
- yarn 3 [Alin Voinea - [`b4949e1`](https://github.com/eea/volto-statistic-block/commit/b4949e18f23a7965c76ef97a5790607a587987dc)]
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`8820afa`](https://github.com/eea/volto-statistic-block/commit/8820afa4ab8fcebd17e90522196c1fde8b246e21)]
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`8eb5b8d`](https://github.com/eea/volto-statistic-block/commit/8eb5b8de3f87152cb57faeb960233791b328c900)]
- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`58f36bd`](https://github.com/eea/volto-statistic-block/commit/58f36bd4ae9dcdccbef182789957dbf0bb97da74)]
- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`3bb9a21`](https://github.com/eea/volto-statistic-block/commit/3bb9a2128a88c1196258722112a1957f60d332fc)]
### [1.0.1](https://github.com/eea/volto-statistic-block/compare/1.0.0...1.0.1) - 16 November 2022

#### :hammer_and_wrench: Others

- test(estlint): Fix .project.eslintrc.js [Alin Voinea - [`d81878f`](https://github.com/eea/volto-statistic-block/commit/d81878fff2ba1be4446dd330560c46d8161f8bc2)]
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`a58f436`](https://github.com/eea/volto-statistic-block/commit/a58f436c5bb052fcdd13b213895c497881e48c67)]
## [1.0.0](https://github.com/eea/volto-statistic-block/compare/0.3.0...1.0.0) - 28 October 2022

#### :nail_care: Enhancements
Expand All @@ -62,6 +80,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### :hammer_and_wrench: Others

- Cleanup [Alin Voinea - [`6d5f4a6`](https://github.com/eea/volto-statistic-block/commit/6d5f4a6d8048689e97e567316f24902d0865de88)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`5fd7ba7`](https://github.com/eea/volto-statistic-block/commit/5fd7ba7a4595e157bdb0ebb0932f1d3afd64b369)]
### [0.3.0](https://github.com/eea/volto-statistic-block/compare/0.2.0...0.3.0) - 19 September 2022

#### :nail_care: Enhancements
Expand Down Expand Up @@ -92,6 +111,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
#### :hammer_and_wrench: Others

- Remove useless from block title [Alin Voinea - [`a3daf0a`](https://github.com/eea/volto-statistic-block/commit/a3daf0ad63666d0cd87eef465f42f525a5a307bc)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`4a9ea35`](https://github.com/eea/volto-statistic-block/commit/4a9ea35d0717941e9d96a29e46dc85717140fccf)]
### [0.1.1](https://github.com/eea/volto-statistic-block/compare/0.1.0...0.1.1) - 10 March 2022

#### :hammer_and_wrench: Others
Expand All @@ -102,4 +122,5 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### :hammer_and_wrench: Others

- yarn bootstrap [Alin Voinea - [`ba85706`](https://github.com/eea/volto-statistic-block/commit/ba857067b16dc04f9bc970b0c0d4afd479bb7528)]
- Initial commit [Alin Voinea - [`2e19fe2`](https://github.com/eea/volto-statistic-block/commit/2e19fe2708f89887d2d79f88696e197643ea10f4)]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eeacms/volto-statistic-block",
"version": "1.3.0",
"version": "1.3.1",
"description": "@eeacms/volto-statistic-block: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
9 changes: 6 additions & 3 deletions src/StatisticBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ const View = ({ data, mode }) => {
className={cx(textAlign, { 'ui container': styles.align === 'full' })}
>
{items.map((item, index) => {
const href = getFieldURL(item.href);
const StatisticWrapper = href ? UniversalLink : Statistic;
const href = mode !== 'edit' ? getFieldURL(item.href) : '#';
const StatisticWrapper =
href && href !== '#' ? UniversalLink : Statistic;
const valueNodes = serializeToNodes(item.value);
const valueNo = Number(serializeNodesToText(valueNodes));

return (
<StatisticWrapper
key={`${index}-${item.label}`}
{...(href ? { className: 'ui statistic', href } : {})}
{...(href && href !== '#'
? { className: 'ui statistic', href }
: {})}
>
<Statistic.Value
className={cx('slate', `text-${textAlign}`, valueVariation)}
Expand Down
75 changes: 75 additions & 0 deletions src/StatisticBlock/View.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { render } from '@testing-library/react';
import View from './View';
import isNumber from 'lodash/isNumber';
import '@testing-library/jest-dom/extend-expect';

jest.mock('lodash/isNumber', () => jest.fn(() => true));
jest.mock('lodash/isNaN', () => jest.fn(() => false));

jest.mock('react-countup', () => () => <div>Mocked CountUp</div>);

jest.mock('@plone/volto/components', () => ({
UniversalLink: ({ children }) => <div>{children}</div>,
}));

jest.mock('@plone/volto-slate/editor/render', () => ({
serializeNodesToText: jest.fn((nodes) => nodes[0]?.text || ''),
serializeNodes: jest.fn((nodes) => nodes[0]?.text || ''),
}));

jest.mock('@eeacms/volto-statistic-block/helpers', () => ({
getFieldURL: jest.fn((href) => href),
serializeToNodes: jest.fn((text) => [{ text }]),
serializeNodes: jest.fn((text) => text || ''),
}));

describe('Statistic View Component', () => {
it('renders component with items and CountUp', () => {
const data = {
items: [
{
label: 'Test label',
value: 'Test value',
info: 'Test info',
},
],
animation: {
enabled: true,
duration: 3,
decimals: 0,
},
};
const { getByText } = render(<View data={data} mode="view" />);
expect(getByText('Test label')).toBeInTheDocument();
expect(getByText('Test info')).toBeInTheDocument();
expect(getByText('Mocked CountUp')).toBeInTheDocument();
});

it('renders component with items and no CountUp', () => {
const data = {
items: [
{
label: 'Test label',
value: 'Test value',
info: 'Test info',
},
],
animation: {
enabled: true,
duration: 3,
decimals: 0,
},
};
isNumber.mockReturnValueOnce(false);
const { getByText } = render(<View data={data} mode="view" />);
expect(getByText('Test label')).toBeInTheDocument();
expect(getByText('Test value')).toBeInTheDocument();
expect(getByText('Test info')).toBeInTheDocument();
});

it('renders component in edit mode with no items', () => {
const { getByText } = render(<View data={{ items: [] }} mode="edit" />);
expect(getByText('Add statistic items')).toBeInTheDocument();
});
});
161 changes: 161 additions & 0 deletions src/helpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import {
createParagraph,
serializeToNodes,
serializeNodes,
getFieldURL,
} from './helpers';
import config from '@plone/volto/registry';

jest.mock('@plone/volto/registry', () => ({
settings: {
slate: {
defaultBlockType: 'test_type',
},
},
}));

jest.mock('@plone/volto-slate/editor/render', () => ({
serializeNodes: jest.fn(() => 'serialized'),
}));

describe('serializeToNodes', () => {
it('returns valid nodes array', () => {
const nodes = [
{ children: [{ text: 'test1' }] },
{ children: [{ text: 'test2' }] },
];
expect(serializeToNodes(nodes)).toEqual(nodes);
});

it('returns single paragraph for string input', () => {
const string = 'Test string';
const expected = [
{
type: 'test_type',
children: [{ text: string }],
},
];
expect(serializeToNodes(string)).toEqual(expected);
});

it('returns paragraph with empty string for non-string, non-valid nodes array input', () => {
const expected = [
{
type: 'test_type',
children: [{ text: '' }],
},
];
expect(serializeToNodes(42)).toEqual(expected);
expect(serializeToNodes(null)).toEqual(expected);
expect(serializeToNodes({})).toEqual(expected);
});
});

describe('createParagraph', () => {
it('returns a paragraph with the provided text', () => {
const text = 'Hello, World!';
const expected = {
type: config.settings.slate.defaultBlockType,
children: [{ text: text }],
};
expect(createParagraph(text)).toEqual(expected);
});
});

describe('serializeNodes', () => {
it('serializes nodes', () => {
const nodes = [
{ children: [{ text: 'foo' }] },
{ children: [{ text: 'bar' }] },
];
expect(serializeNodes(nodes)).toEqual('serialized');
});
});

describe('getFieldURL', () => {
it('handles a URL type object with type and value', () => {
const data = {
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('value_url');
});

it('handles an object with type and url', () => {
const data = {
'@type': 'URL',
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});

it('handles an object with type and href', () => {
const data = {
'@type': 'URL',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});

it('handles an object with type and no value, url and href', () => {
const data = {
'@type': 'URL',
};
expect(getFieldURL(data)).toEqual({ '@type': 'URL' });
});

it('handles an object without a specific type and url', () => {
const data = {
url: 'url_url',
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('url_url');
});

it('handles an object without a specific type and href', () => {
const data = {
href: 'href_url',
};
expect(getFieldURL(data)).toEqual('href_url');
});

it('handles an object without a specific type and no id, url, href', () => {
const data = {
test: 'test_url',
};
expect(getFieldURL(data)).toEqual({
test: 'test_url',
});
});

it('handles an array', () => {
const data = [
{
'@type': 'URL',
value: 'value_url',
url: 'url_url',
href: 'href_url',
},
{
'@id': 'id_url',
url: 'url_url',
href: 'href_url',
},
];
expect(getFieldURL(data)).toEqual(['value_url', 'id_url']);
});

it('handles a string', () => {
const data = '/some/url';
expect(getFieldURL(data)).toEqual('/some/url');
});

it('returns the data unchanged for non-object/non-array/non-string inputs', () => {
expect(getFieldURL(42)).toEqual(42);
expect(getFieldURL(undefined)).toEqual(undefined);
expect(getFieldURL(null)).toEqual(null);
});
});

0 comments on commit d6cd362

Please sign in to comment.