@blaze-cms/react-page-builder 0.123.0-alpha.22 → 0.123.0-alpha.25

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +42 -870
  2. package/lib/components/Card/Card.js +12 -5
  3. package/lib/components/Card/Card.js.map +1 -1
  4. package/lib/components/DataSummary/helpers/get-link-based-on-value.js +4 -0
  5. package/lib/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -1
  6. package/lib/components/SearchFilter/SearchFilter/FiltersList.js +16 -11
  7. package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  8. package/lib/components/SearchFilter/components/Select.js +22 -10
  9. package/lib/components/SearchFilter/components/Select.js.map +1 -1
  10. package/lib/constants/index.js +5 -2
  11. package/lib/constants/index.js.map +1 -1
  12. package/lib-es/components/Card/Card.js +12 -5
  13. package/lib-es/components/Card/Card.js.map +1 -1
  14. package/lib-es/components/DataSummary/helpers/get-link-based-on-value.js +5 -1
  15. package/lib-es/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -1
  16. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +20 -16
  17. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  18. package/lib-es/components/SearchFilter/components/Select.js +22 -6
  19. package/lib-es/components/SearchFilter/components/Select.js.map +1 -1
  20. package/lib-es/constants/index.js +3 -1
  21. package/lib-es/constants/index.js.map +1 -1
  22. package/package.json +3 -3
  23. package/src/components/Card/Card.js +19 -4
  24. package/src/components/DataSummary/helpers/get-link-based-on-value.js +9 -1
  25. package/src/components/SearchFilter/SearchFilter/FiltersList.js +5 -2
  26. package/src/components/SearchFilter/components/Select.js +29 -6
  27. package/src/constants/index.js +3 -1
  28. package/tests/unit/src/components/Card/__snapshots__/Card.test.js.snap +10 -10
  29. package/tests/unit/src/components/Card/__snapshots__/CardContainer.test.js.snap +4 -4
  30. package/tests/unit/src/components/Card/__snapshots__/CardRender.test.js.snap +1 -1
  31. package/tests/unit/src/components/DataSummary/helpers/get-link-based-on-value.test.js +29 -0
  32. package/tests/unit/src/components/List/components/Cards/__snapshots__/CardsRender.test.js.snap +12 -12
  33. package/tests/unit/src/components/SearchFilter/components/Select.test.js +58 -4
  34. package/tests/unit/src/components/SearchFilter/components/__snapshots__/Select.test.js.snap +28 -5
@@ -4,7 +4,15 @@ import Select from '@blaze-react/select';
4
4
  import { withTitle } from '../../../HOC';
5
5
  import { DEFAULT_OPTION } from '../constants';
6
6
 
