@eeacms/volto-datahub 1.0.32 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,65 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const projectRootPath = fs.realpathSync(__dirname + '/../../../');
4
+
5
+ let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');
6
+ let configFile;
7
+ if (fs.existsSync(`${projectRootPath}/tsconfig.json`))
8
+ configFile = `${projectRootPath}/tsconfig.json`;
9
+ else if (fs.existsSync(`${projectRootPath}/jsconfig.json`))
10
+ configFile = `${projectRootPath}/jsconfig.json`;
11
+
12
+ if (configFile) {
13
+ const jsConfig = require(configFile).compilerOptions;
14
+ const pathsConfig = jsConfig.paths;
15
+ if (pathsConfig['@plone/volto'])
16
+ voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`;
17
+ }
18
+
19
+ const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
20
+ const reg = new AddonConfigurationRegistry(projectRootPath);
21
+
22
+ // Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
23
+ const addonAliases = Object.keys(reg.packages).map((o) => [
24
+ o,
25
+ reg.packages[o].modulePath,
26
+ ]);
27
+
28
+ const addonExtenders = reg.getEslintExtenders().map((m) => require(m));
29
+
30
+ const defaultConfig = {
31
+ extends: `${voltoPath}/.eslintrc`,
32
+ settings: {
33
+ 'import/resolver': {
34
+ alias: {
35
+ map: [
36
+ ['@plone/volto', '@plone/volto/src'],
37
+ ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'],
38
+ ...addonAliases,
39
+ ['@package', `${__dirname}/src`],
40
+ ['@root', `${__dirname}/src`],
41
+ ['~', `${__dirname}/src`],
42
+ ],
43
+ extensions: ['.js', '.jsx', '.json'],
44
+ },
45
+ 'babel-plugin-root-import': {
46
+ rootPathSuffix: 'src',
47
+ },
48
+ },
49
+ },
50
+ rules: {
51
+ 'react/jsx-no-target-blank': [
52
+ 'error',
53
+ {
54
+ allowReferrer: true,
55
+ },
56
+ ],
57
+ }
58
+ };
59
+
60
+ const config = addonExtenders.reduce(
61
+ (acc, extender) => extender.modify(acc),
62
+ defaultConfig,
63
+ );
64
+
65
+ module.exports = config;
package/CHANGELOG.md CHANGED
@@ -4,6 +4,30 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [2.0.0](https://github.com/eea/volto-datahub/compare/1.0.33...2.0.0) - 22 April 2024
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: Release 2.0.0 - Volto 17 support [alin - [`1ea48ae`](https://github.com/eea/volto-datahub/commit/1ea48ae306f13cea5729ba55a5b77f79fe0d8716)]
12
+ - feat: Volto 17 support - refs #264527 [EEA Jenkins - [`309c256`](https://github.com/eea/volto-datahub/commit/309c256a62ce3807dd272520ff931bf3cff7f724)]
13
+
14
+ ### [1.0.33](https://github.com/eea/volto-datahub/compare/1.0.32...1.0.33) - 13 March 2024
15
+
16
+ #### :boom: Breaking Change
17
+
18
+ - breaking(webpack): removed path import as webpack 5 no longer patches node modules to use in the browser [David Ichim - [`76f3538`](https://github.com/eea/volto-datahub/commit/76f353869b4ba8c687c97c140fa43db236b55188)]
19
+
20
+ #### :house: Internal changes
21
+
22
+ - chore: husky, lint-staged use fixed versions [valentinab25 - [`da129fb`](https://github.com/eea/volto-datahub/commit/da129fb1259a26c87259f380a37db688281b192d)]
23
+
24
+ #### :hammer_and_wrench: Others
25
+
26
+ - Remove noreferrer for SEO purposes #60 from eea/263008-noreferrer [ichim-david - [`3c68343`](https://github.com/eea/volto-datahub/commit/3c6834393f25bb3e1ffc119512e785db5dca0e7d)]
27
+ - update snapshots [Teodor - [`7a3471b`](https://github.com/eea/volto-datahub/commit/7a3471bcc125ce66b5bd6933b7b9161320c14a23)]
28
+ - remove eslint file from ignoring [Teodor - [`39f6633`](https://github.com/eea/volto-datahub/commit/39f66338f2f7d1797343b88aa20dea9425f37014)]
29
+ - change eslint rule [Teodor - [`73e4bc2`](https://github.com/eea/volto-datahub/commit/73e4bc217e9aa9804f0f57cf9e3488cb2e1e85b8)]
30
+ - Ref #263008 [Teodor - [`9d58c52`](https://github.com/eea/volto-datahub/commit/9d58c52b6bc207c5c622c0428be39ae18875cf64)]
7
31
  ### [1.0.32](https://github.com/eea/volto-datahub/compare/1.0.31...1.0.32) - 11 October 2023
8
32
 
9
33
  #### :house: Internal changes
package/cypress.config.js CHANGED
@@ -2,12 +2,12 @@ const { defineConfig } = require('cypress');
2
2
 
3
3
  module.exports = defineConfig({
4
4
  viewportWidth: 1280,
5
- defaultCommandTimeout: 5000,
5
+ defaultCommandTimeout: 8888,
6
6
  chromeWebSecurity: false,
7
7
  reporter: 'junit',
8
- video: true,
8
+ video: false,
9
9
  retries: {
10
- runMode: 1,
10
+ runMode: 2,
11
11
  openMode: 0,
12
12
  },
13
13
  reporterOptions: {
@@ -1,3 +1,5 @@
1
+ require('dotenv').config({ path: __dirname + '/.env' });
2
+
1
3
  module.exports = {
2
4
  testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
3
5
  collectCoverageFrom: [
@@ -9,19 +11,25 @@ module.exports = {
9
11
  '@plone/volto/cypress': '<rootDir>/node_modules/@plone/volto/cypress',
10
12
  '@plone/volto/babel': '<rootDir>/node_modules/@plone/volto/babel',
11
13
  '@plone/volto/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
12
- '@package/(.*)$': '<rootDir>/src/$1',
13
- '@root/(.*)$': '<rootDir>/src/$1',
14
+ '@package/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
15
+ '@root/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
14
16
  '@plone/volto-quanta/(.*)$': '<rootDir>/src/addons/volto-quanta/src/$1',
15
17
  '@eeacms/search': '<rootDir>/node_modules/@eeacms/volto-searchlib/src',
16
18
  '@eeacms/(.*?)/(.*)$': '<rootDir>/node_modules/@eeacms/$1/src/$2',
17
- '@plone/volto-slate':
19
+ '@plone/volto-slate$':
18
20
  '<rootDir>/node_modules/@plone/volto/packages/volto-slate/src',
21
+ '@plone/volto-slate/(.*)$':
22
+ '<rootDir>/node_modules/@plone/volto/packages/volto-slate/src/$1',
19
23
  '~/(.*)$': '<rootDir>/src/$1',
20
24
  'load-volto-addons':
21
25
  '<rootDir>/node_modules/@plone/volto/jest-addons-loader.js',
22
26
  },
27
+ transformIgnorePatterns: [
28
+ '/node_modules/(?!(@plone|@root|@package|@eeacms)/).*/',
29
+ ],
23
30
  transform: {
24
31
  '^.+\\.js(x)?$': 'babel-jest',
32
+ '^.+\\.ts(x)?$': 'babel-jest',
25
33
  '^.+\\.(png)$': 'jest-file',
26
34
  '^.+\\.(jpg)$': 'jest-file',
27
35
  '^.+\\.(svg)$': './node_modules/@plone/volto/jest-svgsystem-transform.js',
@@ -34,4 +42,9 @@ module.exports = {
34
42
  statements: 5,
35
43
  },
36
44
  },
45
+ ...(process.env.JEST_USE_SETUP === 'ON' && {
46
+ setupFilesAfterEnv: [
47
+ '<rootDir>/node_modules/@eeacms/volto-datahub/jest.setup.js',
48
+ ],
49
+ }),
37
50
  };
package/jest.setup.js ADDED
@@ -0,0 +1,65 @@
1
+ import { jest } from '@jest/globals';
2
+ import configureStore from 'redux-mock-store';
3
+ import thunk from 'redux-thunk';
4
+ import { blocksConfig } from '@plone/volto/config/Blocks';
5
+ import installSlate from '@plone/volto-slate/index';
6
+
7
+ var mockSemanticComponents = jest.requireActual('semantic-ui-react');
8
+ var mockComponents = jest.requireActual('@plone/volto/components');
9
+ var config = jest.requireActual('@plone/volto/registry').default;
10
+
11
+ config.blocks.blocksConfig = {
12
+ ...blocksConfig,
13
+ ...config.blocks.blocksConfig,
14
+ };
15
+
16
+ jest.doMock('semantic-ui-react', () => ({
17
+ __esModule: true,
18
+ ...mockSemanticComponents,
19
+ Popup: ({ content, trigger }) => {
20
+ return (
21
+ <div className="popup">
22
+ <div className="trigger">{trigger}</div>
23
+ <div className="content">{content}</div>
24
+ </div>
25
+ );
26
+ },
27
+ }));
28
+
29
+ jest.doMock('@plone/volto/components', () => {
30
+ return {
31
+ __esModule: true,
32
+ ...mockComponents,
33
+ SidebarPortal: ({ children }) => <div id="sidebar">{children}</div>,
34
+ };
35
+ });
36
+
37
+ jest.doMock('@plone/volto/registry', () =>
38
+ [installSlate].reduce((acc, apply) => apply(acc), config),
39
+ );
40
+
41
+ const mockStore = configureStore([thunk]);
42
+
43
+ global.fetch = jest.fn(() =>
44
+ Promise.resolve({
45
+ json: () => Promise.resolve({}),
46
+ }),
47
+ );
48
+
49
+ global.store = mockStore({
50
+ intl: {
51
+ locale: 'en',
52
+ messages: {},
53
+ formatMessage: jest.fn(),
54
+ },
55
+ content: {
56
+ create: {},
57
+ subrequests: [],
58
+ },
59
+ connected_data_parameters: {},
60
+ screen: {
61
+ page: {
62
+ width: 768,
63
+ },
64
+ },
65
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-datahub",
3
- "version": "1.0.32",
3
+ "version": "2.0.0",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -26,8 +26,9 @@
26
26
  "@cypress/code-coverage": "^3.10.0",
27
27
  "@plone/scripts": "*",
28
28
  "babel-plugin-transform-class-properties": "^6.24.1",
29
- "husky": "*",
30
- "lint-staged": "*",
29
+ "dotenv": "^16.3.2",
30
+ "husky": "^8.0.3",
31
+ "lint-staged": "^14.0.1",
31
32
  "md5": "^2.3.0"
32
33
  },
33
34
  "addons": [
@@ -10,12 +10,7 @@ const ItemLink = ({ item }) => (
10
10
  <List.Content>
11
11
  <div className="dataset-item">
12
12
  <SVGIcon name={servicesSVG} size="20px" />
13
- <a
14
- className="item-link"
15
- href={item.url}
16
- target="_blank"
17
- rel="noreferrer"
18
- >
13
+ <a className="item-link" href={item.url} target="_blank" rel="noopener">
19
14
  {item.protocol} {item.name || item.description}
20
15
  </a>
21
16
  {isInternalURL(item.url) ? (
@@ -1,27 +1,40 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/extend-expect';
3
4
 
4
5
  import DatasetEsri from './DatasetEsri';
5
6
 
6
- jest.mock('@eeacms/search', () => ({
7
- runRequest: jest.fn(),
8
- }));
9
-
10
- const dataset = {
11
- 'ESRI:REST': [
12
- {
13
- id: 1,
14
- url: 'https://example.org/1',
15
- protocol: 'https',
16
- name: 'First',
17
- description: 'Something here',
18
- },
19
- ],
20
- };
7
+ jest.mock('remixicon/icons/System/lock-line.svg', () => 'MockLockIcon');
21
8
 
22
9
  describe('DatasetEsri', () => {
23
- it('renders correctly', () => {
24
- const tree = renderer.create(<DatasetEsri dataset={dataset} />).toJSON();
25
- expect(tree).toMatchSnapshot();
10
+ const dataset = {
11
+ 'ESRI:REST': [
12
+ {
13
+ id: 1,
14
+ url: 'https://example.org/1',
15
+ protocol: 'https',
16
+ name: 'First',
17
+ },
18
+ ],
19
+ };
20
+
21
+ it('renders services section when ESRI:REST data exists', () => {
22
+ render(<DatasetEsri dataset={dataset} />);
23
+
24
+ expect(screen.getByText('Services:')).toBeInTheDocument();
25
+ expect(screen.getByText('https First')).toBeInTheDocument();
26
+ });
27
+
28
+ it('renders services section when OGC:WMS data exists', () => {
29
+ render(<DatasetEsri dataset={{ 'OGC:WMS': dataset['ESRI:REST'] }} />);
30
+
31
+ expect(screen.getByText('Services:')).toBeInTheDocument();
32
+ expect(screen.getByText('https First')).toBeInTheDocument();
33
+ });
34
+
35
+ it('does not render services section when no data exists', () => {
36
+ render(<DatasetEsri dataset={{}} />);
37
+
38
+ expect(screen.queryByText('Services:')).not.toBeInTheDocument();
26
39
  });
27
40
  });
@@ -4,61 +4,36 @@ import { SVGIcon } from '../utils.js';
4
4
 
5
5
  import lockSVG from 'remixicon/icons/System/lock-line.svg';
6
6
 
7
+ const renderListItem = (item, index, iconClass) => (
8
+ <List.Item key={index}>
9
+ <List.Content>
10
+ <div className="dataset-item">
11
+ <Icon className={iconClass} />
12
+ <a href={item.url} className="item-link" target="_blank" rel="noopener">
13
+ <span>{item.name || item.url}</span>
14
+ </a>
15
+ {isInternalURL(item.url) ? (
16
+ <SVGIcon name={lockSVG} size="20px" />
17
+ ) : null}
18
+ </div>
19
+ </List.Content>
20
+ {item.description ? (
21
+ <span className="item-description">{item.description}</span>
22
+ ) : null}
23
+ </List.Item>
24
+ );
25
+
7
26
  export default function DatasetHttpLinks({ dataset }) {
8
27
  return dataset['WWW:LINK-1.0-http--link'] || dataset['DOI'] ? (
9
28
  <>
10
29
  <h5>Links:</h5>
11
30
  <List divided relaxed>
12
- {(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) => {
13
- return (
14
- <List.Item key={i}>
15
- <List.Content>
16
- <div className="dataset-item">
17
- <Icon className="linkify" />
18
- <a
19
- href={item.url}
20
- className="item-link"
21
- target="_blank"
22
- rel="noreferrer"
23
- >
24
- <span>{item.name || item.url}</span>
25
- </a>
26
- {isInternalURL(item.url) ? (
27
- <SVGIcon name={lockSVG} size="20px" />
28
- ) : null}
29
- </div>
30
- </List.Content>
31
- {item.description ? (
32
- <span className="item-description">{item.description}</span>
33
- ) : null}
34
- </List.Item>
35
- );
36
- })}
37
- {(dataset['DOI'] || []).map((item, i) => {
38
- return (
39
- <List.Item key={i}>
40
- <List.Content>
41
- <div className="dataset-item">
42
- <Icon className="info circle" />
43
- <a
44
- href={item.url}
45
- className="item-link"
46
- target="_blank"
47
- rel="noreferrer"
48
- >
49
- <span>{item.name || item.url}</span>
50
- </a>
51
- {isInternalURL(item.url) ? (
52
- <SVGIcon name={lockSVG} size="20px" />
53
- ) : null}
54
- </div>
55
- </List.Content>
56
- {item.description ? (
57
- <span className="item-description">{item.description}</span>
58
- ) : null}
59
- </List.Item>
60
- );
61
- })}
31
+ {(dataset['WWW:LINK-1.0-http--link'] || []).map((item, i) =>
32
+ renderListItem(item, i, 'linkify'),
33
+ )}
34
+ {(dataset['DOI'] || []).map((item, i) =>
35
+ renderListItem(item, i, 'info circle'),
36
+ )}
62
37
  </List>
63
38
  </>
64
39
  ) : null;
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/extend-expect';
4
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
3
5
 
4
6
  import DatasetHttpLinks from './DatasetHttpLinks';
5
7
 
@@ -7,32 +9,71 @@ jest.mock('@eeacms/search', () => ({
7
9
  runRequest: jest.fn(),
8
10
  }));
9
11
 
10
- const dataset = {
11
- 'WWW:LINK-1.0-http--link': [
12
- {
13
- id: 1,
14
- url: 'https://example.org/1',
15
- protocol: 'https',
16
- name: 'First',
17
- description: 'Something here',
18
- },
19
- ],
20
- DOI: [
21
- {
22
- id: 1,
23
- url: 'https://example.org/1',
24
- protocol: 'https',
25
- name: 'First',
26
- description: 'Something here',
27
- },
28
- ],
29
- };
12
+ jest.mock('@eeacms/volto-datahub/utils', () => ({
13
+ isInternalURL: jest.fn(),
14
+ }));
15
+
16
+ jest.mock('remixicon/icons/System/lock-line.svg', () => 'MockLockIcon');
30
17
 
31
18
  describe('DatasetHttpLinks', () => {
32
- it('renders correctly', () => {
33
- const tree = renderer
34
- .create(<DatasetHttpLinks dataset={dataset} />)
35
- .toJSON();
36
- expect(tree).toMatchSnapshot();
19
+ const dataset = {
20
+ 'WWW:LINK-1.0-http--link': [
21
+ {
22
+ url: 'https://example.org/1',
23
+ name: 'Example Link',
24
+ description: 'This is an example link',
25
+ },
26
+ ],
27
+ DOI: [
28
+ {
29
+ url: 'https://doi.org/example',
30
+ name: 'Example DOI',
31
+ description: 'This is an example DOI',
32
+ },
33
+ ],
34
+ };
35
+
36
+ it('renders links section when dataset has WWW:LINK-1.0-http--link or DOI', () => {
37
+ render(<DatasetHttpLinks dataset={dataset} />);
38
+
39
+ expect(screen.getByText('Links:')).toBeInTheDocument();
40
+ });
41
+
42
+ it('does not render links section when dataset has no WWW:LINK-1.0-http--link or DOI', () => {
43
+ render(<DatasetHttpLinks dataset={{}} />);
44
+
45
+ expect(screen.queryByText('Links:')).not.toBeInTheDocument();
46
+ });
47
+
48
+ it('renders WWW:LINK-1.0-http--link items', () => {
49
+ render(<DatasetHttpLinks dataset={dataset} />);
50
+
51
+ expect(screen.getByText('Example Link')).toBeInTheDocument();
52
+ expect(screen.getByText('This is an example link')).toBeInTheDocument();
53
+ });
54
+
55
+ it('renders DOI items', () => {
56
+ render(<DatasetHttpLinks dataset={dataset} />);
57
+
58
+ expect(screen.getByText('Example DOI')).toBeInTheDocument();
59
+ expect(screen.getByText('This is an example DOI')).toBeInTheDocument();
60
+ });
61
+
62
+ it('renders lock icon for internal URLs', () => {
63
+ isInternalURL.mockReturnValue(true);
64
+ const internalDataset = {
65
+ 'WWW:LINK-1.0-http--link': [
66
+ {
67
+ url: 'https://internal.com',
68
+ name: 'Internal Link',
69
+ },
70
+ ],
71
+ };
72
+
73
+ const { container } = render(
74
+ <DatasetHttpLinks dataset={internalDataset} />,
75
+ );
76
+
77
+ expect(container.querySelector('svg.icon')).toBeInTheDocument();
37
78
  });
38
79
  });
@@ -1,28 +1,63 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { groupBy } from '@eeacms/volto-datahub/utils';
4
+ import DatasetUrls from './DatasetUrls';
5
+ import DatasetLinks from './DatasetLinks';
6
+ import DatasetEsri from './DatasetEsri';
7
+ import DatasetHttpLinks from './DatasetHttpLinks';
8
+ import '@testing-library/jest-dom/extend-expect';
3
9
 
4
10
  import DatasetItemDownloadList from './DatasetItemDownloadList';
5
11
 
6
12
  jest.mock('@eeacms/search', () => ({
7
13
  runRequest: jest.fn(),
8
14
  }));
9
-
10
- const link = [
11
- {
12
- function: 'download',
13
- mimeType: '',
14
- protocol: 'WWW:URL',
15
- url: 'https://example.org/1',
16
- name: 'Direct download',
17
- group: 0,
18
- },
19
- ];
15
+ jest.mock('./DatasetUrls', () => jest.fn(() => null));
16
+ jest.mock('./DatasetLinks', () => jest.fn(() => null));
17
+ jest.mock('./DatasetEsri', () => jest.fn(() => null));
18
+ jest.mock('./DatasetHttpLinks', () => jest.fn(() => null));
20
19
 
21
20
  describe('DatasetItemDownloadList', () => {
22
- it('renders correctly', () => {
23
- const tree = renderer
24
- .create(<DatasetItemDownloadList link={link} />)
25
- .toJSON();
26
- expect(tree).toMatchSnapshot();
21
+ const link = [
22
+ {
23
+ function: 'download',
24
+ mimeType: '',
25
+ protocol: 'WWW:URL',
26
+ url: 'https://example.org/1',
27
+ name: 'Direct download',
28
+ group: 0,
29
+ },
30
+ ];
31
+
32
+ it('renders download section when dataset has WWW:URL, WWW:LINK, EEA:FILEPATH, or EEA:FOLDERPATH', () => {
33
+ const dataset = groupBy(link, 'protocol');
34
+ render(<DatasetItemDownloadList link={link} />);
35
+
36
+ expect(screen.getByText('Download:')).toBeInTheDocument();
37
+ expect(DatasetUrls).toHaveBeenCalledWith({ dataset }, expect.anything());
38
+ expect(DatasetLinks).toHaveBeenCalledWith({ dataset }, expect.anything());
39
+ });
40
+
41
+ it('does not render download section when dataset has no WWW:URL, WWW:LINK, EEA:FILEPATH, or EEA:FOLDERPATH', () => {
42
+ render(<DatasetItemDownloadList link={[]} />);
43
+
44
+ expect(screen.queryByText('Download:')).not.toBeInTheDocument();
45
+ });
46
+
47
+ it('renders DatasetEsri component', () => {
48
+ const dataset = groupBy(link, 'protocol');
49
+ render(<DatasetItemDownloadList link={link} />);
50
+
51
+ expect(DatasetEsri).toHaveBeenCalledWith({ dataset }, expect.anything());
52
+ });
53
+
54
+ it('renders DatasetHttpLinks component', () => {
55
+ const dataset = groupBy(link, 'protocol');
56
+ render(<DatasetItemDownloadList link={link} />);
57
+
58
+ expect(DatasetHttpLinks).toHaveBeenCalledWith(
59
+ { dataset },
60
+ expect.anything(),
61
+ );
27
62
  });
28
63
  });
@@ -1,27 +1,49 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
4
+ import '@testing-library/jest-dom/extend-expect';
3
5
 
4
6
  import DatasetLinks from './DatasetLinks';
5
7
 
6
- jest.mock('@eeacms/search', () => ({
7
- runRequest: jest.fn(),
8
+ jest.mock('remixicon/icons/System/lock-line.svg', () => 'MockLockIcon');
9
+ jest.mock('@eeacms/volto-datahub/utils', () => ({
10
+ isInternalURL: jest.fn(),
8
11
  }));
9
12
 
10
- const dataset = {
11
- 'WWW:LINK': [
12
- {
13
- id: 1,
14
- url: 'https://example.org/1',
15
- protocol: 'https',
16
- name: 'First',
17
- description: 'Something here',
18
- },
19
- ],
20
- };
21
-
22
- describe('DatasetEsri', () => {
23
- it('renders correctly', () => {
24
- const tree = renderer.create(<DatasetLinks dataset={dataset} />).toJSON();
25
- expect(tree).toMatchSnapshot();
13
+ describe('DatasetLinks', () => {
14
+ const dataset = {
15
+ 'WWW:LINK': [
16
+ {
17
+ url: 'https://example.com/link1',
18
+ name: 'Link 1',
19
+ },
20
+ {
21
+ url: 'https://example.com/link2',
22
+ name: '',
23
+ },
24
+ ],
25
+ };
26
+
27
+ it('renders links from the dataset', () => {
28
+ render(<DatasetLinks dataset={dataset} />);
29
+
30
+ expect(screen.getByText('Link 1')).toBeInTheDocument();
31
+ expect(screen.getByText('Download link')).toBeInTheDocument();
32
+ });
33
+
34
+ it('renders lock icon for internal URLs', () => {
35
+ isInternalURL.mockReturnValue(true);
36
+
37
+ const { container } = render(<DatasetLinks dataset={dataset} />);
38
+
39
+ expect(container.querySelector('svg.icon')).toBeInTheDocument();
40
+ });
41
+
42
+ it('does not render lock icon for external URLs', () => {
43
+ isInternalURL.mockReturnValue(false);
44
+
45
+ const { container } = render(<DatasetLinks dataset={dataset} />);
46
+
47
+ expect(container.querySelector('svg.icon')).not.toBeInTheDocument();
26
48
  });
27
49
  });
@@ -1,25 +1,51 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { isInternalURL } from '@eeacms/volto-datahub/utils';
4
+ import '@testing-library/jest-dom/extend-expect';
3
5
 
4
6
  import DatasetUrls from './DatasetUrls';
5
7
 
6
- jest.mock('@eeacms/search', () => ({
7
- runRequest: jest.fn(),
8
+ jest.mock('remixicon/icons/System/lock-line.svg', () => 'MockLockIcon');
9
+ jest.mock('@eeacms/volto-datahub/utils', () => ({
10
+ isInternalURL: jest.fn(),
8
11
  }));
9
12
 
10
- const dataset = {
11
- 'WWW:URL': [
12
- {
13
- url: 'https://example.org/1',
14
- name: 'Direct download',
15
- description: 'Download link description',
16
- },
17
- ],
18
- };
19
-
20
- describe('DatasetUrl', () => {
21
- it('renders correctly', () => {
22
- const tree = renderer.create(<DatasetUrls dataset={dataset} />).toJSON();
23
- expect(tree).toMatchSnapshot();
13
+ describe('DatasetUrls', () => {
14
+ const dataset = {
15
+ 'WWW:URL': [
16
+ {
17
+ url: 'https://example.com/url1',
18
+ name: 'Direct download',
19
+ description: 'Download link description',
20
+ },
21
+ {
22
+ url: 'https://example.com/url2',
23
+ name: '',
24
+ description: '',
25
+ },
26
+ ],
27
+ };
28
+
29
+ it('renders URLs from the dataset', () => {
30
+ render(<DatasetUrls dataset={dataset} />);
31
+
32
+ expect(screen.getByText('Direct download')).toBeInTheDocument();
33
+ expect(screen.getByTitle('Download link description')).toBeInTheDocument();
34
+ });
35
+
36
+ it('renders lock icon for internal URLs', () => {
37
+ isInternalURL.mockReturnValue(true);
38
+
39
+ const { container } = render(<DatasetUrls dataset={dataset} />);
40
+
41
+ expect(container.querySelector('svg.icon')).toBeInTheDocument();
42
+ });
43
+
44
+ it('does not render lock icon for external URLs', () => {
45
+ isInternalURL.mockReturnValue(false);
46
+
47
+ const { container } = render(<DatasetUrls dataset={dataset} />);
48
+
49
+ expect(container.querySelector('svg.icon')).not.toBeInTheDocument();
24
50
  });
25
51
  });
@@ -5,10 +5,8 @@ import { parseDatasets } from '@eeacms/volto-datahub/utils';
5
5
  const DatasetsView = (props) => {
6
6
  const { item, appConfig } = props;
7
7
  const { children } = item?.raw_value?.raw || {};
8
- const {
9
- groupedByTemporalCoverage,
10
- groupedByArchivedOrRestricted,
11
- } = parseDatasets(children);
8
+ const { groupedByTemporalCoverage, groupedByArchivedOrRestricted } =
9
+ parseDatasets(children);
12
10
 
13
11
  return (
14
12
  <>
@@ -80,11 +80,11 @@ const MetadataSection = (props) => {
80
80
  <Icon className="file pdf" />
81
81
  <a
82
82
  target="_blank"
83
- rel="noreferrer"
84
83
  href={
85
84
  `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/` +
86
85
  `${docid}/formatters/xsl-view?output=pdf&language=eng&approved=true`
87
86
  }
87
+ rel="noopener"
88
88
  >
89
89
  Metadata Factsheet
90
90
  </a>
@@ -94,8 +94,8 @@ const MetadataSection = (props) => {
94
94
  <Icon className="ri-external-link-line" />
95
95
  <a
96
96
  target="_blank"
97
- rel="noreferrer"
98
97
  href={`${appConfig.indexBaseUrl}/catalogue/srv/eng/catalog.search#/metadata/${docid}`}
98
+ rel="noopener"
99
99
  >
100
100
  Metadata catalogue
101
101
  </a>
@@ -1,18 +1,72 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
3
-
2
+ import { render, screen } from '@testing-library/react';
3
+ import '@testing-library/jest-dom/extend-expect';
4
4
  import MetadataSection from './MetadataSection';
5
5
 
6
- describe('MetadataSection Component', () => {
7
- it('renders correctly with data', () => {
8
- const appConfig = {
9
- indexBaseUrl: 'https://sdi.eea.europa.eu',
6
+ describe('MetadataSection', () => {
7
+ const appConfig = {
8
+ indexBaseUrl: 'https://example.com',
9
+ };
10
+
11
+ const docid = '123';
12
+
13
+ it('renders metadata section when rod, organisations, or merged_time_coverage_range are available', () => {
14
+ const item = {
15
+ raw_value: {
16
+ raw: {
17
+ merged_time_coverage_range: [
18
+ { start: '2020-01-01', end: '2020-12-31' },
19
+ ],
20
+ },
21
+ },
22
+ organisation: {
23
+ raw: ['Organisation 1', 'Organisation 2'],
24
+ },
25
+ rod: {
26
+ raw: ['ROD 1', 'ROD 2'],
27
+ },
10
28
  };
11
29
 
12
- const component = renderer.create(
13
- <MetadataSection appConfig={appConfig} />,
30
+ render(<MetadataSection item={item} appConfig={appConfig} docid={docid} />);
31
+
32
+ expect(screen.getByText('More information')).toBeInTheDocument();
33
+ expect(screen.getByText('Reporting obligations (ROD)')).toBeInTheDocument();
34
+ expect(screen.getByText('ROD 1')).toBeInTheDocument();
35
+ expect(screen.getByText('ROD 2')).toBeInTheDocument();
36
+ expect(screen.getByText('Organisation:')).toBeInTheDocument();
37
+ expect(screen.getByText('Organisation 1')).toBeInTheDocument();
38
+ expect(screen.getByText('Organisation 2')).toBeInTheDocument();
39
+ expect(screen.getByText('Temporal coverage:')).toBeInTheDocument();
40
+ expect(screen.getByText('2020-01-01 - 2020-12-31')).toBeInTheDocument();
41
+ });
42
+
43
+ it('does not render metadata section when rod, organisations, and merged_time_coverage_range are not available', () => {
44
+ const item = {
45
+ raw_value: {
46
+ raw: {},
47
+ },
48
+ };
49
+
50
+ render(<MetadataSection item={item} appConfig={appConfig} docid={docid} />);
51
+
52
+ expect(screen.queryByText('More information')).not.toBeInTheDocument();
53
+ expect(
54
+ screen.queryByText('Reporting obligations (ROD)'),
55
+ ).not.toBeInTheDocument();
56
+ expect(screen.queryByText('Organisation:')).not.toBeInTheDocument();
57
+ expect(screen.queryByText('Temporal coverage:')).not.toBeInTheDocument();
58
+ });
59
+
60
+ it('renders metadata factsheet and catalogue links', () => {
61
+ render(<MetadataSection appConfig={appConfig} docid={docid} />);
62
+
63
+ expect(screen.getByText('Metadata Factsheet')).toHaveAttribute(
64
+ 'href',
65
+ `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/${docid}/formatters/xsl-view?output=pdf&language=eng&approved=true`,
66
+ );
67
+ expect(screen.getByText('Metadata catalogue')).toHaveAttribute(
68
+ 'href',
69
+ `${appConfig.indexBaseUrl}/catalogue/srv/eng/catalog.search#/metadata/${docid}`,
14
70
  );
15
- const json = component.toJSON();
16
- expect(json).toMatchSnapshot();
17
71
  });
18
72
  });
@@ -1,15 +1,70 @@
1
1
  import React from 'react';
2
- import renderer from 'react-test-renderer';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import { runRequest } from '@eeacms/search';
4
+ import '@testing-library/jest-dom/extend-expect';
3
5
 
4
6
  import MoreLikeThis from './MoreLikeThis';
5
7
 
6
- jest.mock('@eeacms/search', () => ({
7
- runRequest: jest.fn(),
8
- }));
8
+ jest.mock('@eeacms/search', () => {
9
+ return {
10
+ runRequest: jest.fn(),
11
+ firstWords: jest.fn((word, length) =>
12
+ word.split(' ').slice(0, length).join(' '),
13
+ ),
14
+ };
15
+ });
9
16
 
10
17
  describe('MoreLikeThis', () => {
11
- it('renders correctly', () => {
12
- const tree = renderer.create(<MoreLikeThis appConfig={{}} />).toJSON();
13
- expect(tree).toMatchSnapshot();
18
+ const title = 'Test title';
19
+ const docid = '123';
20
+ const appConfig = {
21
+ index_name: 'test_index',
22
+ };
23
+
24
+ it('renders similar content section when data is returned', async () => {
25
+ runRequest.mockResolvedValueOnce({
26
+ body: {
27
+ hits: {
28
+ hits: [
29
+ {
30
+ _source: {
31
+ about: '456',
32
+ label: 'Similar item 1',
33
+ description: 'Description 1',
34
+ },
35
+ },
36
+ {
37
+ _source: {
38
+ about: '789',
39
+ label: 'Similar item 2',
40
+ description: 'Description 2',
41
+ },
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ });
47
+
48
+ render(<MoreLikeThis title={title} docid={docid} appConfig={appConfig} />);
49
+
50
+ expect(screen.queryByText('Similar content')).not.toBeInTheDocument();
51
+
52
+ await waitFor(() => {
53
+ expect(screen.getByText('Similar content')).toBeInTheDocument();
54
+ expect(screen.getByText('Similar item 1')).toBeInTheDocument();
55
+ expect(screen.getByText('Description 1')).toBeInTheDocument();
56
+ expect(screen.getByText('Similar item 2')).toBeInTheDocument();
57
+ expect(screen.getByText('Description 2')).toBeInTheDocument();
58
+ });
59
+ });
60
+
61
+ it('does not render similar content section when no data is returned', async () => {
62
+ runRequest.mockResolvedValueOnce({ body: { hits: { hits: [] } } });
63
+
64
+ render(<MoreLikeThis title={title} docid={docid} appConfig={appConfig} />);
65
+
66
+ await waitFor(() => {
67
+ expect(screen.queryByText('Similar content')).not.toBeInTheDocument();
68
+ });
14
69
  });
15
70
  });
@@ -77,11 +77,11 @@ describe('groupBy', () => {
77
77
  { id: 1, name: 'test3' },
78
78
  ];
79
79
  expect(groupBy(arr, 'id')).toEqual({
80
- '1': [
80
+ 1: [
81
81
  { id: 1, name: 'test1' },
82
82
  { id: 1, name: 'test3' },
83
83
  ],
84
- '2': [{ id: 2, name: 'test2' }],
84
+ 2: [{ id: 2, name: 'test2' }],
85
85
  });
86
86
  });
87
87
  });
@@ -89,24 +89,6 @@ describe('groupBy', () => {
89
89
  describe('SVGIcon', () => {
90
90
  afterEach(cleanup);
91
91
 
92
- it('should render SVGIcon correctly', () => {
93
- const { container } = render(
94
- <SVGIcon
95
- name={{
96
- attributes: {
97
- xmlns: 'http://www.w3.org/2000/svg',
98
- viewBox: '0 0 32 32',
99
- },
100
- content: '<path d="M2 9h28l-14 14L2 9z"></path>',
101
- }}
102
- className={'test'}
103
- title={'test title'}
104
- size="32px"
105
- />,
106
- );
107
- expect(container.firstChild).toMatchSnapshot();
108
- });
109
-
110
92
  it('should call onClick when clicked', () => {
111
93
  const onClick = jest.fn();
112
94
  const { container } = render(
@@ -194,10 +194,12 @@ const facets = [
194
194
  }),
195
195
  ];
196
196
 
197
- export default {
197
+ const facetsWrapper = {
198
198
  facets,
199
199
  };
200
200
 
201
+ export default facetsWrapper;
202
+
201
203
  // wrapper: 'ModalFacetWrapper',
202
204
  // factory: 'MultiTermListFacet',
203
205
  // histogramFacet({
@@ -1,4 +1,6 @@
1
- export default {
1
+ const filters = {
2
2
  // filter values that are always added to the ES requests
3
3
  permanentFilters: [{ term: { cluster_name: 'sdi' } }],
4
4
  };
5
+
6
+ export default filters;
@@ -1,14 +1,9 @@
1
1
  import { ResultModel } from '@eeacms/search';
2
- const path = require('path');
3
2
 
4
3
  export class DatahubResultModel extends ResultModel {
5
4
  get href() {
6
5
  if (__CLIENT__) {
7
- return path.join(
8
- window.location.pathname,
9
- 'datahubitem-view/',
10
- this._result.about?.raw,
11
- );
6
+ return `${window.location.pathname}/datahubitem-view/${this._result.about?.raw}`;
12
7
  } else {
13
8
  return ''; //TODO
14
9
  }
@@ -1,4 +1,4 @@
1
- export default {
1
+ const views = {
2
2
  resultViews: [
3
3
  {
4
4
  id: 'datahubCards',
@@ -49,3 +49,5 @@ export default {
49
49
  },
50
50
  },
51
51
  };
52
+
53
+ export default views;
@@ -4,4 +4,6 @@ const vocab = {
4
4
  },
5
5
  };
6
6
 
7
- export default { vocab };
7
+ const vocabWrapper = { vocab };
8
+
9
+ export default vocabWrapper;
package/src/utils.js CHANGED
@@ -83,14 +83,13 @@ export function parseDatasets(children) {
83
83
  const groupDatasets = (items) => {
84
84
  const datasetsByCoverage = groupBy(items, 'temporalDateRange');
85
85
 
86
- const sortedDatasets = Object.keys(datasetsByCoverage).sort(function (
87
- a,
88
- b,
89
- ) {
90
- a = Math.max(...a.split('-'));
91
- b = Math.max(...b.split('-'));
92
- return b - a;
93
- });
86
+ const sortedDatasets = Object.keys(datasetsByCoverage).sort(
87
+ function (a, b) {
88
+ a = Math.max(...a.split('-'));
89
+ b = Math.max(...b.split('-'));
90
+ return b - a;
91
+ },
92
+ );
94
93
 
95
94
  const groupedDatasets = sortedDatasets.map((v, i) => {
96
95
  return { id: i, date: v, children: datasetsByCoverage[v] };
@@ -1,53 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- const projectRootPath = fs.existsSync('./project')
5
- ? fs.realpathSync('./project')
6
- : fs.realpathSync('./../../../');
7
- const packageJson = require(path.join(projectRootPath, 'package.json'));
8
- const jsConfig = require(path.join(projectRootPath, 'jsconfig.json'))
9
- .compilerOptions;
10
-
11
- const pathsConfig = jsConfig.paths;
12
-
13
- let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');
14
-
15
- Object.keys(pathsConfig).forEach((pkg) => {
16
- if (pkg === '@plone/volto') {
17
- voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`;
18
- }
19
- });
20
- const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
21
- const reg = new AddonConfigurationRegistry(projectRootPath);
22
-
23
- // Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
24
- const addonAliases = Object.keys(reg.packages).map((o) => [
25
- o,
26
- reg.packages[o].modulePath,
27
- ]);
28
-
29
- const voltoSearchlibPath = path.dirname(
30
- reg.packages['@eeacms/volto-searchlib'].modulePath,
31
- );
32
- const searchlibPath = path.resolve(`${voltoSearchlibPath}/searchlib`);
33
-
34
- module.exports = {
35
- extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`,
36
- settings: {
37
- 'import/resolver': {
38
- alias: {
39
- map: [
40
- ['@plone/volto', '@plone/volto/src'],
41
- ...addonAliases,
42
- ['@eeacms/search', searchlibPath],
43
- ['@package', `${__dirname}/src`],
44
- ['~', `${__dirname}/src`],
45
- ],
46
- extensions: ['.js', '.jsx', '.json'],
47
- },
48
- 'babel-plugin-root-import': {
49
- rootPathSuffix: 'src',
50
- },
51
- },
52
- },
53
- };