Skip to content

Commit d21c3e9

Browse files
committed
Added material and cupertino tests
1 parent 17e3d9f commit d21c3e9

File tree

5 files changed

+655
-0
lines changed

5 files changed

+655
-0
lines changed

test/cupertino/button_test.dart

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import 'package:exui/src/cupertino.dart';
2+
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
extension CupertinoButtonWidgetExtensionsTest on Widget {
6+
CupertinoButton getButtonFromCupertinoButton({
7+
required void Function()? onPressed,
8+
}) =>
9+
cupertinoButton(onPressed: onPressed);
10+
11+
CupertinoButton getButtonFromFilledButton({
12+
required void Function()? onPressed,
13+
}) =>
14+
cupertinoFilledButton(onPressed: onPressed);
15+
16+
CupertinoButton getButtonFromTintedButton({
17+
required void Function()? onPressed,
18+
}) =>
19+
cupertinoTintedButton(onPressed: onPressed);
20+
}
21+
22+
void main() {
23+
testWidgets(
24+
'cupertinoButton creates CupertinoButton with correct child and onPressed',
25+
(tester) async {
26+
bool pressed = false;
27+
final widget = Text('Tap me').cupertinoButton(
28+
onPressed: () => pressed = true,
29+
);
30+
31+
await tester.pumpWidget(CupertinoApp(home: widget));
32+
33+
expect(find.text('Tap me'), findsOneWidget);
34+
await tester.tap(find.byType(CupertinoButton));
35+
expect(pressed, true);
36+
});
37+
38+
testWidgets('cupertinoFilledButton creates filled button with correct child',
39+
(tester) async {
40+
bool called = false;
41+
final widget = Text('Submit').cupertinoFilledButton(
42+
onPressed: () => called = true,
43+
);
44+
45+
await tester.pumpWidget(CupertinoApp(home: widget));
46+
expect(find.text('Submit'), findsOneWidget);
47+
await tester.tap(find.byType(CupertinoButton));
48+
expect(called, true);
49+
});
50+
51+
testWidgets('cupertinoTintedButton uses tint color correctly',
52+
(tester) async {
53+
final color = CupertinoColors.systemPink;
54+
final widget = Text('Share').cupertinoTintedButton(
55+
color: color,
56+
onPressed: () {},
57+
);
58+
59+
await tester.pumpWidget(CupertinoApp(home: widget));
60+
final btn = tester.widget<CupertinoButton>(find.byType(CupertinoButton));
61+
expect(btn.color, color);
62+
});
63+
64+
testWidgets('disabled button does not trigger onPressed', (tester) async {
65+
bool pressed = false;
66+
final widget = Text('Disabled').cupertinoButton(
67+
onPressed: null,
68+
);
69+
70+
await tester.pumpWidget(CupertinoApp(home: widget));
71+
await tester.tap(find.byType(CupertinoButton));
72+
expect(pressed, false); // No change
73+
});
74+
75+
testWidgets('cupertinoButton applies borderRadius and alignment',
76+
(tester) async {
77+
const radius = BorderRadius.all(Radius.circular(12));
78+
const align = Alignment.bottomRight;
79+
80+
final button = Text('Align').cupertinoButton(
81+
borderRadius: radius,
82+
alignment: align,
83+
onPressed: () {},
84+
);
85+
86+
expect(button.borderRadius, radius);
87+
expect(button.alignment, align);
88+
});
89+
90+
testWidgets('cupertinoFilledButton applies sizeStyle and pressedOpacity',
91+
(tester) async {
92+
final button = Text('Press').cupertinoFilledButton(
93+
sizeStyle: CupertinoButtonSize.small,
94+
pressedOpacity: 0.2,
95+
onPressed: () {},
96+
);
97+
98+
expect(button.sizeStyle, CupertinoButtonSize.small);
99+
expect(button.pressedOpacity, 0.2);
100+
});
101+
102+
testWidgets('cupertinoTintedButton applies disabledColor and autofocus',
103+
(tester) async {
104+
final button = Text('Auto').cupertinoTintedButton(
105+
disabledColor: CupertinoColors.systemGrey,
106+
autofocus: true,
107+
onPressed: () {},
108+
);
109+
110+
expect(button.disabledColor, CupertinoColors.systemGrey);
111+
expect(button.autofocus, true);
112+
});
113+
114+
testWidgets('cupertinoButton handles focusColor and focusNode',
115+
(tester) async {
116+
final node = FocusNode();
117+
final button = Text('Focus').cupertinoButton(
118+
focusColor: CupertinoColors.activeBlue,
119+
focusNode: node,
120+
onPressed: () {},
121+
);
122+
123+
expect(button.focusNode, node);
124+
expect(button.focusColor, CupertinoColors.activeBlue);
125+
});
126+
127+
testWidgets('cupertinoButton calls onLongPress', (tester) async {
128+
bool longPressed = false;
129+
final widget = Text('Long Press').cupertinoButton(
130+
onPressed: () {},
131+
onLongPress: () => longPressed = true,
132+
);
133+
134+
await tester.pumpWidget(CupertinoApp(home: widget));
135+
await tester.longPress(find.byType(CupertinoButton));
136+
expect(longPressed, true);
137+
});
138+
}

