Skip to content

Commit 64dfaeb

Browse files
committed
fragment generation tests
1 parent c8306c3 commit 64dfaeb

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

gql_example_build/test/fragments/shape_test.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ String getShapeInfo($Shape data) {
1515
}
1616
}
1717

18+
String getShapeInfoNoRefs($Shape data) {
19+
final shape = data.shape;
20+
final type = shape.$__typename;
21+
final area = shape.area;
22+
23+
final square = shape.asSquare();
24+
if (square != null) {
25+
return "$type(area: $area, sideLength: ${square.sideLength})";
26+
}
27+
28+
final rectangle = shape.asRectangle();
29+
if (rectangle != null) {
30+
return "$type(area: $area, sideLengthA: ${rectangle.sideLengthA}, sideLengthB: ${rectangle.sideLengthB})";
31+
}
32+
}
33+
1834
void main() {
1935
group("shape", () {
2036
test("square", () async {
@@ -48,4 +64,37 @@ void main() {
4864
);
4965
});
5066
});
67+
68+
group("shape without ref to generated classes", () {
69+
test("square", () async {
70+
const shapeData = <String, dynamic>{
71+
"shape": <String, dynamic>{
72+
"__typename": "Square",
73+
"area": 4,
74+
"sideLength": 2,
75+
},
76+
};
77+
78+
expect(
79+
getShapeInfoNoRefs($Shape(shapeData)),
80+
"Square(area: 4.0, sideLength: 2.0)",
81+
);
82+
});
83+
84+
test("rectangle", () async {
85+
const shapeData = <String, dynamic>{
86+
"shape": <String, dynamic>{
87+
"__typename": "Rectangle",
88+
"area": 3,
89+
"sideLengthA": 3,
90+
"sideLengthB": 1,
91+
},
92+
};
93+
94+
expect(
95+
getShapeInfoNoRefs($Shape(shapeData)),
96+
"Rectangle(area: 3.0, sideLengthA: 3.0, sideLengthB: 1.0)",
97+
);
98+
});
99+
});
51100
}

0 commit comments

Comments
 (0)