@eeacms/volto-tabs-block 5.0.3 → 5.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 +10 -0
- package/package.json +1 -1
- package/src/components/templates/accordion/Edit.jsx +2 -4
- package/src/helpers.test.js +118 -0
- package/src/less/carousel.less +1 -0
- package/src/utils/SimpleMarkdown.test.jsx +50 -0
- package/src/utils/dimensions.test.js +130 -0
- package/src/utils/index.test.js +84 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,16 @@ 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
|
+
### [5.0.5](https://github.com/eea/volto-tabs-block/compare/5.0.4...5.0.5) - 4 July 2023
|
|
8
|
+
|
|
9
|
+
#### :hammer_and_wrench: Others
|
|
10
|
+
|
|
11
|
+
- set gutter on carousel [Miu Razvan - [`ccea0b6`](https://github.com/eea/volto-tabs-block/commit/ccea0b6c4c5dd49afe8de127df10751239f6a5fa)]
|
|
12
|
+
### [5.0.4](https://github.com/eea/volto-tabs-block/compare/5.0.3...5.0.4) - 13 June 2023
|
|
13
|
+
|
|
14
|
+
#### :hammer_and_wrench: Others
|
|
15
|
+
|
|
16
|
+
- test: add unit tests for helpers - refs #253277 [ana-oprea - [`aa270d7`](https://github.com/eea/volto-tabs-block/commit/aa270d7db0da5086d48378a6ccf503e563805d72)]
|
|
7
17
|
### [5.0.3](https://github.com/eea/volto-tabs-block/compare/5.0.2...5.0.3) - 12 June 2023
|
|
8
18
|
|
|
9
19
|
#### :house: Internal changes
|
package/package.json
CHANGED
|
@@ -8,10 +8,8 @@ import Tabs from 'react-responsive-tabs';
|
|
|
8
8
|
import AnimateHeight from 'react-animate-height';
|
|
9
9
|
import EditBlockWrapper from '@eeacms/volto-tabs-block/components/EditBlockWrapper';
|
|
10
10
|
import { emptyBlocksForm } from '@plone/volto/helpers';
|
|
11
|
-
import {
|
|
12
|
-
import { Icon } from '
|
|
13
|
-
import { Menu, Input } from 'semantic-ui-react';
|
|
14
|
-
import { Icon as VoltoIcon } from '@plone/volto/components';
|
|
11
|
+
import { Menu, Input, Icon } from 'semantic-ui-react';
|
|
12
|
+
import { Icon as VoltoIcon, BlocksForm } from '@plone/volto/components';
|
|
15
13
|
import config from '@plone/volto/registry';
|
|
16
14
|
import { TABS_BLOCK } from '@eeacms/volto-tabs-block/constants';
|
|
17
15
|
import { withScrollToTarget } from '@eeacms/volto-tabs-block/hocs';
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
empty,
|
|
3
|
+
emptyTab,
|
|
4
|
+
scrollToTarget,
|
|
5
|
+
getParentTabFromHash,
|
|
6
|
+
} from './helpers';
|
|
7
|
+
import { emptyBlocksForm } from '@plone/volto/helpers';
|
|
8
|
+
import { visitBlocks, toSlug } from '@eeacms/volto-anchors/helpers';
|
|
9
|
+
|
|
10
|
+
jest.mock('@plone/volto/helpers', () => ({
|
|
11
|
+
emptyBlocksForm: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
jest.mock('@eeacms/volto-anchors/helpers', () => ({
|
|
15
|
+
visitBlocks: jest.fn(),
|
|
16
|
+
toSlug: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
describe('empty function', () => {
|
|
20
|
+
it('returns a tab block with unique ID', () => {
|
|
21
|
+
emptyBlocksForm.mockReturnValue({});
|
|
22
|
+
const result = empty();
|
|
23
|
+
expect(Object.keys(result.blocks)).toHaveLength(1);
|
|
24
|
+
expect(result.blocks[Object.keys(result.blocks)[0]]['@type']).toEqual(
|
|
25
|
+
'tab',
|
|
26
|
+
);
|
|
27
|
+
expect(result.blocks_layout.items).toEqual([Object.keys(result.blocks)[0]]);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('emptyTab function', () => {
|
|
32
|
+
it('returns a tab block', () => {
|
|
33
|
+
emptyBlocksForm.mockReturnValue({});
|
|
34
|
+
const result = emptyTab();
|
|
35
|
+
expect(result['@type']).toEqual('tab');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('scrollToTarget', () => {
|
|
40
|
+
it('should call window.scrollTo with the correct arguments', () => {
|
|
41
|
+
window.scrollTo = jest.fn();
|
|
42
|
+
|
|
43
|
+
const mockElement = {
|
|
44
|
+
getBoundingClientRect: jest.fn(),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
document.body.getBoundingClientRect = jest.fn(() => ({ top: 100 }));
|
|
48
|
+
mockElement.getBoundingClientRect.mockReturnValue({ top: 200 });
|
|
49
|
+
|
|
50
|
+
scrollToTarget(mockElement, 50);
|
|
51
|
+
|
|
52
|
+
expect(window.scrollTo).toHaveBeenCalledWith({
|
|
53
|
+
top: 50,
|
|
54
|
+
behavior: 'smooth',
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should call window.scrollTo with the correct arguments with offsetHeight not provided', () => {
|
|
59
|
+
window.scrollTo = jest.fn();
|
|
60
|
+
|
|
61
|
+
const mockElement = {
|
|
62
|
+
getBoundingClientRect: jest.fn(),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
document.body.getBoundingClientRect = jest.fn(() => ({ top: 100 }));
|
|
66
|
+
mockElement.getBoundingClientRect.mockReturnValue({ top: 200 });
|
|
67
|
+
|
|
68
|
+
scrollToTarget(mockElement);
|
|
69
|
+
|
|
70
|
+
expect(window.scrollTo).toHaveBeenCalledWith({
|
|
71
|
+
top: 100,
|
|
72
|
+
behavior: 'smooth',
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('getParentTabFromHash function', () => {
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
visitBlocks.mockClear();
|
|
80
|
+
toSlug.mockClear();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('returns parentBlockId if slug is not matching urlHash', () => {
|
|
84
|
+
const urlHash = 'slug';
|
|
85
|
+
const tabsBlockData = { data: 'test' };
|
|
86
|
+
const parentBlockId = 'parentBlockId';
|
|
87
|
+
const dataForCallback = { '@type': 'tab', plaintext: urlHash };
|
|
88
|
+
|
|
89
|
+
visitBlocks.mockImplementation((data, callback) => {
|
|
90
|
+
callback([parentBlockId, dataForCallback]);
|
|
91
|
+
});
|
|
92
|
+
toSlug.mockReturnValue(urlHash);
|
|
93
|
+
|
|
94
|
+
const result = getParentTabFromHash(tabsBlockData, urlHash);
|
|
95
|
+
expect(result).toEqual(parentBlockId);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('returns null if slug is matching urlHash', () => {
|
|
99
|
+
const urlHash = 'slug';
|
|
100
|
+
const tabsBlockData = { data: 'test' };
|
|
101
|
+
const parentBlockId = 'parentBlockId';
|
|
102
|
+
const dataForCallback = { '@type': 'tab', plaintext: 'notMatchingSlug' };
|
|
103
|
+
|
|
104
|
+
visitBlocks.mockImplementation((data, callback) => {
|
|
105
|
+
callback([parentBlockId, dataForCallback]);
|
|
106
|
+
});
|
|
107
|
+
toSlug.mockReturnValue('notMatchingSlug');
|
|
108
|
+
|
|
109
|
+
const result = getParentTabFromHash(tabsBlockData, urlHash);
|
|
110
|
+
expect(result).toEqual(null);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('returns null if urlHash is not provided', () => {
|
|
114
|
+
const tabsBlockData = { data: 'test' };
|
|
115
|
+
const result = getParentTabFromHash(tabsBlockData, null);
|
|
116
|
+
expect(result).toEqual(null);
|
|
117
|
+
});
|
|
118
|
+
});
|
package/src/less/carousel.less
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import SimpleMarkdown from './SimpleMarkdown';
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
5
|
+
|
|
6
|
+
describe('SimpleMarkdown', () => {
|
|
7
|
+
it('renders empty when no markdown is provided', () => {
|
|
8
|
+
const { container } = render(<SimpleMarkdown />);
|
|
9
|
+
expect(container).toBeEmptyDOMElement();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('renders pararaph with the tag provided when no text is provided with the markdown', () => {
|
|
13
|
+
const { getByText } = render(<SimpleMarkdown md="#" />);
|
|
14
|
+
expect(getByText('#').tagName).toBe('P');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('renders paragraph when no tag is provided', () => {
|
|
18
|
+
const { getByText } = render(<SimpleMarkdown md="test test" />);
|
|
19
|
+
expect(getByText('test test').tagName).toBe('P');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders h1 when # tag is provided', () => {
|
|
23
|
+
const { getByText } = render(<SimpleMarkdown md="# test test" />);
|
|
24
|
+
expect(getByText('test test').tagName).toBe('H1');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders h2 when ## tag is provided', () => {
|
|
28
|
+
const { getByText } = render(<SimpleMarkdown md="## test test" />);
|
|
29
|
+
expect(getByText('test test').tagName).toBe('H2');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders h3 when ### tag is provided', () => {
|
|
33
|
+
const { getByText } = render(<SimpleMarkdown md="### test test" />);
|
|
34
|
+
expect(getByText('test test').tagName).toBe('H3');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders h4 when #### tag is provided', () => {
|
|
38
|
+
const { getByText } = render(<SimpleMarkdown md="#### test test" />);
|
|
39
|
+
expect(getByText('test test').tagName).toBe('H4');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('renders h5 when ##### tag is provided', () => {
|
|
43
|
+
const { getByText } = render(<SimpleMarkdown md="##### test test" />);
|
|
44
|
+
expect(getByText('test test').tagName).toBe('H5');
|
|
45
|
+
});
|
|
46
|
+
it('renders h6 when ###### tag is provided', () => {
|
|
47
|
+
const { getByText } = render(<SimpleMarkdown md="###### test test" />);
|
|
48
|
+
expect(getByText('test test').tagName).toBe('H6');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
positionedOffset,
|
|
3
|
+
getDocumentHeight,
|
|
4
|
+
getDocumentWidth,
|
|
5
|
+
} from './dimensions';
|
|
6
|
+
|
|
7
|
+
describe('positionedOffset', () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
document.body.innerHTML = `<div id="container">
|
|
10
|
+
<div id="element" style="height: 50px; width: 50px;"></div>
|
|
11
|
+
</div>`;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
jest.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns correct offset position', () => {
|
|
19
|
+
const element = document.querySelector('#element');
|
|
20
|
+
const container = document.querySelector('#container');
|
|
21
|
+
|
|
22
|
+
jest.spyOn(element, 'offsetTop', 'get').mockReturnValue(100);
|
|
23
|
+
jest.spyOn(element, 'offsetLeft', 'get').mockReturnValue(200);
|
|
24
|
+
jest.spyOn(element, 'offsetHeight', 'get').mockReturnValue(50);
|
|
25
|
+
jest.spyOn(element, 'offsetWidth', 'get').mockReturnValue(50);
|
|
26
|
+
jest.spyOn(element, 'offsetParent', 'get').mockReturnValue(container);
|
|
27
|
+
|
|
28
|
+
jest.spyOn(container, 'scrollHeight', 'get').mockReturnValue(500);
|
|
29
|
+
jest.spyOn(container, 'scrollWidth', 'get').mockReturnValue(500);
|
|
30
|
+
|
|
31
|
+
const result = positionedOffset(element, container);
|
|
32
|
+
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
top: 100,
|
|
35
|
+
left: 200,
|
|
36
|
+
bottom: 350,
|
|
37
|
+
right: 250,
|
|
38
|
+
_container: container,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('returns correct offset position when container is undefined', () => {
|
|
43
|
+
document.body.innerHTML = `
|
|
44
|
+
<div id="element" style="height: 50px; width: 50px;" />
|
|
45
|
+
`;
|
|
46
|
+
const element = document.getElementById('element');
|
|
47
|
+
|
|
48
|
+
jest.spyOn(element, 'offsetTop', 'get').mockReturnValue(100);
|
|
49
|
+
jest.spyOn(element, 'offsetLeft', 'get').mockReturnValue(200);
|
|
50
|
+
jest.spyOn(element, 'offsetHeight', 'get').mockReturnValue(50);
|
|
51
|
+
jest.spyOn(element, 'offsetWidth', 'get').mockReturnValue(50);
|
|
52
|
+
jest.spyOn(element, 'offsetParent', 'get').mockReturnValue(document.body);
|
|
53
|
+
|
|
54
|
+
jest.spyOn(document.body, 'scrollHeight', 'get').mockReturnValue(500);
|
|
55
|
+
jest.spyOn(document.body, 'scrollWidth', 'get').mockReturnValue(500);
|
|
56
|
+
|
|
57
|
+
const result = positionedOffset(element, undefined);
|
|
58
|
+
expect(result).toEqual({
|
|
59
|
+
top: 100,
|
|
60
|
+
left: 200,
|
|
61
|
+
bottom: 350,
|
|
62
|
+
right: 250,
|
|
63
|
+
_container: document.documentElement,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns undefined when container is not an HTML element', () => {
|
|
68
|
+
document.body.innerHTML = `
|
|
69
|
+
<div id="element" style="height: 50px; width: 50px;" />
|
|
70
|
+
`;
|
|
71
|
+
const element = document.getElementById('element');
|
|
72
|
+
|
|
73
|
+
jest.spyOn(element, 'offsetTop', 'get').mockReturnValue(100);
|
|
74
|
+
jest.spyOn(element, 'offsetLeft', 'get').mockReturnValue(200);
|
|
75
|
+
jest.spyOn(element, 'offsetHeight', 'get').mockReturnValue(50);
|
|
76
|
+
jest.spyOn(element, 'offsetWidth', 'get').mockReturnValue(50);
|
|
77
|
+
jest.spyOn(element, 'offsetParent', 'get').mockReturnValue(document.body);
|
|
78
|
+
|
|
79
|
+
jest.spyOn(document.body, 'scrollHeight', 'get').mockReturnValue(500);
|
|
80
|
+
jest.spyOn(document.body, 'scrollWidth', 'get').mockReturnValue(500);
|
|
81
|
+
|
|
82
|
+
const result = positionedOffset(element, 'not an HTML element');
|
|
83
|
+
expect(result).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('returns undefined when element is not part of DOM', () => {
|
|
87
|
+
const detachedElement = document.createElement('div');
|
|
88
|
+
const result = positionedOffset(detachedElement, null);
|
|
89
|
+
expect(result).toBeUndefined();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('returns undefined when documentElement does not exist', () => {
|
|
93
|
+
document.body.innerHTML = `
|
|
94
|
+
<div id="element" style="height: 50px; width: 50px;" />
|
|
95
|
+
`;
|
|
96
|
+
const element = document.getElementById('element');
|
|
97
|
+
|
|
98
|
+
jest.spyOn(document, 'documentElement', 'get').mockReturnValue(null);
|
|
99
|
+
|
|
100
|
+
const result = positionedOffset(element, null);
|
|
101
|
+
expect(result).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('returns undefined when ownerDocument does not exist', () => {
|
|
105
|
+
document.body.innerHTML = `
|
|
106
|
+
<div id="element" style="height: 50px; width: 50px;" />
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
const element = document.getElementById('element');
|
|
110
|
+
|
|
111
|
+
jest.spyOn(element, 'ownerDocument', 'get').mockReturnValue(null);
|
|
112
|
+
|
|
113
|
+
const result = positionedOffset(element, null);
|
|
114
|
+
expect(result).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('getDocumentHeight', () => {
|
|
119
|
+
it('returns maximum height', () => {
|
|
120
|
+
const result = getDocumentHeight(document.body, document.documentElement);
|
|
121
|
+
expect(result).toBe(0);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('getDocumentWidth', () => {
|
|
126
|
+
it('returns maximum width', () => {
|
|
127
|
+
const result = getDocumentWidth(document.body, document.documentElement);
|
|
128
|
+
expect(result).toBe(0);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getMenuPosition, toggleItem } from './index';
|
|
2
|
+
|
|
3
|
+
describe('getMenuPosition', () => {
|
|
4
|
+
it('returns correct position object for top', () => {
|
|
5
|
+
expect(getMenuPosition({ menuPosition: 'top' })).toEqual({
|
|
6
|
+
direction: 'top',
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('returns correct position object for bottom', () => {
|
|
11
|
+
expect(getMenuPosition({ menuPosition: 'bottom' })).toEqual({
|
|
12
|
+
attached: 'bottom',
|
|
13
|
+
direction: 'bottom',
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('returns correct position object for left side', () => {
|
|
18
|
+
expect(getMenuPosition({ menuPosition: 'left side' })).toEqual({
|
|
19
|
+
vertical: true,
|
|
20
|
+
direction: 'left',
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('returns correct position object for right side', () => {
|
|
25
|
+
expect(getMenuPosition({ menuPosition: 'right side' })).toEqual({
|
|
26
|
+
vertical: true,
|
|
27
|
+
direction: 'right',
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('toggleItem', () => {
|
|
33
|
+
it('toggles visibility of item and related item', () => {
|
|
34
|
+
document.body.innerHTML = `<div id="container">
|
|
35
|
+
<div id="item"></div>
|
|
36
|
+
<div id="relatedItem"></div>
|
|
37
|
+
</div>`;
|
|
38
|
+
const container = document.getElementById('container');
|
|
39
|
+
const item = document.getElementById('item');
|
|
40
|
+
const relatedItem = document.getElementById('relatedItem');
|
|
41
|
+
|
|
42
|
+
relatedItem.setAttribute('underline-item-data', 'test-data');
|
|
43
|
+
item.setAttribute('item-data', 'test-data');
|
|
44
|
+
|
|
45
|
+
item.style.visibility = '';
|
|
46
|
+
relatedItem.hidden = false;
|
|
47
|
+
|
|
48
|
+
toggleItem(container, item, true);
|
|
49
|
+
expect(item.style.visibility).toBe('hidden');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('handles when no related item is present', () => {
|
|
53
|
+
document.body.innerHTML = `<div id="container">
|
|
54
|
+
<div id="item"></div>
|
|
55
|
+
</div>`;
|
|
56
|
+
const container = document.getElementById('container');
|
|
57
|
+
const item = document.getElementById('item');
|
|
58
|
+
item.setAttribute('item-data', 'test-data');
|
|
59
|
+
|
|
60
|
+
item.style.visibility = '';
|
|
61
|
+
|
|
62
|
+
toggleItem(container, item, true);
|
|
63
|
+
expect(item.style.visibility).toBe('hidden');
|
|
64
|
+
|
|
65
|
+
toggleItem(container, item, false);
|
|
66
|
+
expect(item.style.visibility).toBe('');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('handles when no item-data is present', () => {
|
|
70
|
+
document.body.innerHTML = `<div id="container">
|
|
71
|
+
<div id="item"></div>
|
|
72
|
+
</div>`;
|
|
73
|
+
const container = document.getElementById('container');
|
|
74
|
+
const item = document.getElementById('item');
|
|
75
|
+
|
|
76
|
+
item.style.visibility = '';
|
|
77
|
+
|
|
78
|
+
toggleItem(container, item, true);
|
|
79
|
+
expect(item.style.visibility).toBe('hidden');
|
|
80
|
+
|
|
81
|
+
toggleItem(container, item, false);
|
|
82
|
+
expect(item.style.visibility).toBe('');
|
|
83
|
+
});
|
|
84
|
+
});
|