test/cupertino/colored_box_test.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:exui/cupertino.dart';
2+
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
void main() {
6+
testWidgets('CupertinoBoxColorsExtension applies correct colors',
7+
(tester) async {
8+
final widget = const Text('test');
9+
10+
await tester.pumpWidget(
11+
Directionality(
12+
textDirection: TextDirection.ltr,
13+
child: Column(
14+
children: [
15+
widget.redBox(),
16+
widget.destructiveRedBox(),
17+
widget.greenBox(),
18+
widget.activeGreenBox(),
19+
widget.blueBox(),
20+
widget.activeBlueBox(),
21+
widget.yellowBox(),
22+
widget.orangeBox(),
23+
widget.orangeAccentBox(),
24+
widget.purpleBox(),
25+
widget.pinkBox(),
26+
widget.brownBox(),
27+
widget.tealBox(),
28+
widget.cyanBox(),
29+
widget.greyBox(),
30+
widget.blackBox(),
31+
widget.whiteBox(),
32+
widget.darkGrayBox(),
33+
widget.lightGrayBox(),
34+
],
35+
),
36+
),
37+
);
38+
39+
final colors = [
40+
CupertinoColors.systemRed,
41+
CupertinoColors.destructiveRed,
42+
CupertinoColors.systemGreen,
43+
CupertinoColors.activeGreen,
44+
CupertinoColors.systemBlue,
45+
CupertinoColors.activeBlue,
46+
CupertinoColors.systemYellow,
47+
CupertinoColors.systemOrange,
48+
CupertinoColors.activeOrange,
49+
CupertinoColors.systemPurple,
50+
CupertinoColors.systemPink,
51+
CupertinoColors.systemBrown,
52+
CupertinoColors.systemTeal,
53+
CupertinoColors.systemCyan,
54+
CupertinoColors.systemGrey,
55+
CupertinoColors.black,
56+
CupertinoColors.white,
57+
CupertinoColors.darkBackgroundGray,
58+
CupertinoColors.lightBackgroundGray,
59+
];
60+
61+
final coloredBoxes = find.byType(ColoredBox);
62+
expect(coloredBoxes, findsNWidgets(colors.length));
63+
64+
for (int i = 0; i < colors.length; i++) {
65+
final box = tester.widget<ColoredBox>(coloredBoxes.at(i));
66+
expect(box.color, equals(colors[i]));
67+
expect(box.child, isA<Text>());
68+
expect((box.child as Text).data, equals('test'));
69+
}
70+
});
71+
}