7
- const SelectFilter = ({ data, label, prop, updateFilterValues, filterValues, shouldSearch }) => {
7
+ const SelectFilter = ({
8
+ data,
9
+ label,
10
+ prop,
11
+ updateFilterValues,
12
+ filterValues,
13
+ shouldSearch,
14
+ displayLabelAsPlaceholder
15
+ }) => {
8
16
  const filterValue = filterValues[prop] || '';
9
17
 
10
18
  const options = data[prop].buckets
@@ -12,16 +20,29 @@ const SelectFilter = ({ data, label, prop, updateFilterValues, filterValues, sho
12
20
  .filter(Boolean)
13
21
  .sort();
14
22
 
15
- const optionsJoined = [DEFAULT_OPTION, ...options];
23
+ const optionsJoined = options;
24
+
25
+ const labelText = label || prop;
26
+ let labelToUse = labelText;
27
+ let defaultTextValue = DEFAULT_OPTION;
28
+ if (displayLabelAsPlaceholder) {
29
+ defaultTextValue = labelToUse;
30
+ labelToUse = null;
31
+ }
16
32
 
17
33
  return (
18
34
  <Select
19
- label={`${label || prop}`}
35
+ label={labelToUse}
20
36
  value={filterValue}
21
37
  id={prop}
38
+ data-testid={`filter-${prop}`}
22
39
  options={optionsJoined}
40
+ defaultTextValue={defaultTextValue}
23
41
  onChange={({ value }) => {
24
- updateFilterValues({ [prop]: value }, shouldSearch);
42
+ let valueToUse = value;
43
+ if (value === defaultTextValue) valueToUse = '';
44
+
45
+ updateFilterValues({ [prop]: valueToUse }, shouldSearch);
25
46
  }}
26
47
  />
27
48
  );
@@ -33,12 +54,14 @@ SelectFilter.propTypes = {
33
54
  filterValues: PropTypes.object.isRequired,
34
55
  updateFilterValues: PropTypes.func.isRequired,
35
56
  shouldSearch: PropTypes.bool,
36
- label: PropTypes.string
57
+ label: PropTypes.string,
58
+ displayLabelAsPlaceholder: PropTypes.bool
37
59
  };
38
60
 
39
61
  SelectFilter.defaultProps = {
40
62
  shouldSearch: false,
41
- label: ''
63
+ label: '',
64
+ displayLabelAsPlaceholder: false
42
65
  };
43
66
 
44
67
  export default withTitle(SelectFilter);
@@ -207,6 +207,7 @@ const TARGET_BLANK = '_blank';
207
207
 
208
208
  const DATA_SUMMARY_EMAIL_REGEX = /^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
209
209
  const DATA_SUMMARY_URL_REGEX = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
210
+ const DATA_SUMMARY_TEL_REGEX = /^\+{0,1}[0-9\(\)\.\- \/]{7,}$/; // note: very loose phone number match not for validation
210
211
 
211
212
  export {
212
213
  BANNER_LOADING,
@@ -318,5 +319,6 @@ export {
318
319
  ANCHOR_TAG,
319
320
  TARGET_BLANK,
320
321
  DATA_SUMMARY_EMAIL_REGEX,
321
- DATA_SUMMARY_URL_REGEX
322
+ DATA_SUMMARY_URL_REGEX,
323
+ DATA_SUMMARY_TEL_REGEX
322
324
  };
@@ -19,7 +19,7 @@ exports[`Card component should not render alternative headline if alternativePre
19
19
  </a>
20
20
  </div>
21
21
  <div
22
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
22
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
23
23
  >
24
24
  <div
25
25
  class="card__content card__content--portrait"
@@ -31,7 +31,7 @@ exports[`Card component should not render alternative headline if alternativePre
31
31
  category-name
32
32
  </a>
33
33
  <h2
34
- class="card__title card__title--portrait"
34
+ class="card__title card__title--portrait card__content--overlay__title"
35
35
  >
36
36
  <a
37
37
  href="/mockurl"
@@ -93,13 +93,13 @@ exports[`Card component should not render alternative headline if displayCategor
93
93
  </a>
94
94
  </div>
95
95
  <div
96
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
96
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
97
97
  >
98
98
  <div
99
99
  class="card__content card__content--portrait"
100
100
  >
101
101
  <h2
102
- class="card__title card__title--portrait"
102
+ class="card__title card__title--portrait card__content--overlay__title"
103
103
  >
104
104
  <a
105
105
  href="/mockurl"
@@ -161,7 +161,7 @@ exports[`Card component should not render preHeader if alternativeHeadline is no
161
161
  </a>
162
162
  </div>
163
163
  <div
164
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
164
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
165
165
  >
166
166
  <div
167
167
  class="card__content card__content--portrait"
@@ -173,7 +173,7 @@ exports[`Card component should not render preHeader if alternativeHeadline is no
173
173
  category-name
174
174
  </a>
175
175
  <h2
176
- class="card__title card__title--portrait"
176
+ class="card__title card__title--portrait card__content--overlay__title"
177
177
  >
178
178
  <a
179
179
  href="/mockurl"
@@ -235,7 +235,7 @@ exports[`Card component should render customPreheader and alternativeHeadline in
235
235
  </a>
236
236
  </div>
237
237
  <div
238
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
238
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
239
239
  >
240
240
  <div
241
241
  class="card__content card__content--portrait"
@@ -246,7 +246,7 @@ exports[`Card component should render customPreheader and alternativeHeadline in
246
246
  Pre header
247
247
  </div>
248
248
  <h2
249
- class="card__title card__title--portrait"
249
+ class="card__title card__title--portrait card__content--overlay__title"
250
250
  >
251
251
  <a
252
252
  href="/mockurl"
@@ -308,7 +308,7 @@ exports[`Card component should render without throwing an error and match snapsh
308
308
  </a>
309
309
  </div>
310
310
  <div
311
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
311
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
312
312
  >
313
313
  <div
314
314
  class="card__content card__content--portrait"
@@ -320,7 +320,7 @@ exports[`Card component should render without throwing an error and match snapsh
320
320
  category-name
321
321
  </a>
322
322
  <h2
323
- class="card__title card__title--portrait"
323
+ class="card__title card__title--portrait card__content--overlay__title"
324
324
  >
325
325
  <a
326
326
  href="/mockurl"
@@ -37,7 +37,7 @@ exports[`CardContainer component should render with carousel if option is enable
37
37
  page
38
38
  </div>
39
39
  <h2
40
- class="card__title card__title--portrait"
40
+ class="card__title card__title--portrait "
41
41
  >
42
42
  <a
43
43
  href="/nautors-swan/swan-78"
@@ -74,7 +74,7 @@ exports[`CardContainer component should render with carousel if option is enable
74
74
  page
75
75
  </div>
76
76
  <h2
77
- class="card__title card__title--portrait"
77
+ class="card__title card__title--portrait "
78
78
  >
79
79
  <a
80
80
  href="/nautors-swan/swan-98"
@@ -121,7 +121,7 @@ exports[`CardContainer component should render without throwing error and match
121
121
  page
122
122
  </div>
123
123
  <h2
124
- class="card__title card__title--portrait"
124
+ class="card__title card__title--portrait "
125
125
  >
126
126
  <a
127
127
  href="/nautors-swan/swan-78"
@@ -158,7 +158,7 @@ exports[`CardContainer component should render without throwing error and match
158
158
  page
159
159
  </div>
160
160
  <h2
161
- class="card__title card__title--portrait"
161
+ class="card__title card__title--portrait "
162
162
  >
163
163
  <a
164
164
  href="/nautors-swan/swan-98"
@@ -33,7 +33,7 @@ exports[`CardRender component should render without throwing an error and match
33
33
  Card page cat
34
34
  </a>
35
35
  <h2
36
- class="card__title card__title--portrait"
36
+ class="card__title card__title--portrait "
37
37
  >
38
38
  <a
39
39
  href="/card-page"
@@ -26,4 +26,33 @@ describe('Get link based on value', () => {
26
26
  });
27
27
  expect.hasAssertions();
28
28
  });
29
+
30
+ it('should return tel: link for phone numbers', () => {
31
+ const examples = [
32
+ '+385 (0) 98 398 831',
33
+ '123456781211',
34
+ '+44123123566345',
35
+ '07789793111',
36
+ '555-456',
37
+ '123/1123',
38
+ '+32 (0) 3231 5055',
39
+ '+32 3 219 08 91'
40
+ ];
41
+ examples.forEach(example => {
42
+ expect(getLinkBasedOnValue(example)).toEqual(`tel:${example}`);
43
+ });
44
+ });
45
+
46
+ it('should not add tel: link for short numbers', () => {
47
+ const examples = [
48
+ '123',
49
+ '2010',
50
+ '123456',
51
+ '11m',
52
+ 'string with number +44123123566345 in the middle'
53
+ ];
54
+ examples.forEach(example => {
55
+ expect(getLinkBasedOnValue(example)).toEqual('');
56
+ });
57
+ });
29
58
  });
@@ -20,13 +20,13 @@ exports[`CardsRender component should render based on listData received 1`] = `
20
20
  class="card card--portrait"
21
21
  >
22
22
  <div
23
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
23
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
24
24
  >
25
25
  <div
26
26
  class="card__content card__content--portrait"
27
27
  >
28
28
  <h2
29
- class="card__title card__title--portrait"
29
+ class="card__title card__title--portrait card__content--overlay__title"
30
30
  >
31
31
  item 1
32
32
  </h2>
@@ -41,13 +41,13 @@ exports[`CardsRender component should render based on listData received 1`] = `
41
41
  class="card card--portrait"
42
42
  >
43
43
  <div
44
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
44
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
45
45
  >
46
46
  <div
47
47
  class="card__content card__content--portrait"
48
48
  >
49
49
  <h2
50
- class="card__title card__title--portrait"
50
+ class="card__title card__title--portrait card__content--overlay__title"
51
51
  >
52
52
  item 1
53
53
  </h2>
@@ -62,13 +62,13 @@ exports[`CardsRender component should render based on listData received 1`] = `
62
62
  class="card card--portrait"
63
63
  >
64
64
  <div
65
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
65
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
66
66
  >
67
67
  <div
68
68
  class="card__content card__content--portrait"
69
69
  >
70
70
  <h2
71
- class="card__title card__title--portrait"
71
+ class="card__title card__title--portrait card__content--overlay__title"
72
72
  >
73
73
  item 1
74
74
  </h2>
@@ -95,13 +95,13 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
95
95
  class="card card--portrait"
96
96
  >
97
97
  <div
98
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
98
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
99
99
  >
100
100
  <div
101
101
  class="card__content card__content--portrait"
102
102
  >
103
103
  <h2
104
- class="card__title card__title--portrait"
104
+ class="card__title card__title--portrait card__content--overlay__title"
105
105
  >
106
106
  item 1
107
107
  </h2>
@@ -116,13 +116,13 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
116
116
  class="card card--portrait"
117
117
  >
118
118
  <div
119
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
119
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
120
120
  >
121
121
  <div
122
122
  class="card__content card__content--portrait"
123
123
  >
124
124
  <h2
125
- class="card__title card__title--portrait"
125
+ class="card__title card__title--portrait card__content--overlay__title"
126
126
  >
127
127
  item 1
128
128
  </h2>
@@ -137,13 +137,13 @@ exports[`CardsRender component should render without wrapper, when requested 1`]
137
137
  class="card card--portrait"
138
138
  >
139
139
  <div
140
- class="card__content-wrapper card__content-wrapper--portrait card--overlay"
140
+ class="card__content-wrapper card__content-wrapper--portrait card__content--overlay"
141
141
  >
142
142
  <div
143
143
  class="card__content card__content--portrait"
144
144
  >
145
145
  <h2
146
- class="card__title card__title--portrait"
146
+ class="card__title card__title--portrait card__content--overlay__title"
147
147
  >
148
148
  item 1
149
149
  </h2>
@@ -1,23 +1,27 @@
1
1
  import { render } from '@blaze-cms/tools/test-helpers/test-functions';
2
- import { screen } from '@testing-library/react';
2
+ import { screen, fireEvent, act } from '@testing-library/react';
3
3
  import '@testing-library/jest-dom/extend-expect';
4
4
  import { SelectFilter } from '../../../../../../src/components/SearchFilter/components';
5
+ import { DEFAULT_OPTION } from '../../../../../../src/components/SearchFilter/constants';
5
6
 
6
7
  jest.mock('next/router', () => ({
7
8
  useRouter: jest.fn(() => ({ asPath: 'test-url' }))
8
9
  }));
9
10
 
11
+ const changeValue = 'name2';
12
+ const testId = 'filter-name';
10
13
  const props = {
11
14
  data: {
12
15
  name: {
13
- buckets: [{ key: 'name1' }, { key: 'name2' }]
16
+ buckets: [{ key: 'name1' }, { key: changeValue }]
14
17
  }
15
18
  },
16
19
  filterValues: {},
17
20
  updateFilterValues: jest.fn(),
18
21
  prop: 'name',
19
22
  buttonRef: {},
20
- hasUrl: false
23
+ hasUrl: false,
24
+ shouldSearch: true
21
25
  };
22
26
 
23
27
  describe('Select component', () => {
@@ -26,10 +30,60 @@ describe('Select component', () => {
26
30
  expect(asFragment()).toMatchSnapshot();
27
31
  });
28
32
 
29
- it('should match snapshot with label', () => {
33
+ it('should match snapshot with label', () => {
30
34
  const label = 'Select name';
31
35
  const propsWithLabel = { ...props, label };
32
36
  render(SelectFilter, propsWithLabel);
33
37
  expect(screen.getByLabelText(label)).toBeInTheDocument();
34
38
  });
39
+
40
+ it('should pass on changed value', () => {
41
+ const { getByTestId } = render(SelectFilter, props);
42
+ act(() => {
43
+ fireEvent.change(getByTestId(testId), { target: { value: changeValue } });
44
+ });
45
+
46
+ expect(props.updateFilterValues).toHaveBeenCalledWith(
47
+ {
48
+ [props.prop]: changeValue
49
+ },
50
+ props.shouldSearch
51
+ );
52
+ });
53
+
54
+ it('should reset value if default option selected', () => {
55
+ const { getByTestId } = render(SelectFilter, props);
56
+ act(() => {
57
+ fireEvent.change(getByTestId(testId), { target: { value: DEFAULT_OPTION } });
58
+ });
59
+
60
+ expect(props.updateFilterValues).toHaveBeenCalledWith(
61
+ {
62
+ [props.prop]: ''
63
+ },
64
+ props.shouldSearch
65
+ );
66
+ });
67
+
68
+ it('should display label as placeholder with no label tag', () => {
69
+ const label = 'Placeholder label';
70
+ const { asFragment, getByTestId, queryByText } = render(SelectFilter, {
71
+ ...props,
72
+ label,
73
+ displayLabelAsPlaceholder: true
74
+ });
75
+ expect(asFragment()).toMatchSnapshot();
76
+ expect(queryByText(DEFAULT_OPTION)).toBeNull();
77
+
78
+ act(() => {
79
+ fireEvent.change(getByTestId(testId), { target: { value: label } });
80
+ });
81
+
82
+ expect(props.updateFilterValues).toHaveBeenCalledWith(
83
+ {
84
+ [props.prop]: ''
85
+ },
86
+ props.shouldSearch
87
+ );
88
+ });
35
89
  });
@@ -1,5 +1,32 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`Select component should display label as placeholder with no label tag 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="form-field form-field--select"
7
+ >
8
+ <select
9
+ data-testid="filter-name"
10
+ id="name"
11
+ >
12
+ <option>
13
+ Placeholder label
14
+ </option>
15
+ <option
16
+ value="name1"
17
+ >
18
+ name1
19
+ </option>
20
+ <option
21
+ value="name2"
22
+ >
23
+ name2
24
+ </option>
25
+ </select>
26
+ </div>
27
+ </DocumentFragment>
28
+ `;
29
+
3
30
  exports[`Select component should render witout throwing an error and match snapshot 1`] = `
4
31
  <DocumentFragment>
5
32
  <div
@@ -12,14 +39,10 @@ exports[`Select component should render witout throwing an error and match snaps
12
39
  name
13
40
  </label>
14
41
  <select
42
+ data-testid="filter-name"
15
43
  id="name"
16
44
  >
17
45
  <option>
18
- Please Choose...
19
- </option>
20
- <option
21
- value="Any"
22
- >
23
46
  Any
24
47
  </option>
25
48
  <option