Skip to content

Commit

Permalink
fragment generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klavs committed Feb 26, 2020
1 parent c8306c3 commit 64dfaeb
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions gql_example_build/test/fragments/shape_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ String getShapeInfo($Shape data) {
}
}

String getShapeInfoNoRefs($Shape data) {
final shape = data.shape;
final type = shape.$__typename;
final area = shape.area;

final square = shape.asSquare();
if (square != null) {
return "$type(area: $area, sideLength: ${square.sideLength})";
}

final rectangle = shape.asRectangle();
if (rectangle != null) {
return "$type(area: $area, sideLengthA: ${rectangle.sideLengthA}, sideLengthB: ${rectangle.sideLengthB})";
}
}

void main() {
group("shape", () {
test("square", () async {
Expand Down Expand Up @@ -48,4 +64,37 @@ void main() {
);
});
});

group("shape without ref to generated classes", () {
test("square", () async {
const shapeData = <String, dynamic>{
"shape": <String, dynamic>{
"__typename": "Square",
"area": 4,
"sideLength": 2,
},
};

expect(
getShapeInfoNoRefs($Shape(shapeData)),
"Square(area: 4.0, sideLength: 2.0)",
);
});

test("rectangle", () async {
const shapeData = <String, dynamic>{
"shape": <String, dynamic>{
"__typename": "Rectangle",
"area": 3,
"sideLengthA": 3,
"sideLengthB": 1,
},
};

expect(
getShapeInfoNoRefs($Shape(shapeData)),
"Rectangle(area: 3.0, sideLengthA: 3.0, sideLengthB: 1.0)",
);
});
});
}

0 comments on commit 64dfaeb

Please sign in to comment.