Skip to content

Commit

Permalink
Fixed next pr issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Daviiddoo committed Oct 2, 2024
1 parent 8ae0af7 commit 92fa7ba
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
18 changes: 9 additions & 9 deletions forui/lib/src/widgets/accordion/accordion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:forui/forui.dart';
///
///
/// See:
/// * https://forui.dev/docs/FAccordion for working examples.
/// * https://forui.dev/docs/accordion for working examples.
/// * [FAccordionController] for customizing the accordion's selection behavior.
/// * [FAccordionItem] for adding items to an accordion.
/// * [FAccordionStyle] for customizing an accordion's appearance.
Expand Down Expand Up @@ -106,7 +106,7 @@ final class FAccordionStyle with Diagnosticable {
final Widget icon;

/// The divider's color.
final Color dividerColor;
final FDividerStyle divider;

/// Creates a [FAccordionStyle].
FAccordionStyle({
Expand All @@ -115,7 +115,7 @@ final class FAccordionStyle with Diagnosticable {
required this.titlePadding,
required this.childPadding,
required this.icon,
required this.dividerColor,
required this.divider,
});

/// Creates a [FDividerStyles] that inherits its properties from [colorScheme].
Expand All @@ -133,7 +133,7 @@ final class FAccordionStyle with Diagnosticable {
height: 20,
colorFilter: ColorFilter.mode(colorScheme.primary, BlendMode.srcIn),
),
dividerColor = colorScheme.border;
divider = FDividerStyle(color: colorScheme.border, padding: EdgeInsets.zero);

/// Returns a copy of this [FAccordionStyle] with the given properties replaced.
@useResult
Expand All @@ -143,15 +143,15 @@ final class FAccordionStyle with Diagnosticable {
EdgeInsets? titlePadding,
EdgeInsets? childPadding,
SvgPicture? icon,
Color? dividerColor,
FDividerStyle? divider,
}) =>
FAccordionStyle(
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
childTextStyle: childTextStyle ?? this.childTextStyle,
titlePadding: titlePadding ?? this.titlePadding,
childPadding: childPadding ?? this.childPadding,
icon: icon ?? this.icon,
dividerColor: dividerColor ?? this.dividerColor,
divider: divider ?? this.divider,
);

@override
Expand All @@ -162,7 +162,7 @@ final class FAccordionStyle with Diagnosticable {
..add(DiagnosticsProperty('childTextStyle', childTextStyle))
..add(DiagnosticsProperty('padding', titlePadding))
..add(DiagnosticsProperty('contentPadding', childPadding))
..add(ColorProperty('dividerColor', dividerColor));
..add(DiagnosticsProperty('divider', divider));
}

@override
Expand All @@ -175,7 +175,7 @@ final class FAccordionStyle with Diagnosticable {
titlePadding == other.titlePadding &&
childPadding == other.childPadding &&
icon == other.icon &&
dividerColor == other.dividerColor;
divider == other.divider;

@override
int get hashCode =>
Expand All @@ -184,7 +184,7 @@ final class FAccordionStyle with Diagnosticable {
titlePadding.hashCode ^
childPadding.hashCode ^
icon.hashCode ^
dividerColor.hashCode;
divider.hashCode;
}

@internal
Expand Down
4 changes: 2 additions & 2 deletions forui/lib/src/widgets/accordion/accordion_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FAccordionItem extends StatefulWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty('style', style))
..add(DiagnosticsProperty('initiallyExpanded', initiallyExpanded));
..add(FlagProperty('initiallyExpanded', value: initiallyExpanded, ifTrue: 'Initially expanded'));
}
}

Expand Down Expand Up @@ -125,7 +125,7 @@ class _FAccordionItemState extends State<FAccordionItem> with TickerProviderStat
),
),
FDivider(
style: context.theme.dividerStyles.horizontal.copyWith(padding: EdgeInsets.zero, color: style.dividerColor),
style: style.divider,
),
],
),
Expand Down
Binary file modified forui/test/golden/accordion/hidden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified forui/test/golden/accordion/shown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 46 additions & 22 deletions forui/test/src/widgets/accordion/accordion_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import 'package:mockito/mockito.dart';
import 'package:forui/forui.dart';
import 'accordion_controller_test.mocks.dart';

@GenerateNiceMocks([MockSpec<AnimationController>()])
@GenerateNiceMocks([MockSpec<Animation>()])
void _setup(List<AnimationController> animationControllers, List<Animation<int>> animations, int length) {
animations.clear();
animationControllers.clear();
(List<AnimationController>, List) _setup(int length) {
final animationControllers = <AnimationController>[];
final animations = [];

for (int i = 0; i < length; i++) {
animationControllers.add(MockAnimationController());
Expand All @@ -27,48 +25,56 @@ void _setup(List<AnimationController> animationControllers, List<Animation<int>>
return TickerFuture.complete();
});
}

return (animationControllers, animations);
}

