@pushwoosh/dumb-components 2.9.11 → 2.9.13
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/Skeleton/styles.js +2 -0
- package/package.json +4 -6
- package/Banner/__tests__/Banner.test.d.ts +0 -1
- package/Banner/__tests__/Banner.test.js +0 -57
- package/Button/__tests__/Button.test.d.ts +0 -1
- package/Button/__tests__/Button.test.js +0 -27
- package/Calendar/__tests__/CalendarMonthSlider.test.d.ts +0 -1
- package/Calendar/__tests__/CalendarMonthSlider.test.js +0 -85
- package/Calendar/__tests__/CellBox.test.d.ts +0 -1
- package/Calendar/__tests__/CellBox.test.js +0 -34
- package/Calendar/__tests__/helpers.test.d.ts +0 -1
- package/Calendar/__tests__/helpers.test.js +0 -143
- package/CardMetric/__tests__/CardMetric.test.d.ts +0 -1
- package/CardMetric/__tests__/CardMetric.test.js +0 -31
- package/Chip/__tests__/Chip.test.d.ts +0 -1
- package/Chip/__tests__/Chip.test.js +0 -101
- package/DateTimePicker/__tests__/YearView.test.d.ts +0 -1
- package/DateTimePicker/__tests__/YearView.test.js +0 -15
- package/DropdownMenu/__tests__/DropdownMenuItem.test.d.ts +0 -1
- package/DropdownMenu/__tests__/DropdownMenuItem.test.js +0 -109
- package/EditableField/__tests__/EditableField.test.d.ts +0 -1
- package/EditableField/__tests__/EditableField.test.js +0 -19
- package/EmailTemplatePreview/__tests__/clickMap.test.d.ts +0 -1
- package/EmailTemplatePreview/__tests__/clickMap.test.js +0 -168
- package/ExternalImagePreview/__tests__/ExternalImagePreview.test.d.ts +0 -1
- package/ExternalImagePreview/__tests__/ExternalImagePreview.test.js +0 -18
- package/InboxPreview/__tests__/helpers.test.d.ts +0 -1
- package/InboxPreview/__tests__/helpers.test.js +0 -201
- package/NativeRichMediaPreview/__tests__/NativeRichMediaPreview.test.d.ts +0 -1
- package/NativeRichMediaPreview/__tests__/NativeRichMediaPreview.test.js +0 -81
- package/PageHeader/__tests__/PageHeader.test.d.ts +0 -1
- package/PageHeader/__tests__/PageHeader.test.js +0 -37
- package/PushPreview/__tests__/PushPreview.test.d.ts +0 -1
- package/PushPreview/__tests__/PushPreview.test.js +0 -26
- package/PushStoriesPreview/__tests__/PushStoriesPreview.test.d.ts +0 -1
- package/PushStoriesPreview/__tests__/PushStoriesPreview.test.js +0 -234
- package/RadioCard/__tests__/RadioCard.test.d.ts +0 -1
- package/RadioCard/__tests__/RadioCard.test.js +0 -23
- package/RichmediaPreview/__tests__/RichmediaPreview.test.d.ts +0 -1
- package/RichmediaPreview/__tests__/RichmediaPreview.test.js +0 -21
- package/SandboxedHtmlFrame/__tests__/SandboxedHtmlFrame.test.d.ts +0 -1
- package/SandboxedHtmlFrame/__tests__/SandboxedHtmlFrame.test.js +0 -57
- package/Skeleton/__tests__/Skeleton.test.d.ts +0 -1
- package/Skeleton/__tests__/Skeleton.test.js +0 -56
- package/Spinner/__tests__/Spinner.test.d.ts +0 -1
- package/Spinner/__tests__/Spinner.test.js +0 -15
- package/Switch/__tests__/Switch.test.d.ts +0 -1
- package/Switch/__tests__/Switch.test.js +0 -44
- package/Tabs/__tests__/TabBar.test.d.ts +0 -1
- package/Tabs/__tests__/TabBar.test.js +0 -36
- package/Toast/__tests__/Toast.test.d.ts +0 -1
- package/Toast/__tests__/Toast.test.js +0 -20
- package/WhatsAppPreview/__tests__/WhatsAppAttachment.test.d.ts +0 -1
- package/WhatsAppPreview/__tests__/WhatsAppAttachment.test.js +0 -53
- package/WhatsAppPreview/__tests__/WhatsAppPreview.test.d.ts +0 -1
- package/WhatsAppPreview/__tests__/WhatsAppPreview.test.js +0 -55
- package/WhatsAppPreview/__tests__/attachment.test.d.ts +0 -1
- package/WhatsAppPreview/__tests__/attachment.test.js +0 -103
- package/WhatsAppPreview/__tests__/parseWhatsAppMarkup.test.d.ts +0 -1
- package/WhatsAppPreview/__tests__/parseWhatsAppMarkup.test.js +0 -59
- package/helpers/__tests__/barcodeUrl.test.d.ts +0 -1
- package/helpers/__tests__/barcodeUrl.test.js +0 -43
- package/helpers/__tests__/timezones.test.d.ts +0 -1
- package/helpers/__tests__/timezones.test.js +0 -188
- package/hooks/__tests__/useLayer.test.d.ts +0 -1
- package/hooks/__tests__/useLayer.test.js +0 -71
- package/polyglot/__tests__/filters.test.d.ts +0 -1
- package/polyglot/__tests__/filters.test.js +0 -152
- package/polyglot/__tests__/helpers.test.d.ts +0 -1
- package/polyglot/__tests__/helpers.test.js +0 -176
- package/polyglot/__tests__/parser.test.d.ts +0 -1
- package/polyglot/__tests__/parser.test.js +0 -108
- package/polyglot/__tests__/render.test.d.ts +0 -1
- package/polyglot/__tests__/render.test.js +0 -285
- package/shared/dropdownField/__tests__/useDropdownPosition.test.d.ts +0 -1
- package/shared/dropdownField/__tests__/useDropdownPosition.test.js +0 -60
- package/shared/dynamicContent/__tests__/token.test.d.ts +0 -1
- package/shared/dynamicContent/__tests__/token.test.js +0 -32
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { smartSplit, smartSplitAtFirstDelimiter, ensureNumber, ensureString, parseScalarOrVariable, addSpaceAroundOperators, unpackScalarOrValue, decodeHtmlEntities } from '../liquid/helpers';
|
|
2
|
-
describe('smartSplit', () => {
|
|
3
|
-
test('splits simple string by delimiter', () => {
|
|
4
|
-
expect(smartSplit('a,b,c', ',')).toEqual(['a', 'b', 'c']);
|
|
5
|
-
});
|
|
6
|
-
test('preserves quoted strings', () => {
|
|
7
|
-
expect(smartSplit('"a,b",c', ',')).toEqual(['"a,b"', 'c']);
|
|
8
|
-
});
|
|
9
|
-
test('handles escaped quotes in strings', () => {
|
|
10
|
-
expect(smartSplit('"a\\"b",c', ',')).toEqual(['"a\\"b"', 'c']);
|
|
11
|
-
});
|
|
12
|
-
test('handles empty string', () => {
|
|
13
|
-
expect(smartSplit('', ',')).toEqual([]);
|
|
14
|
-
});
|
|
15
|
-
test('handles single element', () => {
|
|
16
|
-
expect(smartSplit('abc', ',')).toEqual(['abc']);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
describe('smartSplitAtFirstDelimiter', () => {
|
|
20
|
-
test('splits at first delimiter', () => {
|
|
21
|
-
expect(smartSplitAtFirstDelimiter('a:b:c', ':')).toEqual(['a', 'b:c']);
|
|
22
|
-
});
|
|
23
|
-
test('returns original string when no delimiter', () => {
|
|
24
|
-
expect(smartSplitAtFirstDelimiter('abc', ':')).toEqual(['abc']);
|
|
25
|
-
});
|
|
26
|
-
test('preserves quoted strings before delimiter', () => {
|
|
27
|
-
expect(smartSplitAtFirstDelimiter('"a:b":c', ':')).toEqual(['"a:b"', 'c']);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('ensureNumber', () => {
|
|
31
|
-
test('returns number as is', () => {
|
|
32
|
-
expect(ensureNumber(42)).toBe(42);
|
|
33
|
-
});
|
|
34
|
-
test('parses string number', () => {
|
|
35
|
-
expect(ensureNumber('42')).toBe(42);
|
|
36
|
-
});
|
|
37
|
-
test('parses float', () => {
|
|
38
|
-
expect(ensureNumber('3.14')).toBe(3.14);
|
|
39
|
-
});
|
|
40
|
-
test('returns 0 for NaN', () => {
|
|
41
|
-
expect(ensureNumber('not a number')).toBe(0);
|
|
42
|
-
});
|
|
43
|
-
test('returns 0 for undefined', () => {
|
|
44
|
-
expect(ensureNumber(undefined)).toBe(0);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe('ensureString', () => {
|
|
48
|
-
test('returns string as is', () => {
|
|
49
|
-
expect(ensureString('hello')).toBe('hello');
|
|
50
|
-
});
|
|
51
|
-
test('converts number to string', () => {
|
|
52
|
-
expect(ensureString(42)).toBe('42');
|
|
53
|
-
});
|
|
54
|
-
test('returns empty string for null', () => {
|
|
55
|
-
expect(ensureString(null)).toBe('');
|
|
56
|
-
});
|
|
57
|
-
test('returns empty string for undefined', () => {
|
|
58
|
-
expect(ensureString(undefined)).toBe('');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe('parseScalarOrVariable', () => {
|
|
62
|
-
test('parses quoted string as scalar', () => {
|
|
63
|
-
expect(parseScalarOrVariable('"hello"')).toEqual({
|
|
64
|
-
type: 'Scalar',
|
|
65
|
-
value: 'hello'
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
test('parses boolean true', () => {
|
|
69
|
-
expect(parseScalarOrVariable('true')).toEqual({
|
|
70
|
-
type: 'Scalar',
|
|
71
|
-
value: true
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
test('parses boolean false', () => {
|
|
75
|
-
expect(parseScalarOrVariable('false')).toEqual({
|
|
76
|
-
type: 'Scalar',
|
|
77
|
-
value: false
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
test('parses integer as scalar', () => {
|
|
81
|
-
expect(parseScalarOrVariable('42')).toEqual({
|
|
82
|
-
type: 'Scalar',
|
|
83
|
-
value: 42
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
test('parses float as scalar', () => {
|
|
87
|
-
expect(parseScalarOrVariable('3.14')).toEqual({
|
|
88
|
-
type: 'Scalar',
|
|
89
|
-
value: 3.14
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
test('parses identifier as variable', () => {
|
|
93
|
-
expect(parseScalarOrVariable('name')).toEqual({
|
|
94
|
-
type: 'Variable',
|
|
95
|
-
name: 'name'
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
describe('addSpaceAroundOperators', () => {
|
|
100
|
-
test('adds spaces around ==', () => {
|
|
101
|
-
expect(addSpaceAroundOperators('a==b')).toBe('a == b');
|
|
102
|
-
});
|
|
103
|
-
test('adds spaces around !=', () => {
|
|
104
|
-
expect(addSpaceAroundOperators('a!=b')).toBe('a != b');
|
|
105
|
-
});
|
|
106
|
-
test('adds spaces around >=', () => {
|
|
107
|
-
expect(addSpaceAroundOperators('a>=b')).toBe('a >= b');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('unpackScalarOrValue', () => {
|
|
111
|
-
const context = {
|
|
112
|
-
values: {
|
|
113
|
-
name: 'John'
|
|
114
|
-
},
|
|
115
|
-
language: 'en',
|
|
116
|
-
timezone: 'UTC'
|
|
117
|
-
};
|
|
118
|
-
test('returns scalar value directly', () => {
|
|
119
|
-
expect(unpackScalarOrValue({
|
|
120
|
-
type: 'Scalar',
|
|
121
|
-
value: 'hello'
|
|
122
|
-
}, context)).toBe('hello');
|
|
123
|
-
});
|
|
124
|
-
test('returns variable value from context', () => {
|
|
125
|
-
expect(unpackScalarOrValue({
|
|
126
|
-
type: 'Variable',
|
|
127
|
-
name: 'name'
|
|
128
|
-
}, context)).toBe('John');
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
describe('decodeHtmlEntities', () => {
|
|
132
|
-
describe('named entities', () => {
|
|
133
|
-
test('decodes to non-breaking space', () => {
|
|
134
|
-
expect(decodeHtmlEntities('Hello World')).toBe('Hello\u00A0World');
|
|
135
|
-
});
|
|
136
|
-
test('decodes & to ampersand', () => {
|
|
137
|
-
expect(decodeHtmlEntities('A&B')).toBe('A&B');
|
|
138
|
-
});
|
|
139
|
-
test('decodes < and >', () => {
|
|
140
|
-
expect(decodeHtmlEntities('<div>')).toBe('<div>');
|
|
141
|
-
});
|
|
142
|
-
test('decodes " and '', () => {
|
|
143
|
-
expect(decodeHtmlEntities('"hello'')).toBe('"hello\'');
|
|
144
|
-
});
|
|
145
|
-
test('leaves unknown named entities as is', () => {
|
|
146
|
-
expect(decodeHtmlEntities('&unknown;')).toBe('&unknown;');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
describe('decimal numeric entities', () => {
|
|
150
|
-
test('decodes   to non-breaking space', () => {
|
|
151
|
-
expect(decodeHtmlEntities('Hello World')).toBe('Hello\u00A0World');
|
|
152
|
-
});
|
|
153
|
-
test('decodes < and >', () => {
|
|
154
|
-
expect(decodeHtmlEntities('<div>')).toBe('<div>');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe('hex numeric entities', () => {
|
|
158
|
-
test('decodes   to non-breaking space', () => {
|
|
159
|
-
expect(decodeHtmlEntities('Hello World')).toBe('Hello\u00A0World');
|
|
160
|
-
});
|
|
161
|
-
test('decodes   (short form)', () => {
|
|
162
|
-
expect(decodeHtmlEntities('Hello World')).toBe('Hello\u00A0World');
|
|
163
|
-
});
|
|
164
|
-
test('decodes < and >', () => {
|
|
165
|
-
expect(decodeHtmlEntities('<div>')).toBe('<div>');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe('mixed entities', () => {
|
|
169
|
-
test('decodes multiple different entity types', () => {
|
|
170
|
-
expect(decodeHtmlEntities('<div> <span> ')).toBe('<div>\u00A0<span>\u00A0');
|
|
171
|
-
});
|
|
172
|
-
test('returns text without entities unchanged', () => {
|
|
173
|
-
expect(decodeHtmlEntities('Hello World')).toBe('Hello World');
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { stringToAst } from '../liquid/parser';
|
|
2
|
-
describe('stringToAst', () => {
|
|
3
|
-
describe('text parsing', () => {
|
|
4
|
-
test('parses plain text', () => {
|
|
5
|
-
const ast = stringToAst('Hello World');
|
|
6
|
-
expect(ast).toHaveLength(1);
|
|
7
|
-
expect(ast[0].type).toBe('Text');
|
|
8
|
-
expect(ast[0].content).toBe('Hello World');
|
|
9
|
-
});
|
|
10
|
-
test('parses empty string', () => {
|
|
11
|
-
const ast = stringToAst('');
|
|
12
|
-
expect(ast).toHaveLength(0);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
describe('variable parsing', () => {
|
|
16
|
-
test('parses simple variable', () => {
|
|
17
|
-
const ast = stringToAst('{{ name }}');
|
|
18
|
-
expect(ast).toHaveLength(1);
|
|
19
|
-
const node = ast[0];
|
|
20
|
-
expect(node.type).toBe('Variable');
|
|
21
|
-
expect(node.value).toEqual({
|
|
22
|
-
type: 'Variable',
|
|
23
|
-
name: 'name'
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
test('parses variable with filter', () => {
|
|
27
|
-
const ast = stringToAst('{{ name | capitalize }}');
|
|
28
|
-
expect(ast).toHaveLength(1);
|
|
29
|
-
const node = ast[0];
|
|
30
|
-
expect(node.type).toBe('Variable');
|
|
31
|
-
expect(node.filters).toHaveLength(1);
|
|
32
|
-
expect(node.filters[0].name).toBe('capitalize');
|
|
33
|
-
});
|
|
34
|
-
test('parses variable with multiple filters', () => {
|
|
35
|
-
const ast = stringToAst('{{ name | capitalize | upperCase }}');
|
|
36
|
-
expect(ast).toHaveLength(1);
|
|
37
|
-
const node = ast[0];
|
|
38
|
-
expect(node.filters).toHaveLength(2);
|
|
39
|
-
expect(node.filters[0].name).toBe('capitalize');
|
|
40
|
-
expect(node.filters[1].name).toBe('upperCase');
|
|
41
|
-
});
|
|
42
|
-
test('parses variable mixed with text', () => {
|
|
43
|
-
const ast = stringToAst('Hello {{ name }}!');
|
|
44
|
-
expect(ast).toHaveLength(3);
|
|
45
|
-
expect(ast[0].content).toBe('Hello ');
|
|
46
|
-
expect(ast[1].type).toBe('Variable');
|
|
47
|
-
expect(ast[2].content).toBe('!');
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('if control parsing', () => {
|
|
51
|
-
test('parses simple if block', () => {
|
|
52
|
-
const ast = stringToAst('{% if count == 1 %}one{% endif %}');
|
|
53
|
-
expect(ast).toHaveLength(1);
|
|
54
|
-
const node = ast[0];
|
|
55
|
-
expect(node.type).toBe('Control');
|
|
56
|
-
expect(node.name).toBe('if');
|
|
57
|
-
expect(node.condition[1]).toBe('==');
|
|
58
|
-
});
|
|
59
|
-
test('parses if-else block', () => {
|
|
60
|
-
const ast = stringToAst('{% if active == true %}yes{% else %}no{% endif %}');
|
|
61
|
-
expect(ast).toHaveLength(1);
|
|
62
|
-
const node = ast[0];
|
|
63
|
-
expect(node.children).toHaveLength(1);
|
|
64
|
-
expect(node.elseChildren).toHaveLength(1);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('for control parsing', () => {
|
|
68
|
-
test('parses for loop', () => {
|
|
69
|
-
const ast = stringToAst('{% for item in items %}{{ item }}{% endfor %}');
|
|
70
|
-
expect(ast).toHaveLength(1);
|
|
71
|
-
const node = ast[0];
|
|
72
|
-
expect(node.type).toBe('Control');
|
|
73
|
-
expect(node.name).toBe('for');
|
|
74
|
-
expect(node.varName).toBe('item');
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('HTML tag parsing', () => {
|
|
78
|
-
test('parses self-closing br tag', () => {
|
|
79
|
-
const ast = stringToAst('line1<br/>line2');
|
|
80
|
-
expect(ast).toHaveLength(3);
|
|
81
|
-
expect(ast[0].content).toBe('line1');
|
|
82
|
-
expect(ast[1].type).toBe('Tag');
|
|
83
|
-
expect(ast[1].name).toBe('br');
|
|
84
|
-
expect(ast[2].content).toBe('line2');
|
|
85
|
-
});
|
|
86
|
-
test('parses void hr tag', () => {
|
|
87
|
-
const ast = stringToAst('before<hr>after');
|
|
88
|
-
expect(ast).toHaveLength(3);
|
|
89
|
-
expect(ast[1].name).toBe('hr');
|
|
90
|
-
});
|
|
91
|
-
test('parses img tag with attributes', () => {
|
|
92
|
-
const ast = stringToAst('<img src="test.png" alt="test">');
|
|
93
|
-
expect(ast).toHaveLength(1);
|
|
94
|
-
const node = ast[0];
|
|
95
|
-
expect(node.name).toBe('img');
|
|
96
|
-
expect(node.params).toHaveProperty('src');
|
|
97
|
-
expect(node.params).toHaveProperty('alt');
|
|
98
|
-
});
|
|
99
|
-
test('parses nested tags', () => {
|
|
100
|
-
const ast = stringToAst('<strong>bold text</strong>');
|
|
101
|
-
expect(ast).toHaveLength(1);
|
|
102
|
-
const node = ast[0];
|
|
103
|
-
expect(node.name).toBe('strong');
|
|
104
|
-
expect(node.children).toHaveLength(1);
|
|
105
|
-
expect(node.children[0].content).toBe('bold text');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { stringToAst } from '../liquid/parser';
|
|
5
|
-
import { renderToString, renderToReact } from '../liquid/render';
|
|
6
|
-
const renderString = (template, values = {}, language = 'en') => {
|
|
7
|
-
const ast = stringToAst(template);
|
|
8
|
-
const context = {
|
|
9
|
-
values,
|
|
10
|
-
language,
|
|
11
|
-
timezone: 'UTC'
|
|
12
|
-
};
|
|
13
|
-
return renderToString(ast, context);
|
|
14
|
-
};
|
|
15
|
-
const renderReactNodes = (template, values = {}, language = 'en') => {
|
|
16
|
-
const ast = stringToAst(template);
|
|
17
|
-
const context = {
|
|
18
|
-
values,
|
|
19
|
-
language,
|
|
20
|
-
timezone: 'UTC'
|
|
21
|
-
};
|
|
22
|
-
return renderToReact(ast, context);
|
|
23
|
-
};
|
|
24
|
-
describe('renderToString', () => {
|
|
25
|
-
describe('text rendering', () => {
|
|
26
|
-
test('renders plain text', () => {
|
|
27
|
-
expect(renderString('Hello World')).toBe('Hello World');
|
|
28
|
-
});
|
|
29
|
-
test('renders empty string', () => {
|
|
30
|
-
expect(renderString('')).toBe('');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('variable rendering', () => {
|
|
34
|
-
test('renders simple variable', () => {
|
|
35
|
-
expect(renderString('Hello {{ name }}', {
|
|
36
|
-
name: 'John'
|
|
37
|
-
})).toBe('Hello John');
|
|
38
|
-
});
|
|
39
|
-
test('renders multiple variables', () => {
|
|
40
|
-
expect(renderString('{{ greeting }} {{ name }}', {
|
|
41
|
-
greeting: 'Hi',
|
|
42
|
-
name: 'Jane'
|
|
43
|
-
})).toBe('Hi Jane');
|
|
44
|
-
});
|
|
45
|
-
test('renders variable with filter', () => {
|
|
46
|
-
expect(renderString('{{ name | upperCase }}', {
|
|
47
|
-
name: 'john'
|
|
48
|
-
})).toBe('JOHN');
|
|
49
|
-
});
|
|
50
|
-
test('renders variable with multiple filters', () => {
|
|
51
|
-
expect(renderString('{{ name | capitalize }}', {
|
|
52
|
-
name: 'john'
|
|
53
|
-
})).toBe('John');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe('if control rendering', () => {
|
|
57
|
-
test('renders if block when true', () => {
|
|
58
|
-
expect(renderString('{% if active == true %}yes{% endif %}', {
|
|
59
|
-
active: true
|
|
60
|
-
})).toBe('yes');
|
|
61
|
-
});
|
|
62
|
-
test('renders nothing when false', () => {
|
|
63
|
-
expect(renderString('{% if active == true %}yes{% endif %}', {
|
|
64
|
-
active: false
|
|
65
|
-
})).toBe('');
|
|
66
|
-
});
|
|
67
|
-
test('renders else block when false', () => {
|
|
68
|
-
expect(renderString('{% if active == true %}yes{% else %}no{% endif %}', {
|
|
69
|
-
active: false
|
|
70
|
-
})).toBe('no');
|
|
71
|
-
});
|
|
72
|
-
test('handles numeric comparison', () => {
|
|
73
|
-
expect(renderString('{% if count > 0 %}positive{% endif %}', {
|
|
74
|
-
count: 5
|
|
75
|
-
})).toBe('positive');
|
|
76
|
-
});
|
|
77
|
-
test('handles != operator', () => {
|
|
78
|
-
expect(renderString('{% if status != "done" %}pending{% endif %}', {
|
|
79
|
-
status: 'active'
|
|
80
|
-
})).toBe('pending');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe('for control rendering', () => {
|
|
84
|
-
test('renders for loop', () => {
|
|
85
|
-
expect(renderString('{% for item in items %}{{ item }},{% endfor %}', {
|
|
86
|
-
items: ['a', 'b', 'c']
|
|
87
|
-
})).toBe('a,b,c,');
|
|
88
|
-
});
|
|
89
|
-
test('renders empty for empty array', () => {
|
|
90
|
-
expect(renderString('{% for item in items %}{{ item }}{% endfor %}', {
|
|
91
|
-
items: []
|
|
92
|
-
})).toBe('');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('HTML tag rendering', () => {
|
|
96
|
-
test('renders self-closing tags', () => {
|
|
97
|
-
expect(renderString('line1<br/>line2')).toBe('line1<br/>line2');
|
|
98
|
-
});
|
|
99
|
-
test('renders void tags', () => {
|
|
100
|
-
expect(renderString('before<hr>after')).toBe('before<hr/>after');
|
|
101
|
-
});
|
|
102
|
-
test('renders tags with attributes', () => {
|
|
103
|
-
expect(renderString('<img src="test.png">')).toBe('<img src="test.png"/>');
|
|
104
|
-
});
|
|
105
|
-
test('renders nested tags', () => {
|
|
106
|
-
expect(renderString('<strong>bold</strong>')).toBe('<strong>bold</strong>');
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe('complex templates', () => {
|
|
110
|
-
test('renders template with variable in tag', () => {
|
|
111
|
-
const template = '{% if count > 0 %}<strong>{{ count }}</strong>{% endif %}';
|
|
112
|
-
expect(renderString(template, {
|
|
113
|
-
count: 5
|
|
114
|
-
})).toBe('<strong>5</strong>');
|
|
115
|
-
});
|
|
116
|
-
test('renders pluralized message', () => {
|
|
117
|
-
const template = '{{ count }} {{ count | pluralize: "item", "items" }}';
|
|
118
|
-
expect(renderString(template, {
|
|
119
|
-
count: 1
|
|
120
|
-
})).toBe('1 item');
|
|
121
|
-
expect(renderString(template, {
|
|
122
|
-
count: 5
|
|
123
|
-
})).toBe('5 items');
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
describe('HTML entities', () => {
|
|
127
|
-
test('decodes to non-breaking space', () => {
|
|
128
|
-
expect(renderString('Hello World')).toBe('Hello\u00A0World');
|
|
129
|
-
});
|
|
130
|
-
test('decodes numeric entities', () => {
|
|
131
|
-
expect(renderString('Hello World')).toBe('Hello\u00A0World');
|
|
132
|
-
});
|
|
133
|
-
test('decodes hex entities', () => {
|
|
134
|
-
expect(renderString('Hello World')).toBe('Hello\u00A0World');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
describe('renderToReact', () => {
|
|
139
|
-
describe('text rendering', () => {
|
|
140
|
-
test('renders plain text', () => {
|
|
141
|
-
const result = renderReactNodes('Hello World');
|
|
142
|
-
render(_jsx(_Fragment, {
|
|
143
|
-
children: result
|
|
144
|
-
}));
|
|
145
|
-
expect(screen.getByText('Hello World')).toBeInTheDocument();
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('variable rendering', () => {
|
|
149
|
-
test('renders simple variable', () => {
|
|
150
|
-
const result = renderReactNodes('Hello {{ name }}', {
|
|
151
|
-
name: 'John'
|
|
152
|
-
});
|
|
153
|
-
render(_jsx(_Fragment, {
|
|
154
|
-
children: result
|
|
155
|
-
}));
|
|
156
|
-
expect(screen.getByText(/Hello/)).toBeInTheDocument();
|
|
157
|
-
expect(screen.getByText(/John/)).toBeInTheDocument();
|
|
158
|
-
});
|
|
159
|
-
test('renders variable with filter', () => {
|
|
160
|
-
const result = renderReactNodes('{{ name | upperCase }}', {
|
|
161
|
-
name: 'john'
|
|
162
|
-
});
|
|
163
|
-
render(_jsx(_Fragment, {
|
|
164
|
-
children: result
|
|
165
|
-
}));
|
|
166
|
-
expect(screen.getByText('JOHN')).toBeInTheDocument();
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe('HTML tag rendering', () => {
|
|
170
|
-
test('renders strong tag', () => {
|
|
171
|
-
const result = renderReactNodes('<strong>bold text</strong>');
|
|
172
|
-
render(_jsx(_Fragment, {
|
|
173
|
-
children: result
|
|
174
|
-
}));
|
|
175
|
-
const element = screen.getByText('bold text');
|
|
176
|
-
expect(element.tagName).toBe('STRONG');
|
|
177
|
-
});
|
|
178
|
-
test('renders br tag', () => {
|
|
179
|
-
const result = renderReactNodes('line1<br/>line2');
|
|
180
|
-
const {
|
|
181
|
-
container
|
|
182
|
-
} = render(_jsx(_Fragment, {
|
|
183
|
-
children: result
|
|
184
|
-
}));
|
|
185
|
-
expect(container.querySelector('br')).toBeInTheDocument();
|
|
186
|
-
});
|
|
187
|
-
test('renders img tag with attributes', () => {
|
|
188
|
-
const result = renderReactNodes('<img src="test.png" alt="test image">');
|
|
189
|
-
render(_jsx(_Fragment, {
|
|
190
|
-
children: result
|
|
191
|
-
}));
|
|
192
|
-
const img = screen.getByAltText('test image');
|
|
193
|
-
expect(img).toHaveAttribute('src', 'test.png');
|
|
194
|
-
});
|
|
195
|
-
test('renders anchor tag with href', () => {
|
|
196
|
-
const result = renderReactNodes('<a href="https://example.com">Link</a>');
|
|
197
|
-
render(_jsx(_Fragment, {
|
|
198
|
-
children: result
|
|
199
|
-
}));
|
|
200
|
-
const link = screen.getByText('Link');
|
|
201
|
-
expect(link.tagName).toBe('A');
|
|
202
|
-
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
203
|
-
});
|
|
204
|
-
test('renders anchor tag with multiple attributes', () => {
|
|
205
|
-
const result = renderReactNodes('<a href="https://example.com" target="_blank" rel="noreferrer">External Link</a>');
|
|
206
|
-
render(_jsx(_Fragment, {
|
|
207
|
-
children: result
|
|
208
|
-
}));
|
|
209
|
-
const link = screen.getByText('External Link');
|
|
210
|
-
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
211
|
-
expect(link).toHaveAttribute('target', '_blank');
|
|
212
|
-
expect(link).toHaveAttribute('rel', 'noreferrer');
|
|
213
|
-
});
|
|
214
|
-
test('renders anchor tag with variable in href', () => {
|
|
215
|
-
const result = renderReactNodes('<a href=linkUrl>Custom Link</a>', {
|
|
216
|
-
linkUrl: 'https://custom.com'
|
|
217
|
-
});
|
|
218
|
-
render(_jsx(_Fragment, {
|
|
219
|
-
children: result
|
|
220
|
-
}));
|
|
221
|
-
const link = screen.getByText('Custom Link');
|
|
222
|
-
expect(link).toHaveAttribute('href', 'https://custom.com');
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
describe('control structures', () => {
|
|
226
|
-
test('renders if block when true', () => {
|
|
227
|
-
const result = renderReactNodes('{% if active == true %}visible{% endif %}', {
|
|
228
|
-
active: true
|
|
229
|
-
});
|
|
230
|
-
render(_jsx(_Fragment, {
|
|
231
|
-
children: result
|
|
232
|
-
}));
|
|
233
|
-
expect(screen.getByText('visible')).toBeInTheDocument();
|
|
234
|
-
});
|
|
235
|
-
test('renders else block when false', () => {
|
|
236
|
-
const result = renderReactNodes('{% if active == true %}yes{% else %}no{% endif %}', {
|
|
237
|
-
active: false
|
|
238
|
-
});
|
|
239
|
-
render(_jsx(_Fragment, {
|
|
240
|
-
children: result
|
|
241
|
-
}));
|
|
242
|
-
expect(screen.getByText('no')).toBeInTheDocument();
|
|
243
|
-
});
|
|
244
|
-
test('renders for loop', () => {
|
|
245
|
-
const result = renderReactNodes('{% for item in items %}<span>{{ item }}</span>{% endfor %}', {
|
|
246
|
-
items: ['a', 'b', 'c']
|
|
247
|
-
});
|
|
248
|
-
render(_jsx(_Fragment, {
|
|
249
|
-
children: result
|
|
250
|
-
}));
|
|
251
|
-
expect(screen.getByText('a')).toBeInTheDocument();
|
|
252
|
-
expect(screen.getByText('b')).toBeInTheDocument();
|
|
253
|
-
expect(screen.getByText('c')).toBeInTheDocument();
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
describe('text tag with styles', () => {
|
|
257
|
-
test('renders text tag', () => {
|
|
258
|
-
const result = renderReactNodes('<text>styled text</text>');
|
|
259
|
-
render(_jsx(_Fragment, {
|
|
260
|
-
children: result
|
|
261
|
-
}));
|
|
262
|
-
expect(screen.getByText('styled text')).toBeInTheDocument();
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
describe('HTML entities', () => {
|
|
266
|
-
test('decodes in React rendering', () => {
|
|
267
|
-
const result = renderReactNodes('Hello World');
|
|
268
|
-
const {
|
|
269
|
-
container
|
|
270
|
-
} = render(_jsx(_Fragment, {
|
|
271
|
-
children: result
|
|
272
|
-
}));
|
|
273
|
-
expect(container.textContent).toBe('Hello\u00A0World');
|
|
274
|
-
});
|
|
275
|
-
test('decodes numeric entities in React rendering', () => {
|
|
276
|
-
const result = renderReactNodes('Hello World');
|
|
277
|
-
const {
|
|
278
|
-
container
|
|
279
|
-
} = render(_jsx(_Fragment, {
|
|
280
|
-
children: result
|
|
281
|
-
}));
|
|
282
|
-
expect(container.textContent).toBe('Hello\u00A0World');
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react';
|
|
2
|
-
import { useDropdownPosition } from '../useDropdownPosition';
|
|
3
|
-
const floating = {
|
|
4
|
-
middleware: []
|
|
5
|
-
};
|
|
6
|
-
jest.mock('@floating-ui/react-dom', () => ({
|
|
7
|
-
...jest.requireActual('@floating-ui/react-dom'),
|
|
8
|
-
size: options => ({
|
|
9
|
-
name: 'size',
|
|
10
|
-
options
|
|
11
|
-
}),
|
|
12
|
-
useFloating: config => {
|
|
13
|
-
floating.middleware = config.middleware;
|
|
14
|
-
return {
|
|
15
|
-
refs: {
|
|
16
|
-
reference: {
|
|
17
|
-
current: null
|
|
18
|
-
},
|
|
19
|
-
floating: {
|
|
20
|
-
current: null
|
|
21
|
-
},
|
|
22
|
-
setReference: jest.fn(),
|
|
23
|
-
setFloating: jest.fn()
|
|
24
|
-
},
|
|
25
|
-
floatingStyles: {}
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
|
-
const maxHeightFor = availableHeight => {
|
|
30
|
-
renderHook(() => useDropdownPosition({
|
|
31
|
-
isOpen: true
|
|
32
|
-
}));
|
|
33
|
-
const style = {};
|
|
34
|
-
floating.middleware.find(m => m.name === 'size').options.apply({
|
|
35
|
-
rects: {
|
|
36
|
-
reference: {
|
|
37
|
-
width: 200
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
elements: {
|
|
41
|
-
floating: {
|
|
42
|
-
style
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
availableWidth: 1000,
|
|
46
|
-
availableHeight
|
|
47
|
-
});
|
|
48
|
-
return style.maxHeight;
|
|
49
|
-
};
|
|
50
|
-
describe('useDropdownPosition max height', () => {
|
|
51
|
-
it('caps the dropdown at 300px when there is more room', () => {
|
|
52
|
-
expect(maxHeightFor(1200)).toBe('300px');
|
|
53
|
-
});
|
|
54
|
-
it('shrinks to the room below the field when it is less than the cap', () => {
|
|
55
|
-
expect(maxHeightFor(200)).toBe('192px');
|
|
56
|
-
});
|
|
57
|
-
it('never goes negative', () => {
|
|
58
|
-
expect(maxHeightFor(4)).toBe('0px');
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { validateContentSting } from '../../../RichMessageEditor/slate/helpers';
|
|
2
|
-
import { isResolvableDc, parseDc } from '../token';
|
|
3
|
-
// The lists below mirror channels/publisher
|
|
4
|
-
// internal/services/dynamiccontentreplacer/constants.go — keep them in sync.
|
|
5
|
-
const caseInsensitiveModifiers = ['capitalizefirst', 'capitalizeallfirst', 'uppercase', 'lowercase', 'regular', 'base64', 'cent', 'dollar', 'comma', 'euro', 'jpy', 'lira'];
|
|
6
|
-
const dateModifiers = ['M-d-y', 'm-d-y', 'M d y', 'M d Y', 'l', 'M d', 'H:i', 'm-d-y H:i'];
|
|
7
|
-
describe('isResolvableDc', () => {
|
|
8
|
-
test.each(caseInsensitiveModifiers)('accepts %s', modifier => {
|
|
9
|
-
expect(isResolvableDc(parseDc(`{Name|${modifier}}`))).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
test.each(caseInsensitiveModifiers)('accepts %s whatever the case', modifier => {
|
|
12
|
-
expect(isResolvableDc(parseDc(`{Name|${modifier.toUpperCase()}}`))).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
test.each(dateModifiers)('accepts the date modifier %s', modifier => {
|
|
15
|
-
expect(isResolvableDc(parseDc(`{Name|${modifier}}`))).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
test('rejects a date modifier in the wrong case, as the sender does', () => {
|
|
18
|
-
expect(isResolvableDc(parseDc('{Name|m d y}'))).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
test.each([['{Name|}', 'no modifier at all'], ['{Name|nope}', 'a modifier outside the list'], ['{|regular}', 'no tag name']])('rejects %s (%s)', token => {
|
|
21
|
-
expect(isResolvableDc(parseDc(token))).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
test('keeps a default value out of the verdict', () => {
|
|
24
|
-
expect(isResolvableDc(parseDc('{WalletPassLink|regular|no pass}'))).toBe(true);
|
|
25
|
-
expect(isResolvableDc(parseDc('{WalletPassLink||no pass}'))).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe('validateContentSting', () => {
|
|
29
|
-
test.each([['Tap here!\n{WalletSerialNo|regular}', true], ['Tap here!\n{WalletSerialNo|}', false], ['{WalletSerialNo|regular}{WalletPassLink|}', false], ['Hi {{ user.name | upcase }}, plain liquid is not a token', true], ['no tokens at all', true], ['', true]])('%s -> %s', (content, expected) => {
|
|
30
|
-
expect(validateContentSting(content)).toBe(expected);
|
|
31
|
-
});
|
|
32
|
-
});
|