UNPKG

@zendesk/retrace

Version:

define and capture Product Operation Traces along with computed metrics with an optional friendly React beacon API

59 lines 3.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const trace_flon2op03qt_ticket_activated_json_1 = __importDefault(require("./__fixtures__/trace-flon2op03qt-ticket.activated.json")); const mapOperationForVisualization_1 = require("./mapOperationForVisualization"); const buildSpanHierarchy_1 = require("./utils/buildSpanHierarchy"); (0, vitest_1.describe)('Phase 1.3 Hierarchical Integration', () => { (0, vitest_1.it)('should create hierarchical operation from trace data', () => { const hierarchicalOperation = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default); (0, vitest_1.expect)(hierarchicalOperation).not.toBeNull(); (0, vitest_1.expect)(hierarchicalOperation).toHaveProperty('expandedSpanIds'); (0, vitest_1.expect)(hierarchicalOperation.expandedSpanIds).toBeInstanceOf(Set); (0, vitest_1.expect)(hierarchicalOperation.spans).toBeInstanceOf(Array); // Verify that spans have hierarchical properties if (hierarchicalOperation.spans.length > 0) { const firstSpan = hierarchicalOperation.spans[0]; (0, vitest_1.expect)(firstSpan).toHaveProperty('children'); (0, vitest_1.expect)(firstSpan).toHaveProperty('isExpanded'); (0, vitest_1.expect)(firstSpan).toHaveProperty('depth'); (0, vitest_1.expect)(firstSpan.children).toBeInstanceOf(Array); (0, vitest_1.expect)(typeof firstSpan.isExpanded).toBe('boolean'); (0, vitest_1.expect)(typeof firstSpan.depth).toBe('number'); } }); (0, vitest_1.it)('should flatten hierarchical spans correctly with no expansion', () => { const hierarchicalOperation = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default); (0, vitest_1.expect)(hierarchicalOperation).not.toBeNull(); // With no expanded spans, should only show root level spans const flattenedSpans = (0, buildSpanHierarchy_1.flattenHierarchicalSpans)(hierarchicalOperation.spans, new Set()); // All flattened spans should have depth 0 (root level) flattenedSpans.forEach((span) => { (0, vitest_1.expect)(span.depth).toBe(0); }); }); (0, vitest_1.it)('should expand children when parent is expanded', () => { const hierarchicalOperation = (0, mapOperationForVisualization_1.mapOperationForVisualizationHierarchical)(trace_flon2op03qt_ticket_activated_json_1.default); (0, vitest_1.expect)(hierarchicalOperation).not.toBeNull(); // Find a span with children const spanWithChildren = hierarchicalOperation.spans.find((span) => span.children.length > 0); if (spanWithChildren) { // Expand this span const expandedIds = new Set([spanWithChildren.span.id]); const flattenedSpans = (0, buildSpanHierarchy_1.flattenHierarchicalSpans)(hierarchicalOperation.spans, expandedIds); // Should include the parent and its children const parentSpan = flattenedSpans.find((s) => s.span.id === spanWithChildren.span.id); const childSpans = flattenedSpans.filter((s) => s.depth === 1); (0, vitest_1.expect)(parentSpan).toBeDefined(); (0, vitest_1.expect)(childSpans.length).toBeGreaterThan(0); // Verify child spans have correct depth childSpans.forEach((child) => { (0, vitest_1.expect)(child.depth).toBe(1); }); } }); }); //# sourceMappingURL=integration.test.js.map