Skip to content

Commit

Permalink
test: Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Aug 22, 2024
1 parent cc43dcb commit 8e21cd1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 22 deletions.
11 changes: 6 additions & 5 deletions lib/src/pages/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class _ExamplePageState extends State<ExamplePage> {
controller: _scrollController,
child: Column(
children: [
Text('Screen Size: ${MediaQuery.of(context).size}'),
const ZetaAccordion(
title: 'Accordion',
child: Text('Expanded'),
Expand Down Expand Up @@ -199,10 +200,10 @@ class _ExamplePageState extends State<ExamplePage> {
child: Row(
children: [
SizedBox(width: 250, child: ZetaDateInput(label: 'Date Input')),
const SizedBox(width: 250, child: ZetaPasswordInput(label: 'Password input')),
const SizedBox(width: 250, child: ZetaPhoneInput(label: 'Phone Input')),
const SizedBox(width: 250, child: ZetaTimeInput(label: 'Phone Input')),
const SizedBox(width: 250, child: ZetaTextInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaPasswordInput(label: 'Password input')),
SizedBox(width: 250, child: ZetaPhoneInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaTimeInput(label: 'Phone Input')),
SizedBox(width: 250, child: ZetaTextInput(label: 'Phone Input')),
SizedBox(
width: 250,
child: ZetaSelectInput(
Expand Down Expand Up @@ -238,7 +239,7 @@ class _ExamplePageState extends State<ExamplePage> {
onActionButtonPressed: () {},
title: const Text('Screen Header Bar'),
),
const ZetaSearchBar(),
ZetaSearchBar(),
ZetaSegmentedControl(
segments: const [
ZetaButtonSegment(value: 1, child: Text('Segmented')),
Expand Down
10 changes: 5 additions & 5 deletions lib/src/utils/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final goRouter = GoRouter(
builder: (context, state, navigationShell) {
return LayoutBuilder(
builder: (context, constraints) {
final showBottomBar = constraints.maxWidth < 479;
final showBottomBar = constraints.maxWidth < 500;

final body = CustomScrollView(
slivers: [
Expand Down Expand Up @@ -42,8 +42,8 @@ final goRouter = GoRouter(
onSelect: (value) => navigationShell.goBranch(value),
selectedIndex: state.fullPath == '/' ? 0 : 1,
items: const [
ZetaNavigationRailItem(label: 'Welcome', icon: Icon(ZetaIcons.content_round)),
ZetaNavigationRailItem(label: 'Example', icon: Icon(ZetaIcons.star_round)),
ZetaNavigationRailItem(label: 'Welcome', icon: Icon(ZetaIcons.content)),
ZetaNavigationRailItem(label: 'Example', icon: Icon(ZetaIcons.star)),
],
),
Expanded(child: body),
Expand All @@ -54,8 +54,8 @@ final goRouter = GoRouter(
onTap: (value) => navigationShell.goBranch(value),
currentIndex: state.fullPath == '/' ? 0 : 1,
items: const [
ZetaNavigationBarItem(icon: ZetaIcons.content_round, label: 'Welcome'),
ZetaNavigationBarItem(icon: ZetaIcons.star_round, label: 'Example'),
ZetaNavigationBarItem(icon: ZetaIcons.content, label: 'Welcome'),
ZetaNavigationBarItem(icon: ZetaIcons.star, label: 'Example'),
],
)
: null,
Expand Down
2 changes: 1 addition & 1 deletion macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Cocoa
import FlutterMacOS

@NSApplicationMain
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies:
flutter:
sdk: flutter
go_router: ^14.2.0
zeta_flutter: ^0.14.0
zeta_flutter: ^0.15.1

dev_dependencies:
flutter_test:
Expand Down
74 changes: 64 additions & 10 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,80 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import 'package:zeta_flutter_template/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
testWidgets('App runs', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
});

testWidgets('Bottom navigation bar works on small screen', (WidgetTester tester) async {
// Set the screen size to a small value
tester.view.devicePixelRatio = 1.0;
tester.view.physicalSize = const Size(481, 480);

// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();

// Find the bottom navigation bar widget
final bottomNavigationBarFinder = find.byType(ZetaNavigationBar);

// Verify that the bottom navigation bar is present
expect(bottomNavigationBarFinder, findsOneWidget);

// Perform a tap on the first item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.content_round));
await tester.pump();

// Verify that the first item is selected
expect(bottomNavigationBarFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationBar>(bottomNavigationBarFinder).currentIndex, 0);

// Perform a tap on the second item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.star_round));
await tester.pump();

// // Verify that the second item is selected
expect(bottomNavigationBarFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationBar>(bottomNavigationBarFinder).currentIndex, 1);
});

testWidgets('Side navigation bar works on large screen', (WidgetTester tester) async {
// Set the screen size to a small value
tester.view.devicePixelRatio = 1.0;
tester.view.physicalSize = const Size(881, 480);

// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());

// Find the bottom navigation bar widget
final navigationRailFinder = find.byType(ZetaNavigationRail);

// Verify that the bottom navigation bar is present
expect(navigationRailFinder, findsOneWidget);

// Perform a tap on the first item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.content));
await tester.pump();

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Verify that the first item is selected
expect(navigationRailFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationRail>(navigationRailFinder).selectedIndex, 0);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
// Perform a tap on the second item of the bottom navigation bar
await tester.tap(find.byIcon(ZetaIcons.star));
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
// // Verify that the second item is selected
expect(navigationRailFinder, findsOneWidget);
expect(tester.widget<ZetaNavigationRail>(navigationRailFinder).selectedIndex, 1);
});
}

0 comments on commit 8e21cd1

Please sign in to comment.