From 64dfaeba432c94769cfb785038851233be5fc781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kl=C4=81vs=20Pried=C4=ABtis?= Date: Sun, 23 Feb 2020 16:37:38 +0200 Subject: [PATCH] fragment generation tests --- .../test/fragments/shape_test.dart | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gql_example_build/test/fragments/shape_test.dart b/gql_example_build/test/fragments/shape_test.dart index 8be08034..6675e765 100644 --- a/gql_example_build/test/fragments/shape_test.dart +++ b/gql_example_build/test/fragments/shape_test.dart @@ -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 { @@ -48,4 +64,37 @@ void main() { ); }); }); + + group("shape without ref to generated classes", () { + test("square", () async { + const shapeData = { + "shape": { + "__typename": "Square", + "area": 4, + "sideLength": 2, + }, + }; + + expect( + getShapeInfoNoRefs($Shape(shapeData)), + "Square(area: 4.0, sideLength: 2.0)", + ); + }); + + test("rectangle", () async { + const shapeData = { + "shape": { + "__typename": "Rectangle", + "area": 3, + "sideLengthA": 3, + "sideLengthB": 1, + }, + }; + + expect( + getShapeInfoNoRefs($Shape(shapeData)), + "Rectangle(area: 3.0, sideLengthA: 3.0, sideLengthB: 1.0)", + ); + }); + }); }