Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaijoe committed Jun 27, 2024
1 parent 65b38f1 commit 1fd771b
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 2 deletions.
9 changes: 9 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.2.0

* Add `NestedHeader` widget.

### Breaking changes

* `FHeaderActionStyle.action` parameter has been renamed to `FHeaderStyle.actionStyle`.
* `FHeaderActionStyle.padding` parameter has been moved to `FHeaderStyle.actionSpacing`.

## 0.1.0

* Initial release! 🚀
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion forui/test/src/widgets/header/header_golden_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@Tags(['golden'])
library;

import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';

import 'package:flutter_test/flutter_test.dart';

Expand Down
2 changes: 1 addition & 1 deletion forui/test/src/widgets/header/header_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:flutter_test/flutter_test.dart';

Expand Down
114 changes: 114 additions & 0 deletions forui/test/src/widgets/nested_header/nested_header_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
@Tags(['golden'])
library;

import 'package:flutter/widgets.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import '../../test_scaffold.dart';

void main() {
group('FNestedHeader', () {
for (final (name, theme, _) in TestScaffold.themes) {
testWidgets('$name with FNestedHeader actions', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FNestedHeader(
title: 'Title',
rightActions: [
FNestedHeaderAction(
icon: FAssets.icons.alarmClock,
onPress: null,
),
FNestedHeaderAction(
icon: FAssets.icons.plus,
onPress: () {},
),
],
onPop: () {},
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('nested-header/$name-header.png'),
);
});

testWidgets('$name with raw title', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FNestedHeader(
rawTitle: const Text('Title'),
rightActions: [
FNestedHeaderAction(
icon: FAssets.icons.alarmClock,
onPress: null,
),
FNestedHeaderAction(
icon: FAssets.icons.plus,
onPress: () {},
),
],
onPop: null,
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('nested-header/$name-raw-title.png'),
);
});

testWidgets('$name with raw constructor', (tester) async {
await tester.pumpWidget(
TestScaffold(
data: theme,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: FNestedHeader.raw(
rawTitle: const Text('Title'),
leftActions: [
FNestedHeaderAction(
icon: FAssets.icons.orbit,
onPress: () {},
),
FNestedHeaderAction(
icon: FAssets.icons.airVent,
onPress: () {},
),
],
rightActions: [
FNestedHeaderAction(
icon: FAssets.icons.alarmClock,
onPress: null,
),
FNestedHeaderAction(
icon: FAssets.icons.plus,
onPress: () {},
),
],
),
),
),
);

await expectLater(
find.byType(TestScaffold),
matchesGoldenFile('nested-header/$name-raw-constructor.png'),
);
});
}
});
}
41 changes: 41 additions & 0 deletions forui/test/src/widgets/nested_header/nested_header_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';

void main() {
group('FNestedHeader', () {
for (final (title, rawTitle) in [
('', null),
(null, const SizedBox()),
]) {
testWidgets('constructor does not throw error', (tester) async {
expect(
() => FNestedHeader(
title: title,
rawTitle: rawTitle,
onPop: null,
),
returnsNormally,
);
});
}

for (final (title, rawTitle) in [
(null, null),
('', const SizedBox()),
]) {
testWidgets('constructor throws error', (tester) async {
expect(
() => FNestedHeader(
title: title,
rawTitle: rawTitle,
onPop: () {},
),
throwsAssertionError,
);
});
}
});
}

0 comments on commit 1fd771b

Please sign in to comment.