@capillarytech/creatives-library 8.0.255-alpha.1 → 8.0.255
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/package.json +1 -1
- package/v2Components/HtmlEditor/__tests__/HTMLEditor.test.js +83 -0
- package/v2Components/HtmlEditor/components/CodeEditorPane/_codeEditorPane.scss +2 -2
- package/v2Components/HtmlEditor/components/ValidationErrorDisplay/_validationErrorDisplay.scss +1 -0
- package/v2Components/HtmlEditor/components/ValidationTabs/_validationTabs.scss +27 -26
- package/v2Components/HtmlEditor/hooks/__tests__/useValidation.test.js +103 -0
- package/v2Containers/EmailWrapper/components/EmailWrapperView.js +2 -1
- package/v2Containers/EmailWrapper/components/__tests__/EmailHTMLEditor.test.js +10 -0
- package/v2Components/HtmlEditor/hooks/__tests__/useValidation.apiErrors.test.js +0 -794
package/package.json
CHANGED
|
@@ -2878,6 +2878,89 @@ describe('HTMLEditor', () => {
|
|
|
2878
2878
|
expect(ref.current).toBeTruthy();
|
|
2879
2879
|
});
|
|
2880
2880
|
});
|
|
2881
|
+
it('computes issue counts and validation state from ref', async () => {
|
|
2882
|
+
const ref = React.createRef();
|
|
2883
|
+
const WrappedHTMLEditor = HTMLEditor.WrappedComponent || HTMLEditor;
|
|
2884
|
+
const intlProvider = new IntlProvider({ locale: 'en', messages: {} }, {});
|
|
2885
|
+
const { intl } = intlProvider.getChildContext();
|
|
2886
|
+
|
|
2887
|
+
mockUseValidationImpl.mockReturnValue({
|
|
2888
|
+
isValidating: false,
|
|
2889
|
+
hasBlockingErrors: true,
|
|
2890
|
+
getAllIssues: () => [
|
|
2891
|
+
{ source: 'liquid-validator', rule: 'liquid-syntax', message: 'Liquid issue' },
|
|
2892
|
+
{ source: 'htmlhint', rule: 'tag-pair', message: 'tag must be paired' },
|
|
2893
|
+
{ source: 'htmlhint', rule: 'html-error', message: 'HTML error' },
|
|
2894
|
+
],
|
|
2895
|
+
isClean: () => false,
|
|
2896
|
+
summary: { totalErrors: 2, totalWarnings: 0 },
|
|
2897
|
+
});
|
|
2898
|
+
|
|
2899
|
+
render(
|
|
2900
|
+
<TestWrapper>
|
|
2901
|
+
<WrappedHTMLEditor {...defaultProps} intl={intl} ref={ref} />
|
|
2902
|
+
</TestWrapper>
|
|
2903
|
+
);
|
|
2904
|
+
|
|
2905
|
+
act(() => {
|
|
2906
|
+
jest.runAllTimers();
|
|
2907
|
+
});
|
|
2908
|
+
|
|
2909
|
+
await waitFor(() => {
|
|
2910
|
+
expect(ref.current).toBeTruthy();
|
|
2911
|
+
});
|
|
2912
|
+
|
|
2913
|
+
const issueCounts = ref.current.getIssueCounts();
|
|
2914
|
+
expect(issueCounts).toEqual({
|
|
2915
|
+
html: 1,
|
|
2916
|
+
label: 1,
|
|
2917
|
+
liquid: 1,
|
|
2918
|
+
total: 3,
|
|
2919
|
+
});
|
|
2920
|
+
|
|
2921
|
+
const validationState = ref.current.getValidationState();
|
|
2922
|
+
expect(validationState.hasErrors).toBe(true);
|
|
2923
|
+
expect(validationState.issueCounts).toEqual({
|
|
2924
|
+
html: 1,
|
|
2925
|
+
label: 1,
|
|
2926
|
+
liquid: 1,
|
|
2927
|
+
total: 3,
|
|
2928
|
+
});
|
|
2929
|
+
});
|
|
2930
|
+
|
|
2931
|
+
it('returns empty counts when validation is missing getAllIssues', async () => {
|
|
2932
|
+
const ref = React.createRef();
|
|
2933
|
+
const WrappedHTMLEditor = HTMLEditor.WrappedComponent || HTMLEditor;
|
|
2934
|
+
const intlProvider = new IntlProvider({ locale: 'en', messages: {} }, {});
|
|
2935
|
+
const { intl } = intlProvider.getChildContext();
|
|
2936
|
+
|
|
2937
|
+
mockUseValidationImpl.mockReturnValue({
|
|
2938
|
+
isValidating: false,
|
|
2939
|
+
isClean: () => true,
|
|
2940
|
+
summary: { totalErrors: 0, totalWarnings: 0 },
|
|
2941
|
+
});
|
|
2942
|
+
|
|
2943
|
+
render(
|
|
2944
|
+
<TestWrapper>
|
|
2945
|
+
<WrappedHTMLEditor {...defaultProps} intl={intl} ref={ref} />
|
|
2946
|
+
</TestWrapper>
|
|
2947
|
+
);
|
|
2948
|
+
|
|
2949
|
+
act(() => {
|
|
2950
|
+
jest.runAllTimers();
|
|
2951
|
+
});
|
|
2952
|
+
|
|
2953
|
+
await waitFor(() => {
|
|
2954
|
+
expect(ref.current).toBeTruthy();
|
|
2955
|
+
});
|
|
2956
|
+
|
|
2957
|
+
expect(ref.current.getIssueCounts()).toEqual({
|
|
2958
|
+
html: 0, label: 0, liquid: 0, total: 0,
|
|
2959
|
+
});
|
|
2960
|
+
expect(ref.current.getValidationState().issueCounts).toEqual({
|
|
2961
|
+
html: 0, label: 0, liquid: 0, total: 0,
|
|
2962
|
+
});
|
|
2963
|
+
});
|
|
2881
2964
|
});
|
|
2882
2965
|
|
|
2883
2966
|
describe('Props coverage (lines 54-84)', () => {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
|
|
54
54
|
&__validation {
|
|
55
55
|
border-top: 0.0625rem solid $CAP_G04;
|
|
56
|
-
background: $
|
|
56
|
+
background: $CAP_WHITE;
|
|
57
57
|
max-height: 12.5rem;
|
|
58
58
|
overflow-y: auto;
|
|
59
59
|
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
|
|
67
67
|
// Add Label button visibility: 50% opacity while typing, 100% on hover
|
|
68
68
|
.code-editor-pane__actions {
|
|
69
|
-
opacity: 0.
|
|
69
|
+
opacity: 0.7; // 70% transparent while typing
|
|
70
70
|
pointer-events: auto; // Always clickable
|
|
71
71
|
transition: opacity 0.2s ease;
|
|
72
72
|
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
.validation-tabs {
|
|
8
8
|
overflow-y: hidden;
|
|
9
9
|
width: 100%;
|
|
10
|
-
background-color: $CAP_COLOR_05; // Light pink background
|
|
11
10
|
border-radius: 0.25rem;
|
|
12
|
-
padding: 1rem 1rem;
|
|
13
11
|
box-sizing: border-box;
|
|
14
12
|
|
|
15
13
|
&__header {
|
|
@@ -24,20 +22,30 @@
|
|
|
24
22
|
|
|
25
23
|
// Override CapTab styles for proper spacing
|
|
26
24
|
.cap-tab-v2 {
|
|
25
|
+
.ant-tabs-bar {
|
|
26
|
+
padding: 0.5rem 0.5rem;
|
|
27
|
+
background-color: $CAP_COLOR_05;
|
|
28
|
+
}
|
|
27
29
|
.ant-tabs-nav {
|
|
28
30
|
margin-bottom: 0;
|
|
29
31
|
|
|
30
32
|
&::before {
|
|
31
|
-
border-bottom: none;
|
|
33
|
+
border-bottom: none; // Remove bottom border
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
.ant-tabs-tab {
|
|
36
38
|
padding: 0.5rem 0.75rem; // Add horizontal padding for spacing
|
|
37
39
|
margin-right: 0; // Remove margin, use padding instead
|
|
40
|
+
|
|
38
41
|
color: $CAP_G03;
|
|
39
42
|
font-size: 0.875rem;
|
|
40
|
-
font-weight:
|
|
43
|
+
font-weight: 400;
|
|
44
|
+
line-height: 1;
|
|
45
|
+
letter-spacing: 0;
|
|
46
|
+
background-color: $CAP_COLOR_05;
|
|
47
|
+
border-radius: 0.25rem;
|
|
48
|
+
border-bottom: none; // Remove bottom border
|
|
41
49
|
|
|
42
50
|
& + .ant-tabs-tab {
|
|
43
51
|
margin-left: 1.5rem; // Add space between tabs
|
|
@@ -45,7 +53,7 @@
|
|
|
45
53
|
|
|
46
54
|
&:hover {
|
|
47
55
|
color: $CAP_COLOR_05;
|
|
48
|
-
background:
|
|
56
|
+
background-color: $CAP_COLOR_05;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
&.ant-tabs-tab-active {
|
|
@@ -57,8 +65,7 @@
|
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
.ant-tabs-ink-bar {
|
|
60
|
-
|
|
61
|
-
height: 0.125rem;
|
|
68
|
+
display: none; // Hide the ink bar (bottom border indicator)
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
.ant-tabs-content-holder {
|
|
@@ -81,17 +88,17 @@
|
|
|
81
88
|
&__actions {
|
|
82
89
|
display: flex;
|
|
83
90
|
align-items: center;
|
|
84
|
-
gap: 0.5rem;
|
|
85
91
|
flex-shrink: 0;
|
|
86
92
|
padding-top: 0.5rem;
|
|
93
|
+
background-color: $CAP_COLOR_05;
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
&__close {
|
|
90
97
|
display: flex;
|
|
91
98
|
align-items: center;
|
|
92
99
|
justify-content: center;
|
|
93
|
-
width: 1.
|
|
94
|
-
height:
|
|
100
|
+
width: 1.9rem;
|
|
101
|
+
height: 2.3rem;
|
|
95
102
|
padding: 0;
|
|
96
103
|
background: transparent;
|
|
97
104
|
border: none;
|
|
@@ -100,10 +107,10 @@
|
|
|
100
107
|
color: $CAP_G03;
|
|
101
108
|
transition: all 0.2s ease;
|
|
102
109
|
|
|
103
|
-
&:hover {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
110
|
+
// &:hover {
|
|
111
|
+
// background-color: rgba($CAP_COLOR_05, 0.1);
|
|
112
|
+
// color: $CAP_COLOR_05;
|
|
113
|
+
// }
|
|
107
114
|
|
|
108
115
|
.cap-icon-v2 {
|
|
109
116
|
font-size: 0.875rem;
|
|
@@ -113,7 +120,6 @@
|
|
|
113
120
|
&__content {
|
|
114
121
|
max-height: 15rem; // Limit height for many errors
|
|
115
122
|
overflow-y: auto;
|
|
116
|
-
padding-right: 0.25rem;
|
|
117
123
|
padding-bottom: 0; // Remove bottom padding completely
|
|
118
124
|
|
|
119
125
|
// Custom scrollbar
|
|
@@ -139,8 +145,8 @@
|
|
|
139
145
|
display: flex;
|
|
140
146
|
align-items: flex-start;
|
|
141
147
|
gap: 0.5rem;
|
|
142
|
-
padding: 0.
|
|
143
|
-
|
|
148
|
+
padding: 0.5rem 0.5rem; // Reduced from 0.375rem
|
|
149
|
+
margin-bottom: 3px;
|
|
144
150
|
|
|
145
151
|
&:last-child {
|
|
146
152
|
border-bottom: none;
|
|
@@ -209,9 +215,8 @@
|
|
|
209
215
|
flex-shrink: 0;
|
|
210
216
|
display: flex;
|
|
211
217
|
align-items: center;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
height: 1.25rem;
|
|
218
|
+
width: 1.7rem;
|
|
219
|
+
height: 1.7rem;
|
|
215
220
|
padding: 0;
|
|
216
221
|
background: transparent;
|
|
217
222
|
border: none;
|
|
@@ -220,13 +225,8 @@
|
|
|
220
225
|
color: $CAP_G04;
|
|
221
226
|
transition: all 0.2s ease;
|
|
222
227
|
|
|
223
|
-
&:hover {
|
|
224
|
-
background-color: rgba($CAP_G01, 0.1);
|
|
225
|
-
color: $CAP_G01;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
228
|
.anticon {
|
|
229
|
-
font-size:
|
|
229
|
+
font-size: 1rem; // Increased icon size
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
}
|
|
@@ -240,6 +240,7 @@
|
|
|
240
240
|
.ant-tabs-tab {
|
|
241
241
|
margin-right: 1rem;
|
|
242
242
|
font-size: 0.8125rem;
|
|
243
|
+
background-color: $CAP_COLOR_05;
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
@@ -84,6 +84,7 @@ const TestComponent = ({ content, variant, options, onStateChange }) => {
|
|
|
84
84
|
<div data-testid="is-clean">{String(validationState.isClean())}</div>
|
|
85
85
|
<div data-testid="has-errors">{String(validationState.hasErrors)}</div>
|
|
86
86
|
<div data-testid="has-warnings">{String(validationState.hasWarnings)}</div>
|
|
87
|
+
<div data-testid="has-blocking-errors">{String(validationState.hasBlockingErrors)}</div>
|
|
87
88
|
<div data-testid="total-errors">{validationState.summary.totalErrors}</div>
|
|
88
89
|
<div data-testid="total-warnings">{validationState.summary.totalWarnings}</div>
|
|
89
90
|
<div data-testid="all-issues-count">{validationState.getAllIssues().length}</div>
|
|
@@ -523,6 +524,60 @@ describe('useValidation', () => {
|
|
|
523
524
|
});
|
|
524
525
|
});
|
|
525
526
|
|
|
527
|
+
describe('API validation errors and line detection', () => {
|
|
528
|
+
it('maps api errors into issues with line from message', async () => {
|
|
529
|
+
let validationState;
|
|
530
|
+
const apiValidationErrors = {
|
|
531
|
+
liquidErrors: ['Line 5: Liquid error'],
|
|
532
|
+
standardErrors: ['line: 3 Standard error'],
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
render(
|
|
536
|
+
<TestComponent
|
|
537
|
+
content="<div>\n{{ tag }}\n</div>"
|
|
538
|
+
options={{ apiValidationErrors }}
|
|
539
|
+
onStateChange={(state) => { validationState = state; }}
|
|
540
|
+
/>
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
await waitFor(() => {
|
|
544
|
+
expect(validationState).toBeDefined();
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
const issues = validationState.getAllIssues();
|
|
548
|
+
const liquidIssue = issues.find((issue) => issue.source === 'liquid-validator');
|
|
549
|
+
const standardIssue = issues.find((issue) => issue.source === 'api-validator');
|
|
550
|
+
|
|
551
|
+
expect(liquidIssue.line).toBe(5);
|
|
552
|
+
expect(standardIssue.line).toBe(3);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it('extracts line number from tag lookup', async () => {
|
|
556
|
+
let validationState;
|
|
557
|
+
const apiValidationErrors = {
|
|
558
|
+
liquidErrors: [],
|
|
559
|
+
standardErrors: ['Unsupported tags: missing_tag'],
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
render(
|
|
563
|
+
<TestComponent
|
|
564
|
+
content="{{ missing_tag }}\n<div></div>"
|
|
565
|
+
options={{ apiValidationErrors }}
|
|
566
|
+
onStateChange={(state) => { validationState = state; }}
|
|
567
|
+
/>
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
await waitFor(() => {
|
|
571
|
+
expect(validationState).toBeDefined();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
const issues = validationState.getAllIssues();
|
|
575
|
+
const standardIssue = issues.find((issue) => issue.source === 'api-validator');
|
|
576
|
+
|
|
577
|
+
expect(standardIssue.line).toBe(1);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
|
|
526
581
|
// Helper Methods tests removed due to async timing issues with fake timers and React state updates
|
|
527
582
|
// The functionality is verified through integration tests and other passing tests
|
|
528
583
|
|
|
@@ -586,5 +641,53 @@ describe('useValidation', () => {
|
|
|
586
641
|
// hasWarnings and hasSecurityIssues tests removed due to async timing issues
|
|
587
642
|
// The functionality is verified through integration tests and the hasErrors test above
|
|
588
643
|
});
|
|
644
|
+
|
|
645
|
+
describe('Blocking errors', () => {
|
|
646
|
+
it('treats protocol security issues as blocking errors', async () => {
|
|
647
|
+
const { isContentSafe, findUnsafeContent } = require('../../utils/contentSanitizer');
|
|
648
|
+
const { validateHTML, extractAndValidateCSS } = require('../../utils/htmlValidator');
|
|
649
|
+
let validationState;
|
|
650
|
+
validateHTML.mockImplementationOnce(() => ({
|
|
651
|
+
isValid: true,
|
|
652
|
+
errors: [],
|
|
653
|
+
warnings: [],
|
|
654
|
+
info: [],
|
|
655
|
+
}));
|
|
656
|
+
extractAndValidateCSS.mockImplementationOnce(() => ({
|
|
657
|
+
isValid: true,
|
|
658
|
+
errors: [],
|
|
659
|
+
warnings: [],
|
|
660
|
+
info: [],
|
|
661
|
+
}));
|
|
662
|
+
isContentSafe.mockImplementationOnce(() => false);
|
|
663
|
+
findUnsafeContent.mockImplementationOnce(() => [{ type: 'JavaScript Protocol' }]);
|
|
664
|
+
|
|
665
|
+
render(
|
|
666
|
+
<TestComponent
|
|
667
|
+
content="<a href='javascript:alert(1)'>x</a>"
|
|
668
|
+
options={{ enableRealTime: false }}
|
|
669
|
+
onStateChange={(state) => { validationState = state; }}
|
|
670
|
+
/>
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
await waitFor(() => {
|
|
674
|
+
expect(validationState).toBeDefined();
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
await act(async () => {
|
|
678
|
+
validationState.forceValidation();
|
|
679
|
+
await Promise.resolve();
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
await waitFor(() => {
|
|
683
|
+
expect(validationState.getAllIssues().length).toBe(1);
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
const [issue] = validationState.getAllIssues();
|
|
687
|
+
expect(issue.rule).toBe('sanitizer.dangerousProtocolDetected');
|
|
688
|
+
expect(issue.severity).toBe('error');
|
|
689
|
+
expect(issue.source).toBe('security');
|
|
690
|
+
});
|
|
691
|
+
});
|
|
589
692
|
});
|
|
590
693
|
|
|
@@ -41,6 +41,7 @@ const CardContainer = styled.div`
|
|
|
41
41
|
}
|
|
42
42
|
`;
|
|
43
43
|
|
|
44
|
+
|
|
44
45
|
// Mode selection component
|
|
45
46
|
const ModeSelectionUI = ({
|
|
46
47
|
isFullMode,
|
|
@@ -77,7 +78,7 @@ const ModeSelectionUI = ({
|
|
|
77
78
|
</CardContainer>
|
|
78
79
|
<>
|
|
79
80
|
{emailCreateMode === EMAIL_CREATE_MODES.UPLOAD && (
|
|
80
|
-
<div
|
|
81
|
+
<div>
|
|
81
82
|
<CapUploader onChange={useFileUpload} accept=".zip, .html, .htm" showUploadList={false}>
|
|
82
83
|
{(isFullMode && isTemplateNameEmpty) && (
|
|
83
84
|
<CapError type="error">
|
|
@@ -435,6 +435,16 @@ describe('EmailHTMLEditor', () => {
|
|
|
435
435
|
});
|
|
436
436
|
|
|
437
437
|
describe('Component Rendering', () => {
|
|
438
|
+
it('uses default loading flags when undefined', () => {
|
|
439
|
+
renderWithIntl({
|
|
440
|
+
isReadOnly: undefined,
|
|
441
|
+
fetchingLiquidTags: undefined,
|
|
442
|
+
createTemplateInProgress: undefined,
|
|
443
|
+
fetchingCmsData: undefined,
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
expect(screen.getByTestId('html-editor')).toBeInTheDocument();
|
|
447
|
+
});
|
|
438
448
|
it('renders without crashing', () => {
|
|
439
449
|
renderWithIntl();
|
|
440
450
|
expect(screen.getByTestId('html-editor')).toBeInTheDocument();
|
|
@@ -1,794 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useValidation Hook Tests - API Validation Errors Coverage
|
|
3
|
-
*
|
|
4
|
-
* Additional tests to cover API validation errors and other uncovered lines
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import { render, screen, act } from '@testing-library/react';
|
|
9
|
-
import '@testing-library/jest-dom';
|
|
10
|
-
import { useValidation } from '../useValidation';
|
|
11
|
-
|
|
12
|
-
// Mock validation utilities
|
|
13
|
-
jest.mock('../../utils/htmlValidator', () => ({
|
|
14
|
-
validateHTML: jest.fn(() => ({
|
|
15
|
-
isValid: true,
|
|
16
|
-
errors: [],
|
|
17
|
-
warnings: [],
|
|
18
|
-
info: [],
|
|
19
|
-
})),
|
|
20
|
-
extractAndValidateCSS: jest.fn(() => ({
|
|
21
|
-
isValid: true,
|
|
22
|
-
errors: [],
|
|
23
|
-
warnings: [],
|
|
24
|
-
info: [],
|
|
25
|
-
})),
|
|
26
|
-
}));
|
|
27
|
-
|
|
28
|
-
jest.mock('../../utils/contentSanitizer', () => ({
|
|
29
|
-
sanitizeHTML: jest.fn((content) => ({
|
|
30
|
-
sanitized: content,
|
|
31
|
-
warnings: [],
|
|
32
|
-
})),
|
|
33
|
-
isContentSafe: jest.fn(() => true),
|
|
34
|
-
findUnsafeContent: jest.fn(() => []),
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
// Test wrapper component
|
|
38
|
-
const TestComponent = ({ content, variant, options, onStateChange }) => {
|
|
39
|
-
const validationState = useValidation(content, variant, options);
|
|
40
|
-
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
if (onStateChange) {
|
|
43
|
-
onStateChange(validationState);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<div>
|
|
49
|
-
<div data-testid="is-validating">{String(validationState.isValidating)}</div>
|
|
50
|
-
<div data-testid="is-valid">{String(validationState.isValid)}</div>
|
|
51
|
-
<div data-testid="is-secure">{String(validationState.isSecure)}</div>
|
|
52
|
-
<div data-testid="is-clean">{String(validationState.isClean())}</div>
|
|
53
|
-
<div data-testid="has-errors">{String(validationState.hasErrors)}</div>
|
|
54
|
-
<div data-testid="has-warnings">{String(validationState.hasWarnings)}</div>
|
|
55
|
-
<div data-testid="total-errors">{validationState.summary.totalErrors}</div>
|
|
56
|
-
<div data-testid="total-warnings">{validationState.summary.totalWarnings}</div>
|
|
57
|
-
<div data-testid="all-issues-count">{validationState.getAllIssues().length}</div>
|
|
58
|
-
<div data-testid="liquid-errors-count">
|
|
59
|
-
{validationState.getAllIssues().filter(issue => issue.source === 'liquid-validator').length}
|
|
60
|
-
</div>
|
|
61
|
-
<div data-testid="standard-errors-count">
|
|
62
|
-
{validationState.getAllIssues().filter(issue => issue.source === 'api-validator').length}
|
|
63
|
-
</div>
|
|
64
|
-
|
|
65
|
-
<button onClick={() => validationState.forceValidation()} data-testid="force-validate">
|
|
66
|
-
Force Validate
|
|
67
|
-
</button>
|
|
68
|
-
<button onClick={() => validationState.clearValidation()} data-testid="clear">
|
|
69
|
-
Clear
|
|
70
|
-
</button>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
describe('useValidation - API Validation Errors', () => {
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
jest.useFakeTimers();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
afterEach(() => {
|
|
81
|
-
jest.runOnlyPendingTimers();
|
|
82
|
-
jest.useRealTimers();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('API Validation Errors Integration', () => {
|
|
86
|
-
it('includes liquid API errors in getAllIssues', async () => {
|
|
87
|
-
const apiValidationErrors = {
|
|
88
|
-
liquidErrors: ['Liquid error on line 5', 'Another liquid error'],
|
|
89
|
-
standardErrors: [],
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
render(
|
|
93
|
-
<TestComponent
|
|
94
|
-
content="<p>Test</p>"
|
|
95
|
-
options={{ apiValidationErrors }}
|
|
96
|
-
/>
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
await act(async () => {
|
|
100
|
-
jest.advanceTimersByTime(500);
|
|
101
|
-
await Promise.resolve();
|
|
102
|
-
await Promise.resolve();
|
|
103
|
-
await Promise.resolve();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// API errors should be included in getAllIssues
|
|
107
|
-
const liquidCount = parseInt(screen.getByTestId('liquid-errors-count').textContent, 10);
|
|
108
|
-
const allCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
109
|
-
expect(liquidCount).toBeGreaterThanOrEqual(2);
|
|
110
|
-
expect(allCount).toBeGreaterThanOrEqual(2);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('includes standard API errors in getAllIssues', async () => {
|
|
114
|
-
const apiValidationErrors = {
|
|
115
|
-
liquidErrors: [],
|
|
116
|
-
standardErrors: ['Standard error on line 3', 'Another standard error'],
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
render(
|
|
120
|
-
<TestComponent
|
|
121
|
-
content="<p>Test</p>"
|
|
122
|
-
options={{ apiValidationErrors }}
|
|
123
|
-
/>
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
await act(async () => {
|
|
127
|
-
jest.advanceTimersByTime(500);
|
|
128
|
-
await Promise.resolve();
|
|
129
|
-
await Promise.resolve();
|
|
130
|
-
await Promise.resolve();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// API errors should be included in getAllIssues
|
|
134
|
-
const standardCount = parseInt(screen.getByTestId('standard-errors-count').textContent, 10);
|
|
135
|
-
const allCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
136
|
-
expect(standardCount).toBeGreaterThanOrEqual(2);
|
|
137
|
-
expect(allCount).toBeGreaterThanOrEqual(2);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('includes both liquid and standard API errors', async () => {
|
|
141
|
-
const apiValidationErrors = {
|
|
142
|
-
liquidErrors: ['Liquid error'],
|
|
143
|
-
standardErrors: ['Standard error'],
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
render(
|
|
147
|
-
<TestComponent
|
|
148
|
-
content="<p>Test</p>"
|
|
149
|
-
options={{ apiValidationErrors }}
|
|
150
|
-
/>
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
await act(async () => {
|
|
154
|
-
jest.advanceTimersByTime(500);
|
|
155
|
-
await Promise.resolve();
|
|
156
|
-
await Promise.resolve();
|
|
157
|
-
await Promise.resolve();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// API errors should be included in getAllIssues
|
|
161
|
-
const liquidCount = parseInt(screen.getByTestId('liquid-errors-count').textContent, 10);
|
|
162
|
-
const standardCount = parseInt(screen.getByTestId('standard-errors-count').textContent, 10);
|
|
163
|
-
const allCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
164
|
-
expect(liquidCount).toBeGreaterThanOrEqual(1);
|
|
165
|
-
expect(standardCount).toBeGreaterThanOrEqual(1);
|
|
166
|
-
expect(allCount).toBeGreaterThanOrEqual(2);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('extracts line numbers from API error messages', async () => {
|
|
170
|
-
const apiValidationErrors = {
|
|
171
|
-
liquidErrors: ['Error at line 10: Invalid syntax'],
|
|
172
|
-
standardErrors: ['Error at line 5: Missing tag'],
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
render(
|
|
176
|
-
<TestComponent
|
|
177
|
-
content="<p>Test</p>"
|
|
178
|
-
options={{ apiValidationErrors }}
|
|
179
|
-
/>
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
await act(async () => {
|
|
183
|
-
jest.advanceTimersByTime(500);
|
|
184
|
-
await Promise.resolve();
|
|
185
|
-
await Promise.resolve();
|
|
186
|
-
await Promise.resolve();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
const allIssues = screen.getByTestId('all-issues-count');
|
|
190
|
-
expect(allIssues).toBeInTheDocument();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('handles API errors with no line numbers', async () => {
|
|
194
|
-
const apiValidationErrors = {
|
|
195
|
-
liquidErrors: ['General liquid error'],
|
|
196
|
-
standardErrors: ['General standard error'],
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
render(
|
|
200
|
-
<TestComponent
|
|
201
|
-
content="<p>Test</p>"
|
|
202
|
-
options={{ apiValidationErrors }}
|
|
203
|
-
/>
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
await act(async () => {
|
|
207
|
-
jest.advanceTimersByTime(500);
|
|
208
|
-
await Promise.resolve();
|
|
209
|
-
await Promise.resolve();
|
|
210
|
-
await Promise.resolve();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// Should include at least the 2 API errors
|
|
214
|
-
const allCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
215
|
-
expect(allCount).toBeGreaterThanOrEqual(2);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('sets correct source for liquid API errors', async () => {
|
|
219
|
-
const apiValidationErrors = {
|
|
220
|
-
liquidErrors: ['Liquid error'],
|
|
221
|
-
standardErrors: [],
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
render(
|
|
225
|
-
<TestComponent
|
|
226
|
-
content="<p>Test</p>"
|
|
227
|
-
options={{ apiValidationErrors }}
|
|
228
|
-
/>
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
await act(async () => {
|
|
232
|
-
jest.advanceTimersByTime(500);
|
|
233
|
-
await Promise.resolve();
|
|
234
|
-
await Promise.resolve();
|
|
235
|
-
await Promise.resolve();
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
// Liquid errors should have source 'liquid-validator'
|
|
239
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it('sets correct source for standard API errors', async () => {
|
|
243
|
-
const apiValidationErrors = {
|
|
244
|
-
liquidErrors: [],
|
|
245
|
-
standardErrors: ['Standard error'],
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
render(
|
|
249
|
-
<TestComponent
|
|
250
|
-
content="<p>Test</p>"
|
|
251
|
-
options={{ apiValidationErrors }}
|
|
252
|
-
/>
|
|
253
|
-
);
|
|
254
|
-
|
|
255
|
-
await act(async () => {
|
|
256
|
-
jest.advanceTimersByTime(500);
|
|
257
|
-
await Promise.resolve();
|
|
258
|
-
await Promise.resolve();
|
|
259
|
-
await Promise.resolve();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// Standard errors should have source 'api-validator'
|
|
263
|
-
expect(screen.getByTestId('standard-errors-count')).toHaveTextContent('1');
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
describe('API Errors with hasErrors', () => {
|
|
268
|
-
it('sets hasErrors to true when API errors exist', async () => {
|
|
269
|
-
const apiValidationErrors = {
|
|
270
|
-
liquidErrors: ['Liquid error'],
|
|
271
|
-
standardErrors: [],
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
render(
|
|
275
|
-
<TestComponent
|
|
276
|
-
content="<p>Test</p>"
|
|
277
|
-
options={{ apiValidationErrors }}
|
|
278
|
-
/>
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
await act(async () => {
|
|
282
|
-
jest.advanceTimersByTime(500);
|
|
283
|
-
await Promise.resolve();
|
|
284
|
-
await Promise.resolve();
|
|
285
|
-
await Promise.resolve();
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// hasErrors should be true when API errors exist
|
|
289
|
-
expect(screen.getByTestId('has-errors')).toHaveTextContent('true');
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('sets hasErrors to false when no API errors and no validation errors', async () => {
|
|
293
|
-
const apiValidationErrors = {
|
|
294
|
-
liquidErrors: [],
|
|
295
|
-
standardErrors: [],
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
render(
|
|
299
|
-
<TestComponent
|
|
300
|
-
content="<p>Test</p>"
|
|
301
|
-
options={{ apiValidationErrors }}
|
|
302
|
-
/>
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
await act(async () => {
|
|
306
|
-
jest.advanceTimersByTime(500);
|
|
307
|
-
await Promise.resolve();
|
|
308
|
-
await Promise.resolve();
|
|
309
|
-
await Promise.resolve();
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
// hasErrors should be false when no API errors and no validation errors
|
|
313
|
-
// Note: This might be true if validation finds errors, so we check the condition
|
|
314
|
-
const allIssuesCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
315
|
-
// If there are no issues, hasErrors should be false
|
|
316
|
-
if (allIssuesCount === 0) {
|
|
317
|
-
expect(screen.getByTestId('has-errors')).toHaveTextContent('false');
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
describe('API Errors with isClean', () => {
|
|
323
|
-
it('returns false when API errors exist', async () => {
|
|
324
|
-
const apiValidationErrors = {
|
|
325
|
-
liquidErrors: ['Liquid error'],
|
|
326
|
-
standardErrors: [],
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
render(
|
|
330
|
-
<TestComponent
|
|
331
|
-
content="<p>Test</p>"
|
|
332
|
-
options={{ apiValidationErrors }}
|
|
333
|
-
/>
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
await act(async () => {
|
|
337
|
-
jest.advanceTimersByTime(500);
|
|
338
|
-
await Promise.resolve();
|
|
339
|
-
await Promise.resolve();
|
|
340
|
-
await Promise.resolve();
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
// isClean should be false when API errors exist
|
|
344
|
-
expect(screen.getByTestId('is-clean')).toHaveTextContent('false');
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it('returns true when no API errors and no other issues', async () => {
|
|
348
|
-
const apiValidationErrors = {
|
|
349
|
-
liquidErrors: [],
|
|
350
|
-
standardErrors: [],
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
render(
|
|
354
|
-
<TestComponent
|
|
355
|
-
content="<p>Test</p>"
|
|
356
|
-
options={{ apiValidationErrors }}
|
|
357
|
-
/>
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
await act(async () => {
|
|
361
|
-
jest.advanceTimersByTime(500);
|
|
362
|
-
await Promise.resolve();
|
|
363
|
-
await Promise.resolve();
|
|
364
|
-
await Promise.resolve();
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
// isClean should be true when no API errors and no validation issues
|
|
368
|
-
// Note: This might be false if validation finds issues, so we check the condition
|
|
369
|
-
const allIssuesCount = parseInt(screen.getByTestId('all-issues-count').textContent, 10);
|
|
370
|
-
if (allIssuesCount === 0) {
|
|
371
|
-
expect(screen.getByTestId('is-clean')).toHaveTextContent('true');
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
describe('API Errors Edge Cases', () => {
|
|
377
|
-
it('handles null apiValidationErrors', async () => {
|
|
378
|
-
render(
|
|
379
|
-
<TestComponent
|
|
380
|
-
content="<p>Test</p>"
|
|
381
|
-
options={{ apiValidationErrors: null }}
|
|
382
|
-
/>
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
await act(async () => {
|
|
386
|
-
jest.advanceTimersByTime(500);
|
|
387
|
-
await Promise.resolve();
|
|
388
|
-
await Promise.resolve();
|
|
389
|
-
await Promise.resolve();
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
// Should not include API errors when null
|
|
393
|
-
const liquidCount = parseInt(screen.getByTestId('liquid-errors-count').textContent, 10);
|
|
394
|
-
const standardCount = parseInt(screen.getByTestId('standard-errors-count').textContent, 10);
|
|
395
|
-
expect(liquidCount).toBe(0);
|
|
396
|
-
expect(standardCount).toBe(0);
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it('handles undefined apiValidationErrors', async () => {
|
|
400
|
-
render(
|
|
401
|
-
<TestComponent
|
|
402
|
-
content="<p>Test</p>"
|
|
403
|
-
options={{ apiValidationErrors: undefined }}
|
|
404
|
-
/>
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
await act(async () => {
|
|
408
|
-
jest.advanceTimersByTime(500);
|
|
409
|
-
await Promise.resolve();
|
|
410
|
-
await Promise.resolve();
|
|
411
|
-
await Promise.resolve();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
// Should not include API errors when undefined
|
|
415
|
-
const liquidCount = parseInt(screen.getByTestId('liquid-errors-count').textContent, 10);
|
|
416
|
-
const standardCount = parseInt(screen.getByTestId('standard-errors-count').textContent, 10);
|
|
417
|
-
expect(liquidCount).toBe(0);
|
|
418
|
-
expect(standardCount).toBe(0);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('handles empty liquidErrors array', async () => {
|
|
422
|
-
const apiValidationErrors = {
|
|
423
|
-
liquidErrors: [],
|
|
424
|
-
standardErrors: ['Standard error'],
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
render(
|
|
428
|
-
<TestComponent
|
|
429
|
-
content="<p>Test</p>"
|
|
430
|
-
options={{ apiValidationErrors }}
|
|
431
|
-
/>
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
await act(async () => {
|
|
435
|
-
jest.advanceTimersByTime(500);
|
|
436
|
-
await Promise.resolve();
|
|
437
|
-
await Promise.resolve();
|
|
438
|
-
await Promise.resolve();
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('0');
|
|
442
|
-
expect(screen.getByTestId('standard-errors-count')).toHaveTextContent('1');
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it('handles empty standardErrors array', async () => {
|
|
446
|
-
const apiValidationErrors = {
|
|
447
|
-
liquidErrors: ['Liquid error'],
|
|
448
|
-
standardErrors: [],
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
render(
|
|
452
|
-
<TestComponent
|
|
453
|
-
content="<p>Test</p>"
|
|
454
|
-
options={{ apiValidationErrors }}
|
|
455
|
-
/>
|
|
456
|
-
);
|
|
457
|
-
|
|
458
|
-
await act(async () => {
|
|
459
|
-
jest.advanceTimersByTime(500);
|
|
460
|
-
await Promise.resolve();
|
|
461
|
-
await Promise.resolve();
|
|
462
|
-
await Promise.resolve();
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
466
|
-
expect(screen.getByTestId('standard-errors-count')).toHaveTextContent('0');
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it('handles missing liquidErrors property', async () => {
|
|
470
|
-
const apiValidationErrors = {
|
|
471
|
-
standardErrors: ['Standard error'],
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
render(
|
|
475
|
-
<TestComponent
|
|
476
|
-
content="<p>Test</p>"
|
|
477
|
-
options={{ apiValidationErrors }}
|
|
478
|
-
/>
|
|
479
|
-
);
|
|
480
|
-
|
|
481
|
-
await act(async () => {
|
|
482
|
-
jest.advanceTimersByTime(500);
|
|
483
|
-
await Promise.resolve();
|
|
484
|
-
await Promise.resolve();
|
|
485
|
-
await Promise.resolve();
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('0');
|
|
489
|
-
expect(screen.getByTestId('standard-errors-count')).toHaveTextContent('1');
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('handles missing standardErrors property', async () => {
|
|
493
|
-
const apiValidationErrors = {
|
|
494
|
-
liquidErrors: ['Liquid error'],
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
render(
|
|
498
|
-
<TestComponent
|
|
499
|
-
content="<p>Test</p>"
|
|
500
|
-
options={{ apiValidationErrors }}
|
|
501
|
-
/>
|
|
502
|
-
);
|
|
503
|
-
|
|
504
|
-
await act(async () => {
|
|
505
|
-
jest.advanceTimersByTime(500);
|
|
506
|
-
await Promise.resolve();
|
|
507
|
-
await Promise.resolve();
|
|
508
|
-
await Promise.resolve();
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
512
|
-
expect(screen.getByTestId('standard-errors-count')).toHaveTextContent('0');
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
describe('Line Number Extraction', () => {
|
|
517
|
-
it('extracts line number from error message with "Line X" pattern', async () => {
|
|
518
|
-
const apiValidationErrors = {
|
|
519
|
-
liquidErrors: ['Error message Line 15'],
|
|
520
|
-
standardErrors: [],
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
render(
|
|
524
|
-
<TestComponent
|
|
525
|
-
content="<p>Test</p>"
|
|
526
|
-
options={{ apiValidationErrors }}
|
|
527
|
-
/>
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
await act(async () => {
|
|
531
|
-
jest.advanceTimersByTime(500);
|
|
532
|
-
await Promise.resolve();
|
|
533
|
-
await Promise.resolve();
|
|
534
|
-
await Promise.resolve();
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
// Line number should be extracted
|
|
538
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
it('extracts line number from error message with "line X" pattern', async () => {
|
|
542
|
-
const apiValidationErrors = {
|
|
543
|
-
liquidErrors: ['Error message line 20'],
|
|
544
|
-
standardErrors: [],
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
render(
|
|
548
|
-
<TestComponent
|
|
549
|
-
content="<p>Test</p>"
|
|
550
|
-
options={{ apiValidationErrors }}
|
|
551
|
-
/>
|
|
552
|
-
);
|
|
553
|
-
|
|
554
|
-
await act(async () => {
|
|
555
|
-
jest.advanceTimersByTime(500);
|
|
556
|
-
await Promise.resolve();
|
|
557
|
-
await Promise.resolve();
|
|
558
|
-
await Promise.resolve();
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
it('handles error messages without line numbers', async () => {
|
|
565
|
-
const apiValidationErrors = {
|
|
566
|
-
liquidErrors: ['General error message'],
|
|
567
|
-
standardErrors: [],
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
render(
|
|
571
|
-
<TestComponent
|
|
572
|
-
content="<p>Test</p>"
|
|
573
|
-
options={{ apiValidationErrors }}
|
|
574
|
-
/>
|
|
575
|
-
);
|
|
576
|
-
|
|
577
|
-
await act(async () => {
|
|
578
|
-
jest.advanceTimersByTime(500);
|
|
579
|
-
await Promise.resolve();
|
|
580
|
-
await Promise.resolve();
|
|
581
|
-
await Promise.resolve();
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
expect(screen.getByTestId('liquid-errors-count')).toHaveTextContent('1');
|
|
585
|
-
});
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
describe('API Errors Sorting', () => {
|
|
589
|
-
it('sorts API errors with other validation issues', async () => {
|
|
590
|
-
const { validateHTML } = require('../../utils/htmlValidator');
|
|
591
|
-
validateHTML.mockReturnValueOnce({
|
|
592
|
-
isValid: false,
|
|
593
|
-
errors: [{
|
|
594
|
-
type: 'error',
|
|
595
|
-
message: 'HTML error',
|
|
596
|
-
line: 1,
|
|
597
|
-
column: 1,
|
|
598
|
-
rule: 'html-error',
|
|
599
|
-
severity: 'error',
|
|
600
|
-
source: 'htmlhint',
|
|
601
|
-
}],
|
|
602
|
-
warnings: [],
|
|
603
|
-
info: [],
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
const apiValidationErrors = {
|
|
607
|
-
liquidErrors: ['Liquid error'],
|
|
608
|
-
standardErrors: [],
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
render(
|
|
612
|
-
<TestComponent
|
|
613
|
-
content="<p>error</p>"
|
|
614
|
-
options={{ apiValidationErrors }}
|
|
615
|
-
/>
|
|
616
|
-
);
|
|
617
|
-
|
|
618
|
-
await act(async () => {
|
|
619
|
-
jest.advanceTimersByTime(500);
|
|
620
|
-
await Promise.resolve();
|
|
621
|
-
await Promise.resolve();
|
|
622
|
-
await Promise.resolve();
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// Should have both HTML error and API error
|
|
626
|
-
expect(screen.getByTestId('all-issues-count')).toHaveTextContent('2');
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
describe('getLineNumberForApiError helper functions', () => {
|
|
631
|
-
it('should extract line number from error message with "line X" pattern', () => {
|
|
632
|
-
const content = '<p>Line 1</p>\n<p>Line 2</p>\n<p>Line 3</p>';
|
|
633
|
-
const apiValidationErrors = {
|
|
634
|
-
liquidErrors: ['Error at line 2'],
|
|
635
|
-
standardErrors: [],
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
render(
|
|
639
|
-
<TestComponent
|
|
640
|
-
content={content}
|
|
641
|
-
options={{ apiValidationErrors }}
|
|
642
|
-
/>
|
|
643
|
-
);
|
|
644
|
-
|
|
645
|
-
// The getLineNumberForApiError should extract line 2 from the error message
|
|
646
|
-
// This is tested indirectly through the error processing
|
|
647
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
it('should extract line number from error message with "Line: X" pattern', () => {
|
|
651
|
-
const content = '<p>Line 1</p>\n<p>Line 2</p>';
|
|
652
|
-
const apiValidationErrors = {
|
|
653
|
-
liquidErrors: ['Error at Line: 2'],
|
|
654
|
-
standardErrors: [],
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
render(
|
|
658
|
-
<TestComponent
|
|
659
|
-
content={content}
|
|
660
|
-
options={{ apiValidationErrors }}
|
|
661
|
-
/>
|
|
662
|
-
);
|
|
663
|
-
|
|
664
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
it('should find tag in content using {{ tagName }} pattern', () => {
|
|
668
|
-
const content = '<p>Line 1</p>\n<p>{{ customer.name }}</p>\n<p>Line 3</p>';
|
|
669
|
-
const apiValidationErrors = {
|
|
670
|
-
liquidErrors: ['Unsupported tags: customer.name'],
|
|
671
|
-
standardErrors: [],
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
render(
|
|
675
|
-
<TestComponent
|
|
676
|
-
content={content}
|
|
677
|
-
options={{ apiValidationErrors }}
|
|
678
|
-
/>
|
|
679
|
-
);
|
|
680
|
-
|
|
681
|
-
// Should find the tag and extract line number
|
|
682
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it('should find tag in content using {% %} pattern', () => {
|
|
686
|
-
const content = '<p>Line 1</p>\n{% assign x = customer.name %}\n<p>Line 3</p>';
|
|
687
|
-
const apiValidationErrors = {
|
|
688
|
-
liquidErrors: ['Unsupported tags: customer.name'],
|
|
689
|
-
standardErrors: [],
|
|
690
|
-
};
|
|
691
|
-
|
|
692
|
-
render(
|
|
693
|
-
<TestComponent
|
|
694
|
-
content={content}
|
|
695
|
-
options={{ apiValidationErrors }}
|
|
696
|
-
/>
|
|
697
|
-
);
|
|
698
|
-
|
|
699
|
-
// Should find the tag in liquid syntax
|
|
700
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
701
|
-
});
|
|
702
|
-
|
|
703
|
-
it('should handle tag name with special characters', () => {
|
|
704
|
-
const content = '<p>{{ customer.name.first }}</p>';
|
|
705
|
-
const apiValidationErrors = {
|
|
706
|
-
liquidErrors: ['Unsupported tags: customer.name.first'],
|
|
707
|
-
standardErrors: [],
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
render(
|
|
711
|
-
<TestComponent
|
|
712
|
-
content={content}
|
|
713
|
-
options={{ apiValidationErrors }}
|
|
714
|
-
/>
|
|
715
|
-
);
|
|
716
|
-
|
|
717
|
-
// Should escape special characters in tag name
|
|
718
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
it('should return null when tag is not found in content', () => {
|
|
722
|
-
const content = '<p>No tags here</p>';
|
|
723
|
-
const apiValidationErrors = {
|
|
724
|
-
liquidErrors: ['Unsupported tags: missing.tag'],
|
|
725
|
-
standardErrors: [],
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
render(
|
|
729
|
-
<TestComponent
|
|
730
|
-
content={content}
|
|
731
|
-
options={{ apiValidationErrors }}
|
|
732
|
-
/>
|
|
733
|
-
);
|
|
734
|
-
|
|
735
|
-
// Should still process the error even if tag is not found
|
|
736
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
737
|
-
});
|
|
738
|
-
|
|
739
|
-
it('should handle getLineNumberFromPosition edge cases', () => {
|
|
740
|
-
// Test that helper functions handle edge cases gracefully
|
|
741
|
-
// These are tested indirectly through error processing
|
|
742
|
-
const content = '<p>Content</p>';
|
|
743
|
-
const apiValidationErrors = {
|
|
744
|
-
liquidErrors: ['Error message'],
|
|
745
|
-
standardErrors: [],
|
|
746
|
-
};
|
|
747
|
-
|
|
748
|
-
render(
|
|
749
|
-
<TestComponent
|
|
750
|
-
content={content}
|
|
751
|
-
options={{ apiValidationErrors }}
|
|
752
|
-
/>
|
|
753
|
-
);
|
|
754
|
-
|
|
755
|
-
// Component should render and process errors without crashing
|
|
756
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
it('should handle findLineNumberForTag with null content', () => {
|
|
760
|
-
const apiValidationErrors = {
|
|
761
|
-
liquidErrors: ['Unsupported tags: test.tag'],
|
|
762
|
-
standardErrors: [],
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
render(
|
|
766
|
-
<TestComponent
|
|
767
|
-
content=""
|
|
768
|
-
options={{ apiValidationErrors }}
|
|
769
|
-
/>
|
|
770
|
-
);
|
|
771
|
-
|
|
772
|
-
// Should handle gracefully when content is empty
|
|
773
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
it('should handle findLineNumberForTag with null tagName', () => {
|
|
777
|
-
const content = '<p>Content</p>';
|
|
778
|
-
const apiValidationErrors = {
|
|
779
|
-
liquidErrors: ['Error without tag name'],
|
|
780
|
-
standardErrors: [],
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
render(
|
|
784
|
-
<TestComponent
|
|
785
|
-
content={content}
|
|
786
|
-
options={{ apiValidationErrors }}
|
|
787
|
-
/>
|
|
788
|
-
);
|
|
789
|
-
|
|
790
|
-
// Should handle gracefully when tag name cannot be extracted
|
|
791
|
-
expect(screen.getByTestId('all-issues-count')).toBeInTheDocument();
|
|
792
|
-
});
|
|
793
|
-
});
|
|
794
|
-
});
|