lucasmbraz
5/30/2018 - 12:38 PM

planet_summary_widget_test - v1

import 'package:flutter/material.dart';
import 'package:flutter_planets_tutorial/model/planets.dart';
import 'package:flutter_planets_tutorial/ui/common/plannet_summary.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  //1
  group('PlanetSummary ', () {
    //2
    testWidgets('shows planet in horizontal mode', (WidgetTester tester) async {
      final Planet planet = planets[0];
      //3
      await tester.pumpWidget(new MaterialApp(home: new PlanetSummary(planet)));

      //4
      expectSummaryToShow(planet);
    });

    testWidgets('shows planet in vertical mode', (WidgetTester tester) async {
      final Planet planet = planets[0];
      await tester.pumpWidget(new MaterialApp(home: new PlanetSummary.vertical(planet)));

      expectSummaryToShow(planet);
    });
  });
}

void expectSummaryToShow(Planet planet) {
  //5
  expect(find.text(planet.name), findsOneWidget);
  expect(find.text(planet.location), findsOneWidget);
  expect(find.text(planet.gravity), findsOneWidget);
  expect(find.text(planet.distance), findsOneWidget);
}