void _tearDown(List<AnimationController> animationControllers, length) {
for (int i = 0; i < length; i++) {
animationControllers[i].dispose();
void _tearDown(List<AnimationController> animationControllers) {
for (final controller in animationControllers) {
controller.dispose();
}
}

@GenerateNiceMocks([MockSpec<AnimationController>()])
@GenerateNiceMocks([MockSpec<Animation>()])
void main() {
group('FAccordionController', () {
late FAccordionController controller;
final List<AnimationController> animationControllers = [];
final List<Animation<int>> animations = [];
List<AnimationController> animationControllers = [];
List<Animation<int>> animations = [];
int count = 0;
int length = 3;

setUp(() {
count = 0;
length = 3;
_setup(animationControllers, animations, length);
final record = _setup(length);
animationControllers = List.from(record.$1);
animations = List.from(record.$2);
controller = FAccordionController(min: 1, max: 2)
..addListener(() {
count++;
});
});

tearDown(() {
_tearDown(animationControllers, length);
_tearDown(animationControllers);
controller.dispose();
});

group('addItem(...)', () {
test('sets animation controller value based on initiallyExpanded', () async {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
verify(animationControllers[0].value = 0);

await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
verify(animationControllers[0].value = 1);
});

test('adds to expanded list', () {
controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
expect(controller.expanded.length, 0);

controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
expect(controller.expanded.length, 1);
expect(controller.controllers.length, 1);
Expand All @@ -85,21 +91,24 @@ void main() {
group('removeItem(...)', () {
setUp(() {
length = 1;
_setup(animationControllers, animations, length);
final record = _setup(length);
animationControllers = List.from(record.$1);
animations = List.from(record.$2);
controller = FAccordionController(min: 1, max: 2)
..addListener(() {
count++;
});
});

tearDown(() {
_tearDown(animationControllers, length);
_tearDown(animationControllers);
});
test('removes from the expanded list', () {
controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
expect(controller.removeItem(0), true);
expect(controller.removeItem(0), false);
});

test('aware of min limit', () {
controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
expect(controller.removeItem(0), false);
Expand All @@ -110,6 +119,7 @@ void main() {
test('expands an item', () async {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
expect(controller.controllers[0]?.animation.value, 0);

await controller.toggle(0);
expect(controller.controllers[0]?.animation.value, 100);
});
Expand All @@ -119,6 +129,7 @@ void main() {
await controller.addItem(1, animationControllers[1], animations[1], initiallyExpanded: true);
await animationControllers[0].forward();
expect(controller.controllers[0]?.animation.value, 100);

await controller.toggle(0);
expect(controller.controllers[0]?.animation.value, 0);
});
Expand All @@ -127,6 +138,7 @@ void main() {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
await controller.toggle(1);
expect(count, 0);

await controller.toggle(0);
expect(count, 1);
});
Expand Down Expand Up @@ -161,6 +173,7 @@ void main() {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
await controller.expand(0);
expect(controller.expanded, {0});

await controller.expand(0);
expect(count, 1);
await controller.expand(1);
Expand All @@ -179,22 +192,25 @@ void main() {
group('collapse(...)', () {
setUp(() {
length = 2;
_setup(animationControllers, animations, length);
final record = _setup(length);
animationControllers = List.from(record.$1);
animations = List.from(record.$2);
controller = FAccordionController(min: 1, max: 2)
..addListener(() {
count++;
});
});

tearDown(() {
_tearDown(animationControllers, length);
_tearDown(animationControllers);
});

test('does not call notifyListener on invalid index', () async {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
await controller.addItem(1, animationControllers[1], animations[1], initiallyExpanded: true);
await controller.collapse(0);
expect(controller.expanded, {1});

await controller.collapse(0);
expect(count, 1);
await controller.collapse(2);
Expand All @@ -218,30 +234,33 @@ void main() {

group('FAccordionController.radio', () {
late FAccordionController controller;
final List<AnimationController> animationControllers = [];
final List<Animation<int>> animations = [];
List<AnimationController> animationControllers = [];
List<Animation<int>> animations = [];
int count = 0;
int length = 2;

setUp(() {
count = 0;
length = 2;
_setup(animationControllers, animations, length);
final record = _setup(length);
animationControllers = List.from(record.$1);
animations = List.from(record.$2);
controller = FAccordionController.radio()
..addListener(() {
count++;
});
});

tearDown(() {
_tearDown(animationControllers, length);
_tearDown(animationControllers);
controller.dispose();
});

group('addItem(...)', () {
test('adds to expanded list', () {
controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
expect(controller.expanded.length, 0);

controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
expect(controller.expanded.length, 1);
expect(controller.controllers.length, 1);
Expand All @@ -256,15 +275,17 @@ void main() {
group('removeItem(...)', () {
setUp(() {
length = 1;
_setup(animationControllers, animations, length);
final record = _setup(length);
animationControllers = List.from(record.$1);
animations = List.from(record.$2);
controller = FAccordionController.radio()
..addListener(() {
count++;
});
});

tearDown(() {
_tearDown(animationControllers, length);
_tearDown(animationControllers);
});

test('removes from the expanded list', () {
Expand All @@ -282,6 +303,7 @@ void main() {
test('expands an item', () async {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
expect(controller.controllers[0]?.animation.value, 0);

await controller.toggle(0);
expect(controller.controllers[0]?.animation.value, 100);
});
Expand All @@ -290,13 +312,15 @@ void main() {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: true);
await animationControllers[0].forward();
expect(controller.controllers[0]?.animation.value, 100);

await controller.toggle(0);
expect(controller.controllers[0]?.animation.value, 0);
});

test('invalid index', () async {
await controller.addItem(0, animationControllers[0], animations[0], initiallyExpanded: false);
await controller.toggle(1);

expect(count, 0);
await controller.toggle(0);
expect(count, 1);
Expand Down

0 comments on commit 92fa7ba

Please sign in to comment.