Skip to content

Commit d121dc8

Browse files
authored
de: Improve testing utils (#5647)
Migrate test files to testing utils, meaningfully improving the tests redability and making the test infra more cohesive.
1 parent de30af9 commit d121dc8

16 files changed

Lines changed: 1719 additions & 3319 deletions

ui/src/plugins/dev.perfetto.DataExplorer/query_builder/node_propagation_unittest.ts

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import {
2121
expectColumnNames,
2222
} from './testing/test_utils';
2323

24+
function makeAggNode(): AggregationNode {
25+
return new AggregationNode({groupByColumns: [], aggregations: []}, {});
26+
}
27+
2428
describe('Node Propagation', () => {
2529
describe('column rename propagation', () => {
2630
it('REGRESSION: should update AggregationNode when ModifyColumnsNode columns change', () => {
@@ -30,10 +34,7 @@ describe('Node Propagation', () => {
3034
// Setup: Source -> Modify -> Aggregation
3135
const sourceNode = createMockSourceNode();
3236
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
33-
const aggNode = new AggregationNode(
34-
{groupByColumns: [], aggregations: []},
35-
{},
36-
);
37+
const aggNode = makeAggNode();
3738

3839
// Connect the nodes
3940
connectNodes(sourceNode, modifyNode);
@@ -67,10 +68,7 @@ describe('Node Propagation', () => {
6768
// Setup: Source -> Modify -> Aggregation
6869
const sourceNode = createMockSourceNode();
6970
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
70-
const aggNode = new AggregationNode(
71-
{groupByColumns: [], aggregations: []},
72-
{},
73-
);
71+
const aggNode = makeAggNode();
7472

7573
// Connect the nodes
7674
connectNodes(sourceNode, modifyNode);
@@ -118,10 +116,7 @@ describe('Node Propagation', () => {
118116
// Setup: Source -> Modify -> Aggregation
119117
const sourceNode = createMockSourceNode();
120118
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
121-
const aggNode = new AggregationNode(
122-
{groupByColumns: [], aggregations: []},
123-
{},
124-
);
119+
const aggNode = makeAggNode();
125120

126121
// Connect the nodes
127122
connectNodes(sourceNode, modifyNode);
@@ -153,10 +148,7 @@ describe('Node Propagation', () => {
153148
// Setup: Source -> Modify -> Aggregation
154149
const sourceNode = createMockSourceNode();
155150
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
156-
const aggNode = new AggregationNode(
157-
{groupByColumns: [], aggregations: []},
158-
{},
159-
);
151+
const aggNode = makeAggNode();
160152

161153
// Connect the nodes
162154
connectNodes(sourceNode, modifyNode);
@@ -189,10 +181,7 @@ describe('Node Propagation', () => {
189181
// Setup: Source -> Modify -> Aggregation
190182
const sourceNode = createMockSourceNode();
191183
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
192-
const aggNode = new AggregationNode(
193-
{groupByColumns: [], aggregations: []},
194-
{},
195-
);
184+
const aggNode = makeAggNode();
196185

197186
// Connect the nodes
198187
connectNodes(sourceNode, modifyNode);
@@ -293,10 +282,7 @@ describe('Node Propagation', () => {
293282
// Setup: Source -> Modify1 -> Agg -> Modify2
294283
const sourceNode = createMockSourceNode();
295284
const modify1 = new ModifyColumnsNode({selectedColumns: []}, {});
296-
const aggNode = new AggregationNode(
297-
{groupByColumns: [], aggregations: []},
298-
{},
299-
);
285+
const aggNode = makeAggNode();
300286
const modify2 = new ModifyColumnsNode({selectedColumns: []}, {});
301287

302288
// Connect the nodes
@@ -422,10 +408,7 @@ describe('Node Propagation', () => {
422408
it('should be called on downstream nodes when upstream changes', () => {
423409
const sourceNode = createMockSourceNode();
424410
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
425-
const aggNode = new AggregationNode(
426-
{groupByColumns: [], aggregations: []},
427-
{},
428-
);
411+
const aggNode = makeAggNode();
429412

430413
// Connect the nodes
431414
connectNodes(sourceNode, modifyNode);
@@ -462,10 +445,7 @@ describe('Node Propagation', () => {
462445

463446
// Setup: Source -> Aggregation -> ModifyColumns
464447
const sourceNode = createMockSourceNode();
465-
const aggNode = new AggregationNode(
466-
{groupByColumns: [], aggregations: []},
467-
{},
468-
);
448+
const aggNode = makeAggNode();
469449
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
470450

471451
// Connect the nodes
@@ -523,10 +503,7 @@ describe('Node Propagation', () => {
523503
it('should propagate multiple aggregation column name changes', () => {
524504
// Setup: Source -> Aggregation -> ModifyColumns
525505
const sourceNode = createMockSourceNode();
526-
const aggNode = new AggregationNode(
527-
{groupByColumns: [], aggregations: []},
528-
{},
529-
);
506+
const aggNode = makeAggNode();
530507
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
531508

532509
// Connect the nodes
@@ -578,10 +555,7 @@ describe('Node Propagation', () => {
578555
it('should handle propagation through: Source -> Agg -> ModifyColumns1 -> ModifyColumns2', () => {
579556
// Setup: Source -> Aggregation -> Modify1 -> Modify2
580557
const sourceNode = createMockSourceNode();
581-
const aggNode = new AggregationNode(
582-
{groupByColumns: [], aggregations: []},
583-
{},
584-
);
558+
const aggNode = makeAggNode();
585559
const modify1 = new ModifyColumnsNode({selectedColumns: []}, {});
586560
const modify2 = new ModifyColumnsNode({selectedColumns: []}, {});
587561

@@ -619,10 +593,7 @@ describe('Node Propagation', () => {
619593
// This test requires FilterNode, but we'll use ModifyColumns as a proxy
620594
// to test the general propagation pattern
621595
const sourceNode = createMockSourceNode();
622-
const aggNode = new AggregationNode(
623-
{groupByColumns: [], aggregations: []},
624-
{},
625-
);
596+
const aggNode = makeAggNode();
626597
const middleNode = new ModifyColumnsNode({selectedColumns: []}, {});
627598
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
628599

@@ -656,14 +627,8 @@ describe('Node Propagation', () => {
656627

657628
it('should handle multiple stacked aggregations: Source -> Agg1 -> Agg2 -> ModifyColumns', () => {
658629
const sourceNode = createMockSourceNode();
659-
const agg1 = new AggregationNode(
660-
{groupByColumns: [], aggregations: []},
661-
{},
662-
);
663-
const agg2 = new AggregationNode(
664-
{groupByColumns: [], aggregations: []},
665-
{},
666-
);
630+
const agg1 = makeAggNode();
631+
const agg2 = makeAggNode();
667632
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
668633

669634
// Connect: Source -> Agg1 -> Agg2 -> ModifyColumns
@@ -725,10 +690,7 @@ describe('Node Propagation', () => {
725690
// it should NOT appear in the modify columns node below
726691

727692
const sourceNode = createMockSourceNode();
728-
const aggNode = new AggregationNode(
729-
{groupByColumns: [], aggregations: []},
730-
{},
731-
);
693+
const aggNode = makeAggNode();
732694
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
733695

734696
// Connect the nodes
@@ -776,10 +738,7 @@ describe('Node Propagation', () => {
776738
// it should appear in downstream nodes
777739

778740
const sourceNode = createMockSourceNode();
779-
const aggNode = new AggregationNode(
780-
{groupByColumns: [], aggregations: []},
781-
{},
782-
);
741+
const aggNode = makeAggNode();
783742
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
784743

785744
// Connect the nodes
@@ -821,10 +780,7 @@ describe('Node Propagation', () => {
821780
// When there are multiple aggregations, only valid ones should propagate
822781

823782
const sourceNode = createMockSourceNode();
824-
const aggNode = new AggregationNode(
825-
{groupByColumns: [], aggregations: []},
826-
{},
827-
);
783+
const aggNode = makeAggNode();
828784
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
829785

830786
// Connect the nodes
@@ -878,10 +834,7 @@ describe('Node Propagation', () => {
878834

879835
// Setup: Source -> Aggregation -> ModifyColumns
880836
const sourceNode = createMockSourceNode();
881-
const aggNode = new AggregationNode(
882-
{groupByColumns: [], aggregations: []},
883-
{},
884-
);
837+
const aggNode = makeAggNode();
885838
const modifyNode = new ModifyColumnsNode({selectedColumns: []}, {});
886839

887840
// Connect the nodes

ui/src/plugins/dev.perfetto.DataExplorer/query_builder/nodes/add_columns_node_unittest.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
import {AddColumnsNode, AddColumnsNodeAttrs} from './add_columns_node';
1616
import {QueryNode} from '../../query_node';
1717
import protos from '../../../../protos';
18-
import {createMockNode, createColumnInfo} from '../testing/test_utils';
18+
import {
19+
createMockNode,
20+
createColumnInfo,
21+
connectNodes,
22+
connectSecondary,
23+
} from '../testing/test_utils';
1924

2025
describe('AddColumnsNode', () => {
2126
function createMockPrimaryNode(): QueryNode {
@@ -64,15 +69,8 @@ describe('AddColumnsNode', () => {
6469
secondaryNode?: QueryNode,
6570
): AddColumnsNode {
6671
const node = new AddColumnsNode(state, {});
67-
if (primaryNode) {
68-
primaryNode.nextNodes.push(node);
69-
node.primaryInput = primaryNode;
70-
}
71-
if (secondaryNode) {
72-
// Set the secondary input connection at port 0
73-
secondaryNode.nextNodes.push(node);
74-
node.secondaryInputs.connections.set(0, secondaryNode);
75-
}
72+
if (primaryNode) connectNodes(primaryNode, node);
73+
if (secondaryNode) connectSecondary(secondaryNode, node, 0);
7674
return node;
7775
}
7876

ui/src/plugins/dev.perfetto.DataExplorer/query_builder/nodes/aggregation_node_unittest.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
createMockNode,
2525
createColumnInfo,
2626
connectNodes,
27+
expectValidationError,
28+
expectValidationSuccess,
2729
} from '../testing/test_utils';
2830
import {PerfettoSqlTypes} from '../../../../trace_processor/perfetto_sql_type';
2931

@@ -540,7 +542,7 @@ describe('AggregationNode', () => {
540542
mockPrevNode,
541543
);
542544

543-
expect(node.validate()).toBe(true);
545+
expectValidationSuccess(node);
544546
});
545547

546548
it('should validate node with only aggregations (no group by)', () => {
@@ -561,7 +563,7 @@ describe('AggregationNode', () => {
561563
mockPrevNode,
562564
);
563565

564-
expect(node.validate()).toBe(true);
566+
expectValidationSuccess(node);
565567
});
566568

567569
it('should validate node with both group by and aggregations', () => {
@@ -583,7 +585,7 @@ describe('AggregationNode', () => {
583585
mockPrevNode,
584586
);
585587

586-
expect(node.validate()).toBe(true);
588+
expectValidationSuccess(node);
587589
});
588590

589591
it('should invalidate node with neither group by nor aggregations', () => {
@@ -599,8 +601,8 @@ describe('AggregationNode', () => {
599601
mockPrevNode,
600602
);
601603

602-
expect(node.validate()).toBe(false);
603-
expect(node.context.issues?.queryError?.message).toContain(
604+
expectValidationError(
605+
node,
604606
'requires at least one group by column or aggregation function',
605607
);
606608
});
@@ -653,7 +655,7 @@ describe('AggregationNode', () => {
653655
mockPrevNode,
654656
);
655657

656-
expect(node.validate()).toBe(true);
658+
expectValidationSuccess(node);
657659
});
658660

659661
it('should invalidate node when group by columns are missing from input', () => {
@@ -669,10 +671,7 @@ describe('AggregationNode', () => {
669671
mockPrevNode,
670672
);
671673

672-
expect(node.validate()).toBe(false);
673-
expect(node.context.issues?.queryError?.message).toContain(
674-
'not found in input',
675-
);
674+
expectValidationError(node, 'not found in input');
676675
});
677676

678677
it('should invalidate node without primaryInput', () => {

0 commit comments

Comments
 (0)