@eeacms/volto-datahub 1.0.33 → 2.0.1

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 CHANGED
@@ -1,24 +1,21 @@
1
1
  const fs = require('fs');
2
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(
9
- projectRootPath,
10
- 'jsconfig.json',
11
- )).compilerOptions;
12
-
13
- const pathsConfig = jsConfig.paths;
3
+ const projectRootPath = fs.realpathSync(__dirname + '/../../../');
14
4
 
15
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
+ }
16
18
 
17
- Object.keys(pathsConfig).forEach((pkg) => {
18
- if (pkg === '@plone/volto') {
19
- voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`;
20
- }
21
- });
22
19
  const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
23
20
  const reg = new AddonConfigurationRegistry(projectRootPath);
24
21
 
@@ -28,21 +25,19 @@ const addonAliases = Object.keys(reg.packages).map((o) => [
28
25
  reg.packages[o].modulePath,
29
26
  ]);
30
27
 
31
- const voltoSearchlibPath = path.dirname(
32
- reg.packages['@eeacms/volto-searchlib'].modulePath,
33
- );
34
- const searchlibPath = path.resolve(`${voltoSearchlibPath}/searchlib`);
28
+ const addonExtenders = reg.getEslintExtenders().map((m) => require(m));
35
29
 
36
- module.exports = {
37
- extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`,
30
+ const defaultConfig = {
31
+ extends: `${voltoPath}/.eslintrc`,
38
32
  settings: {
39
33
  'import/resolver': {
40
34
  alias: {
41
35
  map: [
42
36
  ['@plone/volto', '@plone/volto/src'],
37
+ ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'],
43
38
  ...addonAliases,
44
- ['@eeacms/search', searchlibPath],
45
39
  ['@package', `${__dirname}/src`],
40
+ ['@root', `${__dirname}/src`],
46
41
  ['~', `${__dirname}/src`],
47
42
  ],
48
43
  extensions: ['.js', '.jsx', '.json'],
@@ -53,6 +48,18 @@ module.exports = {
53
48
  },
54
49
  },
55
50
  rules: {
56
- 'react/jsx-no-target-blank': 'off',
57
- },
51
+ 'react/jsx-no-target-blank': [
52
+ 'error',
53
+ {
54
+ allowReferrer: true,
55
+ },
56
+ ],
57
+ }
58
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,7 +4,20 @@ 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
- ### [1.0.33](https://github.com/eea/volto-datahub/compare/1.0.32...1.0.33) - 12 March 2024
7
+ ### [2.0.1](https://github.com/eea/volto-datahub/compare/2.0.0...2.0.1) - 6 August 2024
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Bump cypress version to fix cypress testing [kreafox - [`e094261`](https://github.com/eea/volto-datahub/commit/e0942614768cf0f349cf8e31744d087d6ea72a55)]
12
+ - Refs #273191 - remove hide condition for type nonGeographicDataset [Tripon Eugen - [`846b4c2`](https://github.com/eea/volto-datahub/commit/846b4c274425fb17d79c8f1ac0a869659cd4c1f8)]
13
+ ## [2.0.0](https://github.com/eea/volto-datahub/compare/1.0.33...2.0.0) - 22 April 2024
14
+
15
+ #### :rocket: New Features
16
+
17
+ - feat: Release 2.0.0 - Volto 17 support [alin - [`1ea48ae`](https://github.com/eea/volto-datahub/commit/1ea48ae306f13cea5729ba55a5b77f79fe0d8716)]
18
+ - feat: Volto 17 support - refs #264527 [EEA Jenkins - [`309c256`](https://github.com/eea/volto-datahub/commit/309c256a62ce3807dd272520ff931bf3cff7f724)]
19
+
20
+ ### [1.0.33](https://github.com/eea/volto-datahub/compare/1.0.32...1.0.33) - 13 March 2024
8
21
 
9
22
  #### :boom: Breaking Change
10
23
 
@@ -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.33",
3
+ "version": "2.0.1",
4
4
  "description": "@eeacms/volto-datahub: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -23,9 +23,11 @@
23
23
  "feed": "4.2.2"
24
24
  },
25
25
  "devDependencies": {
26
+ "cypress": "13.1.0",
26
27
  "@cypress/code-coverage": "^3.10.0",
27
28
  "@plone/scripts": "*",
28
29
  "babel-plugin-transform-class-properties": "^6.24.1",
30
+ "dotenv": "^16.3.2",
29
31
  "husky": "^8.0.3",
30
32
  "lint-staged": "^14.0.1",
31
33
  "md5": "^2.3.0"
@@ -10,7 +10,7 @@ const ItemLink = ({ item }) => (
10
10
  <List.Content>
11
11
  <div className="dataset-item">
12
12
  <SVGIcon name={servicesSVG} size="20px" />
13
- <a className="item-link" href={item.url} target="_blank">
13
+ <a className="item-link" href={item.url} target="_blank" rel="noopener">
14
14
  {item.protocol} {item.name || item.description}
15
15
  </a>
16
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,51 +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 href={item.url} className="item-link" target="_blank">
19
- <span>{item.name || item.url}</span>
20
- </a>
21
- {isInternalURL(item.url) ? (
22
- <SVGIcon name={lockSVG} size="20px" />
23
- ) : null}
24
- </div>
25
- </List.Content>
26
- {item.description ? (
27
- <span className="item-description">{item.description}</span>
28
- ) : null}
29
- </List.Item>
30
- );
31
- })}
32
- {(dataset['DOI'] || []).map((item, i) => {
33
- return (
34
- <List.Item key={i}>
35
- <List.Content>
36
- <div className="dataset-item">
37
- <Icon className="info circle" />
38
- <a href={item.url} className="item-link" target="_blank">
39
- <span>{item.name || item.url}</span>
40
- </a>
41
- {isInternalURL(item.url) ? (
42
- <SVGIcon name={lockSVG} size="20px" />
43
- ) : null}
44
- </div>
45
- </List.Content>
46
- {item.description ? (
47
- <span className="item-description">{item.description}</span>
48
- ) : null}
49
- </List.Item>
50
- );
51
- })}
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
+ )}
52
37
  </List>
53
38
  </>
54
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
  });
@@ -143,7 +143,6 @@ const DatasetItemsList = (props) => {
143
143
  } = dataset;
144
144
  const archived = isObsolete(dataset.cl_status);
145
145
  const active = isActive(id);
146
-
147
146
  return (
148
147
  <>
149
148
  <Accordion id={id} key={index}>
@@ -238,23 +237,21 @@ const DatasetItemsList = (props) => {
238
237
  )}
239
238
  </div>
240
239
 
241
- {dataset.resourceType[0] !== 'nonGeographicDataset' && (
242
- <div className="dataset-pdf">
243
- <div className="d-link">
244
- <Icon className="file pdf" />
245
- <a
246
- target="_blank"
247
- rel="noreferrer"
248
- href={
249
- `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/` +
250
- `${dataset.metadataIdentifier}/formatters/xsl-view?output=pdf&language=eng&approved=true`
251
- }
252
- >
253
- Metadata Factsheet
254
- </a>
255
- </div>
240
+ <div className="dataset-pdf">
241
+ <div className="d-link">
242
+ <Icon className="file pdf" />
243
+ <a
244
+ target="_blank"
245
+ rel="noreferrer"
246
+ href={
247
+ `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/` +
248
+ `${dataset.metadataIdentifier}/formatters/xsl-view?output=pdf&language=eng&approved=true`
249
+ }
250
+ >
251
+ Metadata Factsheet
252
+ </a>
256
253
  </div>
257
- )}
254
+ </div>
258
255
  </div>
259
256
 
260
257
  {!!dataset.link && dataset.link.length > 0 && (
@@ -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
  <>
@@ -84,6 +84,7 @@ const MetadataSection = (props) => {
84
84
  `${appConfig.indexBaseUrl}/catalogue/datahub/api/records/` +
85
85
  `${docid}/formatters/xsl-view?output=pdf&language=eng&approved=true`
86
86
  }
87
+ rel="noopener"
87
88
  >
88
89
  Metadata Factsheet
89
90
  </a>
@@ -94,6 +95,7 @@ const MetadataSection = (props) => {
94
95
  <a
95
96
  target="_blank"
96
97
  href={`${appConfig.indexBaseUrl}/catalogue/srv/eng/catalog.search#/metadata/${docid}`}
98
+ rel="noopener"
97
99
  >
98
100
  Metadata catalogue
99
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,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] };