Skip to content

Commit 2a6c8f5

Browse files
committed
feat: timeout done
1 parent b8f5308 commit 2a6c8f5

5 files changed

Lines changed: 133 additions & 44 deletions

File tree

src/visualBuilder/__test__/hover/fields/all-hover.test.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,40 @@ vi.mock("../../../utils/visualBuilderPostMessage", async () => {
4545
return Promise.resolve({
4646
contentTypes,
4747
});
48-
return Promise.resolve();
48+
// Resolve all other calls immediately to avoid async delays
49+
return Promise.resolve({});
4950
}),
5051
},
5152
};
5253
});
5354

55+
// Mock fetchEntryPermissionsAndStageDetails to resolve immediately - this is called during hover
56+
// and causes delays for html-rte, json-rte, link, and other fields
57+
vi.mock("../../../utils/fetchEntryPermissionsAndStageDetails", () => ({
58+
fetchEntryPermissionsAndStageDetails: vi.fn().mockResolvedValue({
59+
acl: {
60+
update: {
61+
create: true,
62+
read: true,
63+
update: true,
64+
delete: true,
65+
publish: true,
66+
},
67+
},
68+
workflowStage: {
69+
stage: undefined,
70+
permissions: {
71+
entry: {
72+
update: true,
73+
},
74+
},
75+
},
76+
resolvedVariantPermissions: {
77+
update: true,
78+
},
79+
}),
80+
}));
81+
5482
// Mock waitForHoverOutline to wait for outline with optimized timeout
5583
// This speeds up tests while still ensuring the outline is actually present
5684
vi.mock("../../../../__test__/utils", async () => {
@@ -72,7 +100,7 @@ vi.mock("../../../../__test__/utils", async () => {
72100
throw new Error("Hover outline not found");
73101
}
74102
},
75-
{ timeout: 5000, interval: 50 } // Faster polling, shorter timeout for tests
103+
{ timeout: 2000, interval: 10 } // Optimized: reduced from 5s/50ms to 2s/10ms
76104
);
77105
}),
78106
};
@@ -165,12 +193,15 @@ const MULTIPLE_FIELD_TYPES = [
165193

166194
describe("When an element is hovered in visual builder mode", () => {
167195
let mousemoveEvent: Event;
196+
const fieldSchemaMap = getFieldSchemaMap().all_fields;
168197

169198
beforeAll(() => {
170-
FieldSchemaMap.setFieldSchema(
171-
"all_fields",
172-
getFieldSchemaMap().all_fields
173-
);
199+
// Pre-set all field schemas in cache to avoid async fetches during hover
200+
// This significantly speeds up tests, especially for html-rte, json-rte, link fields
201+
FieldSchemaMap.setFieldSchema("all_fields", fieldSchemaMap);
202+
203+
// Field schemas are already set above - no need for additional caching
204+
// The FieldSchemaMap.setFieldSchema call above sets all fields at once
174205
});
175206

176207
beforeEach(() => {
@@ -220,15 +251,15 @@ describe("When an element is hovered in visual builder mode", () => {
220251
);
221252
expect(hoverOutline).toHaveAttribute("style");
222253

223-
// Wait for cursor icon to be set (not "loading")
254+
// Wait for cursor icon to be set (not "loading") - reduced timeout and faster polling
224255
await waitFor(
225256
() => {
226257
const customCursor = document.querySelector(
227258
`[data-testid="visual-builder__cursor"]`
228259
);
229260
expect(customCursor).toHaveAttribute("data-icon", icon);
230261
},
231-
{ timeout: 5000, interval: 50 }
262+
{ timeout: 2000, interval: 10 } // Reduced from 5s/50ms to 2s/10ms for faster tests
232263
);
233264

234265
const customCursor = document.querySelector(
@@ -273,15 +304,15 @@ describe("When an element is hovered in visual builder mode", () => {
273304
);
274305
expect(hoverOutline).toHaveAttribute("style");
275306

276-
// Wait for cursor icon to be set (not "loading")
307+
// Wait for cursor icon to be set (not "loading") - reduced timeout and faster polling
277308
await waitFor(
278309
() => {
279310
const customCursor = document.querySelector(
280311
`[data-testid="visual-builder__cursor"]`
281312
);
282313
expect(customCursor).toHaveAttribute("data-icon", icon);
283314
},
284-
{ timeout: 5000, interval: 50 }
315+
{ timeout: 2000, interval: 10 } // Reduced from 5s/50ms to 2s/10ms for faster tests
285316
);
286317

287318
const customCursor = document.querySelector(
@@ -389,7 +420,7 @@ describe("When an element is hovered in visual builder mode", () => {
389420
expect(
390421
customCursor?.classList.contains("visible")
391422
).toBeTruthy();
392-
}, 60000);
423+
});
393424
}
394425
);
395426
});

src/visualBuilder/__test__/hover/fields/file.test.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ vi.mock("../../../../__test__/utils", async () => {
4747
throw new Error("Hover outline not found");
4848
}
4949
},
50-
{ timeout: 5000, interval: 50 } // Faster polling, shorter timeout for tests
50+
{ timeout: 2000, interval: 10 } // Optimized: reduced from 5s/50ms to 2s/10ms
5151
);
5252
}),
5353
};
@@ -62,21 +62,43 @@ vi.mock("../../../../utils/index.ts", async () => {
6262
};
6363
});
6464

