Skip to content

Commit

Permalink
Merge pull request #17 from eea/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
avoinea authored Jul 24, 2023
2 parents 26d2184 + efa0fea commit aac5131
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 2 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ 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.2.1](https://github.com/eea/volto-quote-block/compare/1.2.0...1.2.1) - 24 July 2023

#### :hammer_and_wrench: Others

- test: Fix issues identified by Sonarqube refs #254220 [dana-cfc4 - [`7ca6fe0`](https://github.com/eea/volto-quote-block/commit/7ca6fe0321d6610de826fc813003bb9f5b49e210)]
### [1.2.0](https://github.com/eea/volto-quote-block/compare/1.1.0...1.2.0) - 12 June 2023

#### :house: Internal changes

- chore: [JENKINS] Deprecate circularity website [valentinab25 - [`5b8170d`](https://github.com/eea/volto-quote-block/commit/5b8170d33b19d7385f2024437f54360e93819fa6)]

#### :hammer_and_wrench: Others

Expand All @@ -18,16 +24,30 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- update getFieldURL function [Miu Razvan - [`49e4bd7`](https://github.com/eea/volto-quote-block/commit/49e4bd73b11d5f2a08444a4550d32fb243d79f97)]
- refactoring [tedw87 - [`fad035e`](https://github.com/eea/volto-quote-block/commit/fad035e7487e7e4b9190c2f85e425b0cfcc4ddd6)]
- use getFieldURL function for image source [tedw87 - [`f93b977`](https://github.com/eea/volto-quote-block/commit/f93b9771d609f4006142d481ecd817b088f91683)]
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`041c95c`](https://github.com/eea/volto-quote-block/commit/041c95cdc43a3befc039cc05f5db11dee4933a5e)]
### [1.1.0](https://github.com/eea/volto-quote-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 - [`70fad4a`](https://github.com/eea/volto-quote-block/commit/70fad4a7a53128504d49566d67b2e98d4f0e1c6e)]
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`c9f7dfb`](https://github.com/eea/volto-quote-block/commit/c9f7dfbf612351cb7fe1b410558871af4f44bdb0)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`dcb3120`](https://github.com/eea/volto-quote-block/commit/dcb3120733b3c66ab5ae780461de17874f9337cd)]
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`0e1a14b`](https://github.com/eea/volto-quote-block/commit/0e1a14b5c324285c5d34489920f833d0b4d8b722)]
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`7107f41`](https://github.com/eea/volto-quote-block/commit/7107f415c429adee00650a87ec5874374e06916a)]
- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`20470a4`](https://github.com/eea/volto-quote-block/commit/20470a452c91a7f8cee537958ddafa6481c5a098)]
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`335aed4`](https://github.com/eea/volto-quote-block/commit/335aed4cefaa41662faf2daf018c81ac5c0450fe)]
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`43c4789`](https://github.com/eea/volto-quote-block/commit/43c478928259ce1cf71dc64db71761ba5e738db0)]
- yarn 3 [Alin Voinea - [`1d91a66`](https://github.com/eea/volto-quote-block/commit/1d91a66e4efbf1585483dafe90e9233e37ef6907)]
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`b45d254`](https://github.com/eea/volto-quote-block/commit/b45d254ff2a4e8beecbe1dc233b844655bdfd156)]
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`edc3802`](https://github.com/eea/volto-quote-block/commit/edc380248dd51d8b795396eb9938076a64dd0302)]
- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`8d4301f`](https://github.com/eea/volto-quote-block/commit/8d4301f87c4d9afacd3f760f83d4b4329eb4a49f)]
- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`d3927e7`](https://github.com/eea/volto-quote-block/commit/d3927e75ea0d002402df2e606f836b006636dd2f)]
### [1.0.1](https://github.com/eea/volto-quote-block/compare/1.0.0...1.0.1) - 16 November 2022

#### :hammer_and_wrench: Others

- test(estlint): Fix .project.eslintrc.js [Alin Voinea - [`c9d6327`](https://github.com/eea/volto-quote-block/commit/c9d632748b3040478977699ca39c0e0f76ab840e)]
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`e2c8b5c`](https://github.com/eea/volto-quote-block/commit/e2c8b5c0f76bb59411d944a8d431b882f7b5cec6)]
## [1.0.0](https://github.com/eea/volto-quote-block/compare/0.3.3...1.0.0) - 28 October 2022

#### :nail_care: Enhancements
Expand All @@ -42,6 +62,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Release 1.0.0 [Alin Voinea - [`4944731`](https://github.com/eea/volto-quote-block/commit/4944731b1c7b9b80620311909202bb75c894760c)]
- test(cypress): Cypress 10 / Razzle 4 [Alin Voinea - [`91262ed`](https://github.com/eea/volto-quote-block/commit/91262eddb7272d12686cdb71952c607846cecb5d)]
- Cleanup [Alin Voinea - [`9b70192`](https://github.com/eea/volto-quote-block/commit/9b7019284a8e2159248cfa6109c8c0f84c6273d8)]
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`57a87d3`](https://github.com/eea/volto-quote-block/commit/57a87d3474a6390b77c2b1b983cd932bf2dd824f)]
### [0.3.3](https://github.com/eea/volto-quote-block/compare/0.3.2...0.3.3) - 1 August 2022

### [0.3.2](https://github.com/eea/volto-quote-block/compare/0.3.1...0.3.2) - 30 June 2022
Expand All @@ -52,6 +73,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### :hammer_and_wrench: Others

- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`cbbd44a`](https://github.com/eea/volto-quote-block/commit/cbbd44a578ddb6904ef1c7bb0053549029c7447b)]
### [0.2.0](https://github.com/eea/volto-quote-block/compare/0.1.2...0.2.0) - 19 May 2022

#### :nail_care: Enhancements
Expand Down
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-quote-block",
"version": "1.2.0",
"version": "1.2.1",
"description": "@eeacms/volto-quote-block: Volto add-on",
"main": "src/index.js",
"author": "European Environment Agency: IDM2 A-Team",
Expand Down
82 changes: 82 additions & 0 deletions src/Blocks/Quote/variations/DefaultQuote.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import Quote from './DefaultQuote';
import '@testing-library/jest-dom/extend-expect';

const mockStore = configureStore([]);

jest.mock('@plone/volto/registry', () => ({
settings: {
slate: {
defaultValue: jest.fn(() => 'default value'),
},
},
}));

jest.mock('@plone/volto-slate/editor/SlateEditor', () => () => <textarea />);

describe('Quote', () => {
let store;

beforeEach(() => {
store = mockStore({
slate_block_selections: {},
upload_content: {},
});
});

afterEach(() => {
jest.clearAllMocks();
});

it('renders the Quote component', () => {
const { getByText } = render(
<Provider store={store}>
<Quote
data={{
value: 'Test value',
source: 'Test source',
extra: 'Test extra',
position: 'left',
}}
mode="edit"
index={0}
block="block1"
selected={false}
properties={{}}
onChangeBlock={() => {}}
onSelectBlock={() => {}}
/>
</Provider>,
);
expect(getByText('Test source')).toBeInTheDocument();
expect(getByText('Test extra')).toBeInTheDocument();
});

it('renders the Quote component with reversed and no block', () => {
const { getByText } = render(
<Provider store={store}>
<Quote
data={{
value: 'Test value',
source: 'Test source',
extra: 'Test extra',
reversed: true,
}}
mode="edit"
index={0}
block={undefined}
selected={false}
properties={{}}
onChangeBlock={() => {}}
onSelectBlock={() => {}}
/>
</Provider>,
);

expect(getByText('Test source')).toBeInTheDocument();
expect(getByText('Test extra')).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/Blocks/Quote/variations/TestimonialQuote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import {
createSlateParagraph,
serializeText,
getFieldURL,
} from '@eeacms/volto-quote-block/helpers';
import { getFieldURL } from '@eeacms/volto-quote-block/helpers';
import Quote from './DefaultQuote';

import DefaultImageSVG from '@plone/volto/components/manage/Blocks/Listing/default-image.svg';
Expand Down
172 changes: 172 additions & 0 deletions src/helpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { isArray } from 'lodash';
import config from '@plone/volto/registry';
import { serializeNodes } from '@plone/volto-slate/editor/render';
import {
createSlateParagraph,
serializeText,
isFloated,
getFieldURL,
} from './helpers';

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

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

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);
});
});

describe('createSlateParagraph', () => {
afterEach(() => {
jest.clearAllMocks();
});

afterAll(() => {
jest.resetModules();
});

it('should return default value when input is not an array', () => {
const input = 'test';
createSlateParagraph(input);
expect(config.settings.slate.defaultValue).toHaveBeenCalledTimes(1);
});

it('should return input when input is an array', () => {
const input = ['test'];
const result = createSlateParagraph(input);
expect(result).toBe(input);
});
});

describe('serializeText', () => {
beforeEach(() => {
jest.resetAllMocks();
});

afterAll(() => {
jest.resetModules();
jest.clearAllMocks();
});

it('should return the text when it is not an array', () => {
const input = 'test';

expect(serializeText(input)).toEqual(input);
expect(isArray(input)).toBe(false);
expect(serializeNodes).not.toHaveBeenCalled();
});

it('should call serializeNodes when text is an array', () => {
const input = ['test'];

serializeText(input);
expect(isArray(input)).toBe(true);
expect(serializeNodes).toHaveBeenCalledWith(input);
});
});

describe('isFloated', () => {
it('should return true if position is left', () => {
expect(isFloated('left')).toBe(true);
});

it('should return true if position is right', () => {
expect(isFloated('right')).toBe(true);
});

it('should return false if position is not left or right', () => {
expect(isFloated('center')).toBe(false);
});
});

0 comments on commit aac5131

Please sign in to comment.