Skip to content

Commit

Permalink
test: Add widget tests for custom themes in theme_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywellson committed Oct 18, 2024
1 parent 68a83e7 commit a5b46c6
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/widgets/theme_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:get/get.dart';
import 'package:zulip/themes/appbar_theme.dart';
import 'package:zulip/themes/elevated_button_theme.dart';
import 'package:zulip/widgets/channel_colors.dart';
import 'package:zulip/widgets/text.dart';
import 'package:zulip/widgets/theme.dart';
Expand Down Expand Up @@ -133,4 +136,77 @@ void main() {
.isSameColorSwatchAs(ChannelColorSwatch.dark(baseColor));
});
});


group('ZAppBarTheme Tests', () {
testWidgets('Light AppBarThme Test', (tester) async {
final designVariables = DesignVariables.light();

await tester.pumpWidget(GetMaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Test'),
),
),
));

final context = Get.context;

final appBarTheme =
ZAppBarTheme.lightAppBarTheme(context!, designVariables);

expect(appBarTheme.backgroundColor, designVariables.bgTopBar);
expect(appBarTheme.actionsIconTheme!.color, designVariables.icon);
expect(appBarTheme.titleTextStyle!.color, designVariables.title);
expect(appBarTheme.titleTextStyle!.fontSize, 20);
expect(appBarTheme.titleTextStyle!.fontFamily, kDefaultFontFamily);
});

testWidgets('Dark AppBarThem Test', (tester) async {
final designVariables = DesignVariables.dark();

await tester.pumpWidget(GetMaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Test'),
),
),
));

final context = Get.context;
final appBarTheme =
ZAppBarTheme.darkAppBarTheme(context!, designVariables);

expect(appBarTheme.backgroundColor, designVariables.bgTopBar);
expect(appBarTheme.actionsIconTheme!.color, designVariables.icon);
expect(appBarTheme.titleTextStyle!.color, designVariables.title);
expect(appBarTheme.titleTextStyle!.fontSize, 20);
expect(appBarTheme.titleTextStyle!.fontFamily, kDefaultFontFamily);
});
});

testWidgets("Zbutton tests", (tester) async{
final designVariables = DesignVariables.dark();

// Use Get.context to access the context directly
await tester.pumpWidget(
GetMaterialApp(
home: Scaffold(
body: ElevatedButton(
onPressed: () {},
child: const Text('Test Button'),
),
),
),
);

// Act
final elevatedButtonTheme = ZButtonTheme.darkElevatedButtonTheme(designVariables);

// Assert
final elevatedButtonStyle = elevatedButtonTheme.style!;
expect(elevatedButtonStyle.backgroundColor?.resolve({}), designVariables.bgTopBar);
expect(elevatedButtonStyle.foregroundColor?.resolve({}), designVariables.title);
expect(elevatedButtonStyle.elevation?.resolve({}), 4.0);
});
}

0 comments on commit a5b46c6

Please sign in to comment.