65+
// Mock fetchEntryPermissionsAndStageDetails to resolve immediately - speeds up hover tests
66+
vi.mock("../../../utils/fetchEntryPermissionsAndStageDetails", () => ({
67+
fetchEntryPermissionsAndStageDetails: vi.fn().mockResolvedValue({
68+
acl: {
69+
update: {
70+
create: true,
71+
read: true,
72+
update: true,
73+
delete: true,
74+
publish: true,
75+
},
76+
},
77+
workflowStage: {
78+
stage: undefined,
79+
permissions: {
80+
entry: {
81+
update: true,
82+
},
83+
},
84+
},
85+
resolvedVariantPermissions: {
86+
update: true,
87+
},
88+
}),
89+
}));
90+
6591
const convertToPx = (value: number) => {
6692
return `${value}px`;
6793
};
6894
const matchDimensions = (element: HTMLElement, hoverOutline: HTMLElement) => {
6995
const elementDimensions = element.getBoundingClientRect();
70-
// @ts-expect-error - TS doesn't know that style is a CSSStyleDeclaration
71-
const hoverOutlineDimensions = hoverOutline?.style
72-
?._values as CSSStyleDeclaration;
73-
expect(convertToPx(elementDimensions.x)).toBe(hoverOutlineDimensions.left);
74-
expect(convertToPx(elementDimensions.y)).toBe(hoverOutlineDimensions.top);
75-
expect(convertToPx(elementDimensions.width)).toBe(
76-
hoverOutlineDimensions.width
77-
);
96+
const hoverOutlineStyle = hoverOutline?.style as CSSStyleDeclaration;
97+
expect(convertToPx(elementDimensions.x)).toBe(hoverOutlineStyle.left);
98+
expect(convertToPx(elementDimensions.y)).toBe(hoverOutlineStyle.top);
99+
expect(convertToPx(elementDimensions.width)).toBe(hoverOutlineStyle.width);
78100
expect(convertToPx(elementDimensions.height)).toBe(
79-
hoverOutlineDimensions.height
101+
hoverOutlineStyle.height
80102
);
81103
};
82104
describe("When an element is hovered in visual builder mode", () => {
@@ -174,10 +196,21 @@ describe("When an element is hovered in visual builder mode", () => {
174196
);
175197
expect(hoverOutline).toHaveAttribute("style");
176198

199+
// Wait for cursor icon to be set (not "loading") - optimized timeout
200+
const { waitFor } = await import("@testing-library/preact");
201+
await waitFor(
202+
() => {
203+
const customCursor = document.querySelector(
204+
`[data-testid="visual-builder__cursor"]`
205+
);
206+
expect(customCursor).toHaveAttribute("data-icon", "file");
207+
},
208+
{ timeout: 2000, interval: 10 } // Optimized: reduced timeout and faster polling
209+
);
210+
177211
const customCursor = document.querySelector(
178212
`[data-testid="visual-builder__cursor"]`
179213
);
180-
181214
expect(customCursor).toHaveAttribute("data-icon", "file");
182215
expect(customCursor?.classList.contains("visible")).toBeTruthy();
183216
});

src/visualBuilder/__test__/hover/fields/group.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ vi.mock("../../../../__test__/utils", async () => {
4646
throw new Error("Hover outline not found");
4747
}
4848
},
49-
{ timeout: 5000, interval: 50 } // Faster polling, shorter timeout for tests
49+
{ timeout: 2000, interval: 10 } // Optimized: reduced from 5s/50ms to 2s/10ms
5050
);
5151
}),
5252
};
@@ -139,10 +139,21 @@ describe("When an element is hovered in visual builder mode", () => {
139139
);
140140
expect(hoverOutline).toHaveAttribute("style");
141141

142+
// Wait for cursor icon to be set (not "loading") - optimized timeout
143+
const { waitFor } = await import("@testing-library/preact");
144+
await waitFor(
145+
() => {
146+
const customCursor = document.querySelector(
147+
`[data-testid="visual-builder__cursor"]`
148+
);
149+
expect(customCursor).toHaveAttribute("data-icon", "group");
150+
},
151+
{ timeout: 2000, interval: 10 } // Optimized: reduced timeout and faster polling
152+
);
153+
142154
const customCursor = document.querySelector(
143155
`[data-testid="visual-builder__cursor"]`
144156
);
145-
146157
expect(customCursor).toHaveAttribute("data-icon", "group");
147158
expect(customCursor?.classList.contains("visible")).toBeTruthy();
148159
});
@@ -167,10 +178,24 @@ describe("When an element is hovered in visual builder mode", () => {
167178
);
168179
expect(hoverOutline).toHaveAttribute("style");
169180

181+
// Wait for cursor icon to be set (not "loading") - optimized timeout
182+
const { waitFor } = await import("@testing-library/preact");
183+
await waitFor(
184+
() => {
185+
const customCursor = document.querySelector(
186+
`[data-testid="visual-builder__cursor"]`
187+
);
188+
expect(customCursor).toHaveAttribute(
189+
"data-icon",
190+
"singleline"
191+
);
192+
},
193+
{ timeout: 2000, interval: 10 } // Optimized: reduced timeout and faster polling
194+
);
195+
170196
const customCursor = document.querySelector(
171197
`[data-testid="visual-builder__cursor"]`
172198
);
173-
174199
expect(customCursor).toHaveAttribute("data-icon", "singleline");
175200
expect(customCursor?.classList.contains("visible")).toBeTruthy();
176201
});