test/material/bottom_bar_test.dart

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
import 'package:exui/material.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
List<BottomNavigationBarItem> extensionTestItems() =>
6+
const <BottomNavigationBarItem>[
7+
BottomNavigationBarItem(
8+
icon: Icon(Icons.home),
9+
label: 'Home',
10+
),
11+
BottomNavigationBarItem(
12+
icon: Icon(Icons.search),
13+
label: 'Search',
14+
),
15+
];
16+
17+
void main() {
18+
late List<BottomNavigationBarItem> items;
19+
20+
setUp(() {
21+
items = extensionTestItems();
22+
});
23+
24+
testWidgets('creates BottomNavigationBar with default values',
25+
(tester) async {
26+
final widget = MaterialApp(
27+
home: Scaffold(
28+
bottomNavigationBar: items.bottomNavigationBar(),
29+
),
30+
);
31+
32+
await tester.pumpWidget(widget);
33+
34+
expect(find.byType(BottomNavigationBar), findsOneWidget);
35+
final bottomNavBar = tester.widget<BottomNavigationBar>(
36+
find.byType(BottomNavigationBar),
37+
);
38+
39+
expect(bottomNavBar.items.length, 2);
40+
expect(bottomNavBar.currentIndex, 0);
41+
expect(bottomNavBar.iconSize, 24.0);
42+
expect(bottomNavBar.selectedFontSize, 14.0);
43+
expect(bottomNavBar.unselectedFontSize, 12.0);
44+
expect(bottomNavBar.useLegacyColorScheme, isTrue);
45+
});
46+
47+
testWidgets('passes currentIndex and onTap correctly', (tester) async {
48+
int? tappedIndex;
49+
50+
final widget = MaterialApp(
51+
home: Scaffold(
52+
bottomNavigationBar: items.bottomNavigationBar(
53+
currentIndex: 1,
54+
onTap: (index) => tappedIndex = index,
55+
),
56+
),
57+
);
58+
59+
await tester.pumpWidget(widget);
60+
final bottomNavBar = tester.widget<BottomNavigationBar>(
61+
find.byType(BottomNavigationBar),
62+
);
63+
64+
expect(bottomNavBar.currentIndex, 1);
65+
66+
await tester.tap(find.text('Home'));
67+
expect(tappedIndex, 0);
68+
69+
await tester.tap(find.text('Search'));
70+
expect(tappedIndex, 1);
71+
});
72+
73+
testWidgets('applies color and type configurations', (tester) async {
74+
final widget = MaterialApp(
75+
home: Scaffold(
76+
bottomNavigationBar: items.bottomNavigationBar(
77+
selectedItemColor: Colors.red,
78+
unselectedItemColor: Colors.grey,
79+
backgroundColor: Colors.black,
80+
type: BottomNavigationBarType.fixed,
81+
),
82+
),
83+
);
84+
85+
await tester.pumpWidget(widget);
86+
final bottomNavBar = tester.widget<BottomNavigationBar>(
87+
find.byType(BottomNavigationBar),
88+
);
89+
90+
expect(bottomNavBar.selectedItemColor, Colors.red);
91+
expect(bottomNavBar.unselectedItemColor, Colors.grey);
92+
expect(bottomNavBar.backgroundColor, Colors.black);
93+
expect(bottomNavBar.type, BottomNavigationBarType.fixed);
94+
});
95+
96+
testWidgets('uses custom icon theme and label styles', (tester) async {
97+
final selectedIconTheme = IconThemeData(size: 30, color: Colors.green);
98+
final unselectedIconTheme = IconThemeData(size: 20, color: Colors.blue);
99+
final selectedLabelStyle = TextStyle(fontWeight: FontWeight.bold);
100+
final unselectedLabelStyle = TextStyle(fontWeight: FontWeight.normal);
101+
102+
final widget = MaterialApp(
103+
home: Scaffold(
104+
bottomNavigationBar: items.bottomNavigationBar(
105+
selectedIconTheme: selectedIconTheme,
106+
unselectedIconTheme: unselectedIconTheme,
107+
selectedLabelStyle: selectedLabelStyle,
108+
unselectedLabelStyle: unselectedLabelStyle,
109+
),
110+
),
111+
);
112+
113+
await tester.pumpWidget(widget);
114+
final bottomNavBar = tester.widget<BottomNavigationBar>(
115+
find.byType(BottomNavigationBar),
116+
);
117+
118+
expect(bottomNavBar.selectedIconTheme, selectedIconTheme);
119+
expect(bottomNavBar.unselectedIconTheme, unselectedIconTheme);
120+
expect(bottomNavBar.selectedLabelStyle, selectedLabelStyle);
121+
expect(bottomNavBar.unselectedLabelStyle, unselectedLabelStyle);
122+
});
123+
124+
testWidgets('respects feedback and landscape layout', (tester) async {
125+
final widget = MaterialApp(
126+
home: Scaffold(
127+
bottomNavigationBar: items.bottomNavigationBar(
128+
enableFeedback: false,
129+
landscapeLayout: BottomNavigationBarLandscapeLayout.centered,
130+
useLegacyColorScheme: false,
131+
),
132+
),
133+
);
134+
135+
await tester.pumpWidget(widget);
136+
final bottomNavBar = tester.widget<BottomNavigationBar>(
137+
find.byType(BottomNavigationBar),
138+
);
139+
140+
expect(bottomNavBar.enableFeedback, false);
141+
expect(bottomNavBar.landscapeLayout,
142+
BottomNavigationBarLandscapeLayout.centered);
143+
expect(bottomNavBar.useLegacyColorScheme, false);
144+
});
145+
146+
testWidgets('respects label visibility settings', (tester) async {
147+
final widget = MaterialApp(
148+
home: Scaffold(
149+
bottomNavigationBar: items.bottomNavigationBar(
150+
showSelectedLabels: false,
151+
showUnselectedLabels: false,
152+
),
153+
),
154+
);
155+
156+
await tester.pumpWidget(widget);
157+
final bottomNavBar = tester.widget<BottomNavigationBar>(
158+
find.byType(BottomNavigationBar),
159+
);
160+
161+
expect(bottomNavBar.showSelectedLabels, false);
162+
expect(bottomNavBar.showUnselectedLabels, false);
163+
});
164+
}

0 commit comments

Comments
 (0)