@eeacms/volto-tabs-block 7.0.4 → 7.0.5

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,6 +4,17 @@ 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
+ ### [7.0.5](https://github.com/eea/volto-tabs-block/compare/7.0.4...7.0.5) - 10 December 2023
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: add more tests for view/edit component [hazigabriel - [`72d0467`](https://github.com/eea/volto-tabs-block/commit/72d0467e74042b103630aacb8cffafb7c7a4a83f)]
12
+ - feat: refactor custom useQuery hook to avoid uncessary rerender [hazigabriel - [`6f28052`](https://github.com/eea/volto-tabs-block/commit/6f28052336db391ef9c918b2b329da4ae1639850)]
13
+
14
+ #### :bug: Bug Fixes
15
+
16
+ - fix: add jest config to fix jenkins error [hazigabriel - [`63fa962`](https://github.com/eea/volto-tabs-block/commit/63fa962f7f49ac8986ff250db57f544292aa951c)]
17
+
7
18
  ### [7.0.4](https://github.com/eea/volto-tabs-block/compare/7.0.3...7.0.4) - 4 December 2023
8
19
 
9
20
  #### :bug: Bug Fixes
@@ -19,6 +19,7 @@ module.exports = {
19
19
  'load-volto-addons':
20
20
  '<rootDir>/node_modules/@plone/volto/jest-addons-loader.js',
21
21
  },
22
+ transformIgnorePatterns: ['node_modules/(?!@eeacms)/volto-anchors/helpers'],
22
23
  transform: {
23
24
  '^.+\\.js(x)?$': 'babel-jest',
24
25
  '^.+\\.(png)$': 'jest-file',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-tabs-block",
3
- "version": "7.0.4",
3
+ "version": "7.0.5",
4
4
  "description": "volto-tabs-block: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -33,12 +33,11 @@ const View = (props) => {
33
33
 
34
34
  const TabsView = activeTemplate?.[0]?.view || DefaultView;
35
35
 
36
- const useQuery = () => {
36
+ const query = React.useMemo(() => {
37
37
  const { search } = location;
38
- return React.useMemo(() => new URLSearchParams(search), [search]);
39
- };
40
38
 
41
- const query = useQuery();
39
+ return new URLSearchParams(search);
40
+ }, [location]);
42
41
  const activeTabId = query.get('activeTab');
43
42
 
44
43
  const addQueryParam = (key, value) => {
@@ -0,0 +1,109 @@
1
+ import React from 'react';
2
+ import { render, fireEvent } from '@testing-library/react';
3
+ import { BrowserRouter as Router } from 'react-router-dom';
4
+ import View from './View';
5
+ import config from '@plone/volto/registry';
6
+ import configureStore from 'redux-mock-store';
7
+ import { Provider } from 'react-intl-redux';
8
+ import '@testing-library/jest-dom/extend-expect';
9
+
10
+ config.blocks.blocksConfig = {
11
+ tabs_block: {
12
+ variations: [{ id: 'default' }, { id: 'accordion' }],
13
+ },
14
+ };
15
+ config.settings = {
16
+ integratesBlockStyles: [],
17
+ };
18
+ jest.mock('react-router', () => ({
19
+ withRouter: (WrapperComponent) => (props) => {
20
+ return (
21
+ <WrapperComponent
22
+ {...props}
23
+ location={{
24
+ pathname: '/',
25
+ search: '?activeTab=tab1',
26
+ hash: '',
27
+ key: 'qruhb8',
28
+ }}
29
+ history={{
30
+ push: jest.fn(),
31
+ }}
32
+ />
33
+ );
34
+ },
35
+ }));
36
+
37
+ jest.mock('@eeacms/volto-block-style/StyleWrapper', () => ({
38
+ StyleWrapperView: (props) => {
39
+ return <div className="mocked-style-wrapper">{props.children}</div>;
40
+ },
41
+ }));
42
+ const mockStore = configureStore();
43
+ const store = mockStore({
44
+ intl: {
45
+ locale: 'en',
46
+ messages: {},
47
+ },
48
+ });
49
+
50
+ describe('View Component', () => {
51
+ it('Should render and switch Tabs', () => {
52
+ const customTabsData = {
53
+ blocks_layout: {
54
+ items: ['tab1', 'tab2', 'tab3'],
55
+ },
56
+ blocks: {
57
+ tab1: {
58
+ title: 'Tab 1 Title',
59
+ content: 'Tab 1 Content',
60
+ },
61
+ tab2: {
62
+ title: 'Tab 2 Title',
63
+ content: 'Tab 2 Content',
64
+ },
65
+ tab3: {
66
+ title: 'Tab 3 Title',
67
+ content: 'Tab 3 Content',
68
+ },
69
+ },
70
+ };
71
+
72
+ const { container, getByText } = render(
73
+ <Provider store={store}>
74
+ <Router>
75
+ <View data={{ variation: 'default', data: customTabsData }} />
76
+ </Router>
77
+ </Provider>,
78
+ );
79
+ const tabItemsMenu = container.querySelectorAll(
80
+ '.ui.tabs-secondary-variant.menu a',
81
+ );
82
+
83
+ expect(
84
+ container.querySelector('.tabs-block.default.light.flex-start'),
85
+ ).toBeInTheDocument();
86
+ expect(
87
+ container.querySelector('.default.tabs.tabs-accessibility'),
88
+ ).toBeInTheDocument();
89
+ expect(
90
+ container.querySelector('.ui.tabs-secondary-variant.menu'),
91
+ ).toBeInTheDocument();
92
+ expect(
93
+ container.getElementsByClassName('mocked-style-wrapper'),
94
+ ).toHaveLength(2);
95
+ expect(getByText('Tab 1 Title')).toBeInTheDocument();
96
+
97
+ fireEvent.click(getByText('Tab 2 Title'));
98
+ expect(tabItemsMenu).toHaveLength(3);
99
+ expect(tabItemsMenu[0].classList.contains('item'));
100
+ expect(tabItemsMenu[0].classList).not.toContain('active');
101
+ expect(tabItemsMenu[1].classList.contains('active'));
102
+
103
+ fireEvent.click(getByText('Tab 1 Title'));
104
+ expect(tabItemsMenu).toHaveLength(3);
105
+ expect(tabItemsMenu[1].classList.contains('item'));
106
+ expect(tabItemsMenu[1].classList).not.toContain('active');
107
+ expect(tabItemsMenu[0].classList.contains('active'));
108
+ });
109
+ });