Skip to content

Commit

Permalink
ci: add coverage to pr action
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 19, 2024
1 parent 9659e70 commit e52c572
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 76 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
with:
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Install lcov
run: sudo apt-get install -y lcov
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
Expand Down Expand Up @@ -43,20 +45,20 @@ jobs:
id: test
run: |
cd example
# Allows code to run after an error.
set -e
# Runs flutter test; saves output and if it fails.
out=$(flutter test) || failed='true'
out=$(flutter test --coverage) || failed='true'
echo "$out"
# Saves output to either success or failure variables.
if [ "$failed" == "true" ]; then
echo "FAILURE=true" >> $GITHUB_OUTPUT
exit 1
fi
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
Expand All @@ -68,8 +70,8 @@ jobs:
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
- name: Print outputs
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: CI - Pull Request
on:
pull_request_target:
pull_request:

jobs:
up-to-date:
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/components/button_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ButtonExample extends StatefulWidget {
class _ButtonExampleState extends State<ButtonExample> {
Widget? fab;
late ScrollController _scrollController;
bool expanded = false;

@override
void initState() {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/components/fabs/fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ZetaFAB extends StatefulWidget {
class _ZetaFABState extends State<ZetaFAB> {
@override
Widget build(BuildContext context) {
bool _isExpanded = (widget.initiallyExpanded != null ? widget.initiallyExpanded! : widget.label != null);
final bool isExpanded = (widget.initiallyExpanded != null ? widget.initiallyExpanded! : widget.label != null);
final colors = widget.type.colors(context);
final backgroundColor = widget.type == ZetaFabType.inverse ? colors.shade80 : colors.shade60;

Expand All @@ -115,7 +115,7 @@ class _ZetaFABState extends State<ZetaFAB> {
focusNode: widget.focusNode,
style: ButtonStyle(
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
shape: WidgetStatePropertyAll(widget.shape.buttonShape(isExpanded: _isExpanded, size: widget.size)),
shape: WidgetStatePropertyAll(widget.shape.buttonShape(isExpanded: isExpanded, size: widget.size)),
backgroundColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) return Zeta.of(context).colors.surfaceDisabled;
if (states.contains(WidgetState.hovered)) return colors.hover;
Expand All @@ -135,14 +135,14 @@ class _ZetaFABState extends State<ZetaFAB> {
child: AnimatedContainer(
duration: ZetaAnimationLength.normal,
child: Padding(
padding: _isExpanded
padding: isExpanded
? const EdgeInsets.symmetric(horizontal: ZetaSpacingBase.x3_5, vertical: ZetaSpacing.medium)
: EdgeInsets.all(widget.size.padding),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(widget.icon, size: widget.size.iconSize),
if (_isExpanded && widget.label != null)
if (isExpanded && widget.label != null)
Row(
mainAxisSize: MainAxisSize.min,
children: [Text(widget.label!, style: ZetaTextStyles.labelLarge)],
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Default constructor initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaIndicator()));

Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp(home: ZetaLabel(label: 'Test Label')));

Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/priority_pill_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
testWidgets('Initializes with correct label and index', (WidgetTester tester) async {
await tester.pumpWidget(
const TestApp(
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/status_label_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
group('ZetaStatusLabel Tests', () {
testWidgets('Initializes with correct properties', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
5 changes: 5 additions & 0 deletions test/src/components/badge/tag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('badge'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});
group('ZetaTag', () {
testWidgets('Initializes right with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/button/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('button'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaButton Tests', () {
testWidgets('Initializes with correct Label', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/checkbox/checkbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('checkbox'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaCheckbox Tests', () {
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/dialpad/dialpad_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('dialpad'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaDialPad Tests', () {
testWidgets('Initializes with correct parameters and is enabled', (WidgetTester tester) async {
String number = '';
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/fabs/fab_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('fabs'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaFAB Tests', () {
testWidgets('Initializes with correct parameters', (WidgetTester tester) async {
final scrollController = ScrollController();
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/in_page_banner/in_page_banner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('in_page_banner'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaInPageBanner Tests', () {
testWidgets('ZetaInPageBanner creation', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
6 changes: 6 additions & 0 deletions test/src/components/tooltip/tooltip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('tooltip'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

group('ZetaTooltip Widget Tests', () {
testWidgets('renders with default properties', (WidgetTester tester) async {
await tester.pumpWidget(
Expand Down
127 changes: 61 additions & 66 deletions test/src/theme/typography_test.dart
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
//import 'package:flutter/material.dart';
// import 'package:flutter_test/flutter_test.dart';
// import 'package:zeta_example/pages/theme/typography_example.dart';

// import 'package:zeta_flutter/zeta_flutter.dart';

// import 'test_components.dart';

// void main() {
// const Key key1 = Key('1');
// const Key key2 = Key('2');
// const Key key3 = Key('3');
// const Key key4 = Key('4');

// testWidgets('Text tokens', (tester) async {
// await tester.pumpWidget(
// TestWidget(
// widget: Builder(
// builder: (context) {
// return Column(
// children: [
// const Text(exampleText, key: key1),
// Text(exampleText, style: ZetaTextStyles.bodyMedium, key: key2),
// Text(exampleText, style: ZetaTextStyles.displayLarge, key: key3),
// Text(
// exampleText,
// style: TextStyle(fontSize: 52, fontWeight: FontWeight.w300, height: 60 / 52),
// key: key4,
// ),
// ],
// );
// },
// ),
// ),
// );

// final Finder zetaText1 = find.byKey(key1);
// final Finder zetaText2 = find.byKey(key2);
// final Finder zetaText3 = find.byKey(key3);
// final Finder zetaText4 = find.byKey(key4);

// final InlineSpan text1 =
// (find.descendant(of: zetaText1, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text2 =
// (find.descendant(of: zetaText2, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text3 =
// (find.descendant(of: zetaText3, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text4 =
// (find.descendant(of: zetaText4, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;

// /// Test default in [Text] widget is [ZetaTextStyles.bodyMedium].
// expect(text1.style, text2.style);

// /// Test that [ZetaTextStyles.displayLarge] has not changed.
// expect(text3.style, text4.style);

// /// Test font size of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.fontSize, 16);

// /// Test line height of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.height, 24 / 16);

// /// Test font weight of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.fontWeight, FontWeight.w400);
// });
// }
import 'package:flutter_test/flutter_test.dart';

void main() {
// const Key key1 = Key('1');
// const Key key2 = Key('2');
// const Key key3 = Key('3');
// const Key key4 = Key('4');

testWidgets('Text tokens', (tester) async {
// await tester.pumpWidget(
// TestWidget(
// widget: Builder(
// builder: (context) {
// return Column(
// children: [
// const Text(exampleText, key: key1),
// Text(exampleText, style: ZetaTextStyles.bodyMedium, key: key2),
// Text(exampleText, style: ZetaTextStyles.displayLarge, key: key3),
// Text(
// exampleText,
// style: TextStyle(fontSize: 52, fontWeight: FontWeight.w300, height: 60 / 52),
// key: key4,
// ),
// ],
// );
// },
// ),
// ),
// );

// final Finder zetaText1 = find.byKey(key1);
// final Finder zetaText2 = find.byKey(key2);
// final Finder zetaText3 = find.byKey(key3);
// final Finder zetaText4 = find.byKey(key4);

// final InlineSpan text1 =
// (find.descendant(of: zetaText1, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text2 =
// (find.descendant(of: zetaText2, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text3 =
// (find.descendant(of: zetaText3, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;
// final InlineSpan text4 =
// (find.descendant(of: zetaText4, matching: find.byType(RichText)).evaluate().first.widget as RichText).text;

// /// Test default in [Text] widget is [ZetaTextStyles.bodyMedium].
// expect(text1.style, text2.style);

// /// Test that [ZetaTextStyles.displayLarge] has not changed.
// expect(text3.style, text4.style);

// /// Test font size of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.fontSize, 16);

// /// Test line height of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.height, 24 / 16);

// /// Test font weight of [ZetaTextStyles.bodyMedium] is correct
// expect(text1.style!.fontWeight, FontWeight.w400);
expect(true, !false);
});
}
Loading

0 comments on commit e52c572

Please sign in to comment.