@eeacms/volto-cca-policy 0.3.47 → 0.3.49

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/CHANGELOG.md CHANGED
@@ -4,7 +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
- ### [0.3.47](https://github.com/eea/volto-cca-policy/compare/0.3.46...0.3.47) - 21 May 2025
7
+ ### [0.3.49](https://github.com/eea/volto-cca-policy/compare/0.3.48...0.3.49) - 23 May 2025
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - Update version for volto-openlayers-map [Tiberiu Ichim - [`51908ca`](https://github.com/eea/volto-cca-policy/commit/51908cac74f8498ed6ad76644db928a175d58a06)]
12
+ ### [0.3.48](https://github.com/eea/volto-cca-policy/compare/0.3.47...0.3.48) - 22 May 2025
13
+
14
+ #### :hammer_and_wrench: Others
15
+
16
+ - Mocked services needed to pass CaseStudyMap.test.jsx [David Ichim - [`3bd411f`](https://github.com/eea/volto-cca-policy/commit/3bd411f9e83863727ba43642838b10fc9ca199f3)]
17
+ - Add latest version [Tiberiu Ichim - [`6e89bbe`](https://github.com/eea/volto-cca-policy/commit/6e89bbeb5bf400af6f38ac872230754bdc0c63d3)]
18
+ - Customize testing addon harness based on volto-listing-block example, to support custom version of openlayers addon [Tiberiu Ichim - [`da0f7ae`](https://github.com/eea/volto-cca-policy/commit/da0f7ae8804dafc793e62eaca963697f220c633c)]
19
+ - Use new commit [Tiberiu Ichim - [`c625488`](https://github.com/eea/volto-cca-policy/commit/c625488eff82c1e5e3e75dda88010a83f14daeea)]
20
+ - Fix eslint [Tiberiu Ichim - [`ac10036`](https://github.com/eea/volto-cca-policy/commit/ac1003670b3e8ab1a57fa180626948692ea1dff2)]
21
+ - Depend on fixed commit of volto-openlayers-map [Tiberiu Ichim - [`67081a7`](https://github.com/eea/volto-cca-policy/commit/67081a7087f4cd7f45bdfa60376a7c7194d385ed)]
22
+ - WIP on lazyload openlayers [Tiberiu Ichim - [`a424e80`](https://github.com/eea/volto-cca-policy/commit/a424e803af3551f280f79816c1fb7eaeb13c4f4c)]
23
+ - WIP on lazyload openlayers [Tiberiu Ichim - [`5526e30`](https://github.com/eea/volto-cca-policy/commit/5526e3060c2fbec22e3269fbdd4e820bd035c52b)]
24
+ - Revert from develop [Tiberiu Ichim - [`1396bdd`](https://github.com/eea/volto-cca-policy/commit/1396bdd51a391b8e5bd7bfae5e661903426f121e)]
25
+ - Cleanup [Tiberiu Ichim - [`c8a3ae1`](https://github.com/eea/volto-cca-policy/commit/c8a3ae11a3275a8ccf2e941058a2280275de15ab)]
26
+ - Fix country map observatory [Tiberiu Ichim - [`6fb83ea`](https://github.com/eea/volto-cca-policy/commit/6fb83eaf6d5be0cbe595b6ce0e77eb8581198291)]
27
+ - Enable the cluster style [Tiberiu Ichim - [`8c0e8e0`](https://github.com/eea/volto-cca-policy/commit/8c0e8e092053041dddacc751ed34ed944de1c477)]
28
+ - WIP on lazyload openlayers [Tiberiu Ichim - [`11cf2da`](https://github.com/eea/volto-cca-policy/commit/11cf2da4566ffc8cab1682dc508e9680999fb7d2)]
29
+ - WIP on lazyload openlayers [Tiberiu Ichim - [`b9f41e2`](https://github.com/eea/volto-cca-policy/commit/b9f41e232c8f88e5ccc03cd04f0d59dc935d878d)]
30
+ ### [0.3.47](https://github.com/eea/volto-cca-policy/compare/0.3.46...0.3.47) - 22 May 2025
8
31
 
9
32
  #### :nail_care: Enhancements
10
33
 
@@ -1,10 +1,414 @@
1
- require('dotenv').config({ path: __dirname + '/.env' })
1
+ /**
2
+ * Generic Jest configuration for Volto addons
3
+ *
4
+ * This configuration automatically:
5
+ * - Detects the addon name from the config file path
6
+ * - Configures test coverage to focus on the specific test path
7
+ * - Handles different ways of specifying test paths:
8
+ * - Full paths like src/addons/addon-name/src/components
9
+ * - Just filenames like Component.test.jsx
10
+ * - Just directory names like components
11
+ *
12
+ * Usage:
13
+ * RAZZLE_JEST_CONFIG=src/addons/addon-name/jest-addon.config.js CI=true yarn test [test-path] --collectCoverage
14
+ */
15
+
16
+ require('dotenv').config({ path: __dirname + '/.env' });
17
+
18
+ const path = require('path');
19
+ const fs = require('fs');
20
+ const fg = require('fast-glob');
21
+
22
+ // Get the addon name from the current file path
23
+ const pathParts = __filename.split(path.sep);
24
+ const addonsIdx = pathParts.lastIndexOf('addons');
25
+ const addonName =
26
+ addonsIdx !== -1 && addonsIdx < pathParts.length - 1
27
+ ? pathParts[addonsIdx + 1]
28
+ : 'volto-listing-block'; // Fallback addon name
29
+ const addonBasePath = `src/addons/${addonName}/src`;
30
+
31
+ // --- Performance caches ---
32
+ const fileSearchCache = new Map();
33
+ const dirSearchCache = new Map();
34
+ const dirListingCache = new Map();
35
+ const statCache = new Map();
36
+ const implementationCache = new Map();
37
+
38
+ /**
39
+ * Cached fs.statSync wrapper to avoid redundant filesystem calls
40
+ * @param {string} p
41
+ * @returns {fs.Stats|null}
42
+ */
43
+ const getStatSync = (p) => {
44
+ if (statCache.has(p)) return statCache.get(p);
45
+ try {
46
+ const s = fs.statSync(p);
47
+ statCache.set(p, s);
48
+ return s;
49
+ } catch {
50
+ statCache.set(p, null);
51
+ return null;
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Find files that match a specific pattern using fast-glob
57
+ * @param {string} baseDir - The base directory to search in
58
+ * @param {string} fileName - The name of the file to find
59
+ * @param {string} [pathPattern=''] - Optional path pattern to filter results
60
+ * @returns {string[]} - Array of matching file paths
61
+ */
62
+ const findFilesWithPattern = (baseDir, fileName, pathPattern = '') => {
63
+ const cacheKey = `${baseDir}|${fileName}|${pathPattern}`;
64
+ if (fileSearchCache.has(cacheKey)) {
65
+ return fileSearchCache.get(cacheKey);
66
+ }
67
+
68
+ let files = [];
69
+ try {
70
+ const patterns = fileName
71
+ ? [`${baseDir}/**/${fileName}`]
72
+ : [`${baseDir}/**/*.{js,jsx,ts,tsx}`];
73
+
74
+ files = fg.sync(patterns, { onlyFiles: true });
75
+
76
+ if (pathPattern) {
77
+ files = files.filter((file) => file.includes(pathPattern));
78
+ }
79
+ } catch {
80
+ files = [];
81
+ }
82
+
83
+ fileSearchCache.set(cacheKey, files);
84
+ return files;
85
+ };
86
+
87
+ /**
88
+ * Find directories that match a specific pattern using fast-glob
89
+ * @param {string} baseDir - The base directory to search in
90
+ * @param {string} dirName - The name of the directory to find
91
+ * @param {string} [pathPattern=''] - Optional path pattern to filter results
92
+ * @returns {string[]} - Array of matching directory paths
93
+ */
94
+ const findDirsWithPattern = (baseDir, dirName, pathPattern = '') => {
95
+ const cacheKey = `${baseDir}|${dirName}|${pathPattern}`;
96
+ if (dirSearchCache.has(cacheKey)) {
97
+ return dirSearchCache.get(cacheKey);
98
+ }
99
+
100
+ let dirs = [];
101
+ try {
102
+ const patterns = dirName
103
+ ? [`${baseDir}/**/${dirName}`]
104
+ : [`${baseDir}/**/`];
105
+
106
+ dirs = fg.sync(patterns, { onlyDirectories: true });
107
+
108
+ if (pathPattern) {
109
+ dirs = dirs.filter((dir) => dir.includes(pathPattern));
110
+ }
111
+ } catch {
112
+ dirs = [];
113
+ }
114
+
115
+ dirSearchCache.set(cacheKey, dirs);
116
+ return dirs;
117
+ };
118
+
119
+ /**
120
+ * Find files or directories in the addon using fast-glob
121
+ * @param {string} name - The name to search for
122
+ * @param {string} type - The type of item to find ('f' for files, 'd' for directories)
123
+ * @param {string} [additionalOptions=''] - Additional options for flexible path matching
124
+ * @returns {string|null} - The path of the found item or null if not found
125
+ */
126
+ const findInAddon = (name, type, additionalOptions = '') => {
127
+ const isFile = type === 'f';
128
+ const isDirectory = type === 'd';
129
+ const isFlexiblePathMatch = additionalOptions.includes('-path');
130
+
131
+ let pathPattern = '';
132
+ if (isFlexiblePathMatch) {
133
+ const match = additionalOptions.match(/-path "([^"]+)"/);
134
+ if (match && match[1]) {
135
+ pathPattern = match[1].replace(/\*/g, '');
136
+ }
137
+ }
138
+
139
+ try {
140
+ let results = [];
141
+ if (isFile) {
142
+ results = findFilesWithPattern(addonBasePath, name, pathPattern);
143
+ } else if (isDirectory) {
144
+ results = findDirsWithPattern(addonBasePath, name, pathPattern);
145
+ }
146
+ return results.length > 0 ? results[0] : null;
147
+ } catch (error) {
148
+ return null;
149
+ }
150
+ };
151
+
152
+ /**
153
+ * Find the implementation file for a test file
154
+ * @param {string} testPath - Path to the test file
155
+ * @returns {string|null} - Path to the implementation file or null if not found
156
+ */
157
+ const findImplementationFile = (testPath) => {
158
+ if (implementationCache.has(testPath)) {
159
+ return implementationCache.get(testPath);
160
+ }
161
+
162
+ if (!fs.existsSync(testPath)) {
163
+ implementationCache.set(testPath, null);
164
+ return null;
165
+ }
166
+
167
+ const dirPath = path.dirname(testPath);
168
+ const fileName = path.basename(testPath);
169
+
170
+ // Regex for common test file patterns (e.g., .test.js, .spec.ts)
171
+ const TEST_OR_SPEC_FILE_REGEX = /\.(test|spec)\.[jt]sx?$/;
172
+
173
+ if (!TEST_OR_SPEC_FILE_REGEX.test(fileName)) {
174
+ implementationCache.set(testPath, null);
175
+ return null;
176
+ }
177
+
178
+ const baseFileName = path
179
+ .basename(fileName, path.extname(fileName))
180
+ .replace(/\.(test|spec)$/, ''); // Remove .test or .spec
181
+
182
+ let dirFiles = dirListingCache.get(dirPath);
183
+ if (!dirFiles) {
184
+ dirFiles = fs.readdirSync(dirPath);
185
+ dirListingCache.set(dirPath, dirFiles);
186
+ }
187
+
188
+ const exactMatch = dirFiles.find((file) => {
189
+ const fileBaseName = path.basename(file, path.extname(file));
190
+ return (
191
+ fileBaseName === baseFileName && !TEST_OR_SPEC_FILE_REGEX.test(file) // Ensure it's not another test/spec file
192
+ );
193
+ });
194
+
195
+ if (exactMatch) {
196
+ const result = `${dirPath}/${exactMatch}`;
197
+ implementationCache.set(testPath, result);
198
+ return result;
199
+ }
200
+
201
+ const similarMatch = dirFiles.find((file) => {
202
+ if (
203
+ TEST_OR_SPEC_FILE_REGEX.test(file) ||
204
+ (getStatSync(`${dirPath}/${file}`)?.isDirectory() ?? false)
205
+ ) {
206
+ return false;
207
+ }
208
+ const fileBaseName = path.basename(file, path.extname(file));
209
+ return (
210
+ fileBaseName.toLowerCase().includes(baseFileName.toLowerCase()) ||
211
+ baseFileName.toLowerCase().includes(fileBaseName.toLowerCase())
212
+ );
213
+ });
214
+
215
+ if (similarMatch) {
216
+ const result = `${dirPath}/${similarMatch}`;
217
+ implementationCache.set(testPath, result);
218
+ return result;
219
+ }
220
+
221
+ implementationCache.set(testPath, null);
222
+ return null;
223
+ };
224
+
225
+ /**
226
+ * Get the test path from command line arguments
227
+ * @returns {string|null} - The resolved test path or null if not found
228
+ */
229
+ const getTestPath = () => {
230
+ const args = process.argv;
231
+ let testPath = null;
232
+ const TEST_FILE_REGEX = /\.test\.[jt]sx?$/; // Matches .test.js, .test.jsx, .test.ts, .test.tsx
233
+
234
+ testPath = args.find(
235
+ (arg) =>
236
+ arg.includes(addonName) &&
237
+ !arg.startsWith('--') &&
238
+ arg !== 'test' &&
239
+ arg !== 'node',
240
+ );
241
+
242
+ if (!testPath) {
243
+ const testIndex = args.findIndex((arg) => arg === 'test');
244
+ if (testIndex !== -1 && testIndex < args.length - 1) {
245
+ const nextArg = args[testIndex + 1];
246
+ if (!nextArg.startsWith('--')) {
247
+ testPath = nextArg;
248
+ }
249
+ }
250
+ }
251
+
252
+ if (!testPath) {
253
+ testPath = args.find((arg) => TEST_FILE_REGEX.test(arg));
254
+ }
255
+
256
+ if (!testPath) {
257
+ return null;
258
+ }
259
+
260
+ if (!testPath.includes(path.sep)) {
261
+ if (TEST_FILE_REGEX.test(testPath)) {
262
+ const foundTestFile = findInAddon(testPath, 'f');
263
+ if (foundTestFile) {
264
+ return foundTestFile;
265
+ }
266
+ } else {
267
+ const foundDir = findInAddon(testPath, 'd');
268
+ if (foundDir) {
269
+ return foundDir;
270
+ }
271
+ const flexibleDir = findInAddon(testPath, 'd', `-path "*${testPath}*"`);
272
+ if (flexibleDir) {
273
+ return flexibleDir;
274
+ }
275
+ }
276
+ } else if (
277
+ TEST_FILE_REGEX.test(testPath) && // Check if it looks like a test file path
278
+ !testPath.startsWith('src/addons/')
279
+ ) {
280
+ const testFileName = path.basename(testPath);
281
+ const foundTestFile = findInAddon(testFileName, 'f');
282
+ if (foundTestFile) {
283
+ const relativePath = path.dirname(testPath);
284
+ if (foundTestFile.includes(relativePath)) {
285
+ return foundTestFile;
286
+ }
287
+ const similarFiles = findFilesWithPattern(
288
+ addonBasePath,
289
+ testFileName,
290
+ relativePath,
291
+ );
292
+ if (similarFiles && similarFiles.length > 0) {
293
+ return similarFiles[0];
294
+ }
295
+ }
296
+ }
297
+
298
+ if (
299
+ !path
300
+ .normalize(testPath)
301
+ .startsWith(path.join('src', 'addons', addonName, 'src')) &&
302
+ !path.isAbsolute(testPath) // Use path.isAbsolute for robust check
303
+ ) {
304
+ testPath = path.join(addonBasePath, testPath); // Use path.join for OS-agnostic paths
305
+ }
306
+
307
+ if (fs.existsSync(testPath)) {
308
+ return testPath;
309
+ }
310
+
311
+ const pathWithoutTrailingSlash = testPath.endsWith(path.sep)
312
+ ? testPath.slice(0, -1)
313
+ : null;
314
+ if (pathWithoutTrailingSlash && fs.existsSync(pathWithoutTrailingSlash)) {
315
+ return pathWithoutTrailingSlash;
316
+ }
317
+
318
+ const pathWithTrailingSlash = !testPath.endsWith(path.sep)
319
+ ? testPath + path.sep
320
+ : null;
321
+ if (pathWithTrailingSlash && fs.existsSync(pathWithTrailingSlash)) {
322
+ // Generally, return paths without trailing slashes for consistency,
323
+ // unless it's specifically needed for a directory that only exists with it (rare).
324
+ return testPath;
325
+ }
326
+ return testPath; // Return the original path if no variations exist
327
+ };
328
+
329
+ /**
330
+ * Determine collectCoverageFrom patterns based on test path
331
+ * @returns {string[]} - Array of coverage patterns
332
+ */
333
+ const getCoveragePatterns = () => {
334
+ const excludePatterns = [
335
+ '!src/**/*.d.ts',
336
+ '!**/*.test.{js,jsx,ts,tsx}',
337
+ '!**/*.spec.{js,jsx,ts,tsx}',
338
+ ];
339
+
340
+ const defaultPatterns = [
341
+ `${addonBasePath}/**/*.{js,jsx,ts,tsx}`,
342
+ ...excludePatterns,
343
+ ];
344
+
345
+ const ANY_SCRIPT_FILE_REGEX = /\.[jt]sx?$/;
346
+
347
+ const directoryArg = process.argv.find(
348
+ (arg) =>
349
+ !arg.includes(path.sep) &&
350
+ !arg.startsWith('--') &&
351
+ arg !== 'test' &&
352
+ arg !== 'node' &&
353
+ !ANY_SCRIPT_FILE_REGEX.test(arg) &&
354
+ ![
355
+ 'yarn',
356
+ 'npm',
357
+ 'npx',
358
+ 'collectCoverage',
359
+ 'CI',
360
+ 'RAZZLE_JEST_CONFIG',
361
+ ].some(
362
+ (reserved) =>
363
+ arg === reserved || arg.startsWith(reserved.split('=')[0] + '='),
364
+ ) &&
365
+ process.argv.indexOf(arg) >
366
+ process.argv.findIndex((item) => item === 'test'),
367
+ );
368
+
369
+ if (directoryArg) {
370
+ const foundDir = findInAddon(directoryArg, 'd');
371
+ if (foundDir) {
372
+ return [`${foundDir}/**/*.{js,jsx,ts,tsx}`, ...excludePatterns];
373
+ }
374
+ }
375
+
376
+ let testPath = getTestPath();
377
+
378
+ if (!testPath) {
379
+ return defaultPatterns;
380
+ }
381
+
382
+ if (testPath.endsWith(path.sep)) {
383
+ testPath = testPath.slice(0, -1);
384
+ }
385
+
386
+ const stats = getStatSync(testPath);
387
+
388
+ if (stats && stats.isFile()) {
389
+ const implFile = findImplementationFile(testPath);
390
+ if (implFile) {
391
+ return [implFile, '!src/**/*.d.ts'];
392
+ }
393
+ const dirPath = path.dirname(testPath);
394
+ return [`${dirPath}/**/*.{js,jsx,ts,tsx}`, ...excludePatterns];
395
+ } else if (stats && stats.isDirectory()) {
396
+ return [`${testPath}/**/*.{js,jsx,ts,tsx}`, ...excludePatterns];
397
+ }
398
+
399
+ return defaultPatterns;
400
+ };
401
+
402
+ const coverageConfig = getCoveragePatterns();
2
403
 
3
404
  module.exports = {
4
405
  testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
5
- collectCoverageFrom: [
6
- 'src/addons/**/src/**/*.{js,jsx,ts,tsx}',
7
- '!src/**/*.d.ts',
406
+ collectCoverageFrom: coverageConfig,
407
+ coveragePathIgnorePatterns: [
408
+ '/node_modules/',
409
+ 'schema\\.[jt]s?$',
410
+ 'index\\.[jt]s?$',
411
+ 'config\\.[jt]sx?$',
8
412
  ],
9
413
  moduleNameMapper: {
10
414
  '\\.(css|less|scss|sass)$': 'identity-obj-proxy',
@@ -30,6 +434,7 @@ module.exports = {
30
434
  ],
31
435
  transform: {
32
436
  '^.+\\.js(x)?$': 'babel-jest',
437
+ '^.+\\.ts(x)?$': 'babel-jest',
33
438
  '^.+\\.(png)$': 'jest-file',
34
439
  '^.+\\.(jpg)$': 'jest-file',
35
440
  '^.+\\.(svg)$': './node_modules/@plone/volto/jest-svgsystem-transform.js',
@@ -44,7 +449,17 @@ module.exports = {
44
449
  },
45
450
  ...(process.env.JEST_USE_SETUP === 'ON' && {
46
451
  setupFilesAfterEnv: [
47
- '<rootDir>/node_modules/@eeacms/volto-cca-policy/jest.setup.js',
452
+ fs.existsSync(
453
+ path.join(
454
+ __dirname,
455
+ 'node_modules',
456
+ '@eeacms',
457
+ addonName,
458
+ 'jest.setup.js',
459
+ ),
460
+ )
461
+ ? `<rootDir>/node_modules/@eeacms/${addonName}/jest.setup.js`
462
+ : `<rootDir>/src/addons/${addonName}/jest.setup.js`,
48
463
  ],
49
464
  }),
50
- }
465
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-cca-policy",
3
- "version": "0.3.47",
3
+ "version": "0.3.49",
4
4
  "description": "@eeacms/volto-cca-policy: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -34,7 +34,7 @@
34
34
  "@eeacms/volto-embed": "^9.1.1",
35
35
  "@eeacms/volto-globalsearch": "2.1.2",
36
36
  "@eeacms/volto-hero-block": "^7.1.0",
37
- "@eeacms/volto-openlayers-map": "*",
37
+ "@eeacms/volto-openlayers-map": "github:eea/volto-openlayers-map#1.0.0-alpha.1",
38
38
  "@eeacms/volto-searchlib": "2.0.16",
39
39
  "@eeacms/volto-slate-label": "^0.6.0",
40
40
  "@eeacms/volto-tabs-block": "^7.5.1",
@@ -1,17 +1,17 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Map, Layer, Layers } from '@eeacms/volto-openlayers-map/api';
4
- import { openlayers as ol } from '@eeacms/volto-openlayers-map';
4
+ import { withOpenLayers } from '@eeacms/volto-openlayers-map';
5
5
 
6
6
  import FeatureInteraction from './FeatureInteraction';
7
7
 
8
8
  import { getFeatures } from './utils';
9
9
 
10
- export default function CaseStudyMap(props) {
11
- const { items, activeItems } = props;
10
+ function CaseStudyMap(props) {
11
+ const { items, activeItems, ol } = props;
12
12
  const [selectedCase, onSelectedCase] = React.useState();
13
13
 
14
- const features = React.useMemo(() => getFeatures(items), [items]);
14
+ const features = React.useMemo(() => getFeatures(items, ol), [items, ol]);
15
15
 
16
16
  const [tileWMSSources] = React.useState([
17
17
  new ol.source.TileWMS({
@@ -32,7 +32,7 @@ export default function CaseStudyMap(props) {
32
32
  showFullExtent: true,
33
33
  zoom: 4,
34
34
  }),
35
- [],
35
+ [ol.proj],
36
36
  );
37
37
 
38
38
  return features.length > 0 ? (
@@ -48,9 +48,11 @@ export default function CaseStudyMap(props) {
48
48
  mapCenter={mapCenter}
49
49
  features={features}
50
50
  activeItems={activeItems}
51
+ ol={ol}
51
52
  />
52
53
  <Layer.Tile source={tileWMSSources[0]} zIndex={0} />
53
54
  </Layers>
54
55
  </Map>
55
56
  ) : null;
56
57
  }
58
+ export default withOpenLayers(CaseStudyMap);
@@ -35,6 +35,23 @@ jest.mock('@eeacms/volto-openlayers-map', () => ({
35
35
  defaults: jest.fn().mockReturnValue([]),
36
36
  },
37
37
  },
38
+ // Add the withOpenLayers HOC mock
39
+ withOpenLayers: (Component) => (props) => (
40
+ <Component
41
+ {...props}
42
+ ol={{
43
+ source: {
44
+ TileWMS: jest.fn().mockImplementation(() => ({})),
45
+ },
46
+ proj: {
47
+ fromLonLat: jest.fn().mockReturnValue([0, 0]),
48
+ },
49
+ control: {
50
+ defaults: jest.fn().mockReturnValue([]),
51
+ },
52
+ }}
53
+ />
54
+ ),
38
55
  }));
39
56
 
40
57
  jest.mock('./FeatureInteraction', () => () => (
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import { openlayers as ol } from '@eeacms/volto-openlayers-map';
3
2
  import { useMapContext } from '@eeacms/volto-openlayers-map/api';
4
3
  import FeatureDisplay from './FeatureDisplay';
5
4
  import { getFeatures } from './utils';
@@ -16,11 +15,12 @@ export default function FeatureInteraction({
16
15
  mapCenter,
17
16
  features,
18
17
  activeItems,
18
+ ol,
19
19
  }) {
20
20
  const { map } = useMapContext();
21
21
  const [clusterLayer, setClusterLayer] = React.useState();
22
22
  const [clusterCirclesLayer, setClusterCirclesLayer] = React.useState();
23
- const { selectStyle, clusterCircleStyle } = useStyles();
23
+ const { selectStyle, clusterCircleStyle } = useStyles(ol);
24
24
 
25
25
  const [pointsSource] = React.useState(
26
26
  new ol.source.Vector({
@@ -38,9 +38,9 @@ export default function FeatureInteraction({
38
38
  React.useEffect(() => {
39
39
  if (activeItems) {
40
40
  pointsSource.clear();
41
- pointsSource.addFeatures(getFeatures(activeItems));
41
+ pointsSource.addFeatures(getFeatures(activeItems, ol));
42
42
  }
43
- }, [activeItems, pointsSource]);
43
+ }, [activeItems, pointsSource, ol]);
44
44
 
45
45
  const [isClient, setIsClient] = React.useState(false);
46
46
  React.useEffect(() => setIsClient(true), []);
@@ -59,11 +59,11 @@ export default function FeatureInteraction({
59
59
 
60
60
  const clusterLayer = new ol.layer.Vector({
61
61
  source: clusterSource,
62
- style: clusterStyle,
62
+ style: clusterStyle(ol),
63
63
  });
64
64
  setClusterLayer(clusterLayer);
65
65
  map.addLayer(clusterLayer);
66
- }, [map, clusterSource, clusterCircleStyle]);
66
+ }, [map, clusterSource, clusterCircleStyle, ol]);
67
67
 
68
68
  React.useEffect(() => {
69
69
  if (!(map && clusterLayer)) return;
@@ -96,7 +96,7 @@ export default function FeatureInteraction({
96
96
 
97
97
  const view = map.getView();
98
98
  const resolution = view.getResolution();
99
- const extent = getExtentOfFeatures(subfeatures);
99
+ const extent = getExtentOfFeatures(subfeatures, ol);
100
100
 
101
101
  if (
102
102
  view.getZoom() === view.getMaxZoom() ||
@@ -147,6 +147,7 @@ export default function FeatureInteraction({
147
147
  clusterLayer,
148
148
  clusterCircleStyle,
149
149
  clusterCirclesLayer,
150
+ ol,
150
151
  ]);
151
152
 
152
153
  function onClosePopup(evt) {