src/visualBuilder/components/__test__/fieldLabelWrapper.test.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe("FieldLabelWrapperComponent", () => {
320320
container as HTMLElement,
321321
DISPLAY_NAMES.mockFieldCslp,
322322
{},
323-
{ timeout: 10000, interval: 5 }
323+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
324324
);
325325
});
326326

@@ -339,7 +339,7 @@ describe("FieldLabelWrapperComponent", () => {
339339
container as HTMLElement,
340340
"visual-builder__field-icon",
341341
{},
342-
{ timeout: 10000, interval: 5 }
342+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
343343
);
344344
});
345345

@@ -362,7 +362,7 @@ describe("FieldLabelWrapperComponent", () => {
362362
container as HTMLElement,
363363
"visual-builder__focused-toolbar__field-label-wrapper",
364364
{},
365-
{ timeout: 10000, interval: 5 }
365+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
366366
)) as HTMLElement;
367367

368368
// Wait for disabled class to be applied with fast polling (5ms)
@@ -372,7 +372,7 @@ describe("FieldLabelWrapperComponent", () => {
372372
"visual-builder__focused-toolbar--field-disabled"
373373
);
374374
},
375-
{ timeout: 2000, interval: 5 }
375+
{ timeout: 1000, interval: 5 } // Reduced timeout from 2s to 1s
376376
);
377377
});
378378

@@ -391,15 +391,15 @@ describe("FieldLabelWrapperComponent", () => {
391391
container as HTMLElement,
392392
"visual-builder__focused-toolbar__field-label-wrapper",
393393
{},
394-
{ timeout: 10000, interval: 5 }
394+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
395395
);
396396

397397
// Wait for isFieldDisabled to be called with fast polling (5ms)
398398
await waitFor(
399399
() => {
400400
expect(isFieldDisabled).toHaveBeenCalled();
401401
},
402-
{ timeout: 2000, interval: 5 }
402+
{ timeout: 1000, interval: 5 } // Reduced timeout from 2s to 1s
403403
);
404404

405405
expect(isFieldDisabled).toHaveBeenCalledWith(
@@ -476,7 +476,7 @@ describe("FieldLabelWrapperComponent", () => {
476476
);
477477
expect(contentTypeIcon).not.toBeInTheDocument();
478478
},
479-
{ timeout: 5000 }
479+
{ timeout: 3000, interval: 5 } // Reduced timeout from 5s to 3s with faster polling
480480
);
481481
});
482482

@@ -501,7 +501,7 @@ describe("FieldLabelWrapperComponent", () => {
501501
const button = container.querySelector("button");
502502
expect(button).not.toBeDisabled();
503503
},
504-
{ timeout: 15000 }
504+
{ timeout: 5000, interval: 5 } // Reduced timeout from 15s to 5s with faster polling
505505
);
506506

507507
const variantIndicator = container.querySelector(
@@ -525,7 +525,7 @@ describe("FieldLabelWrapperComponent", () => {
525525
container as HTMLElement,
526526
"visual-builder__focused-toolbar__field-label-wrapper",
527527
{},
528-
{ timeout: 10000, interval: 5 }
528+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
529529
);
530530

531531
// Then check variant indicator is not present
@@ -558,7 +558,7 @@ describe("FieldLabelWrapperComponent", () => {
558558
);
559559
expect(fieldLabelWrapper).toBeInTheDocument();
560560
},
561-
{ timeout: 25000 }
561+
{ timeout: 5000, interval: 5 } // Reduced timeout from 25s to 5s with faster polling
562562
);
563563

564564
// Then check for variant class
@@ -571,7 +571,7 @@ describe("FieldLabelWrapperComponent", () => {
571571
"visual-builder__focused-toolbar--variant"
572572
);
573573
},
574-
{ timeout: 5000 }
574+
{ timeout: 2000, interval: 5 } // Reduced timeout from 5s to 2s with faster polling
575575
);
576576
});
577577

@@ -589,7 +589,7 @@ describe("FieldLabelWrapperComponent", () => {
589589
container as HTMLElement,
590590
"visual-builder__focused-toolbar__field-label-wrapper",
591591
{},
592-
{ timeout: 10000, interval: 5 }
592+
{ timeout: 5000, interval: 5 } // Reduced timeout from 10s to 5s
593593
)) as HTMLElement;
594594

595595
// Class should be set immediately, no need to wait

0 commit comments

Comments
 (0)