Skip to content

Commit

Permalink
fix(test): fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasleyba committed May 6, 2024
1 parent 25de3f8 commit 0a4942c
Show file tree
Hide file tree
Showing 34 changed files with 160 additions and 114 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ads_consent_client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: ads_consent_client

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
paths:
- "flutter_news_example/packages/ads_consent_client/**"
- ".github/workflows/ads_consent_client.yaml"
branches:
- main

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
with:
flutter_version: 3.16.9
working_directory: flutter_news_example/packages/ads_consent_client
coverage_excludes: "lib/src/generated/*.dart"
5 changes: 4 additions & 1 deletion .github/workflows/news_blocks_ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
with:
flutter_version: 3.10.2
flutter_version: 3.16.9
working_directory: flutter_news_example/packages/news_blocks_ui
coverage_excludes: "lib/src/generated/*.dart"
# Due to incompability with custom goldenFileComparator,
# reference: flutter_news_example/packages/news_blocks_ui/test/helpers/tolerant_comparator.dart
test_optimization: false
1 change: 1 addition & 0 deletions flutter_news_example/.vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"serializable",
"shollister",
"signup",
"sqflite",
"Sonifications",
"Stepien",
"sublist",
Expand Down
2 changes: 2 additions & 0 deletions flutter_news_example/packages/news_blocks_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ dependencies:
sdk: flutter
flutter_html: 3.0.0-beta.2
google_mobile_ads: ^5.0.0
html: ^0.15.4
news_blocks:
path: ../../api/packages/news_blocks
path_provider_platform_interface: ^2.0.5
platform: ^3.1.0
plugin_platform_interface: ^2.1.3
sqflite_common_ffi: ^2.3.2+1
url_launcher: ^6.1.7
url_launcher_platform_interface: ^2.1.1
video_player: ^2.7.0
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 80 additions & 79 deletions flutter_news_example/packages/news_blocks_ui/test/src/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:app_ui/app_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart' as flutter_html;
import 'package:flutter_test/flutter_test.dart';
import 'package:html/dom.dart' as dom;
import 'package:mocktail/mocktail.dart';
import 'package:news_blocks/news_blocks.dart';
import 'package:news_blocks_ui/news_blocks_ui.dart';
Expand All @@ -18,9 +19,12 @@ class _MockUrlLauncher extends Mock

class _FakeLaunchOptions extends Fake implements LaunchOptions {}

class _MockDomElement extends Mock implements dom.Element {}

void main() {
group('Html', () {
late UrlLauncherPlatform urlLauncher;
final domElement = _MockDomElement();

setUpAll(() {
registerFallbackValue(_FakeLaunchOptions());
Expand All @@ -46,44 +50,53 @@ void main() {
});

group('hyperlinks', () {
testWidgets('does not launch the url when it is empty', (tester) async {
testWidgets('does not launch the url when it is null', (tester) async {
const String? link = null;
const block = HtmlBlock(
content: '<a href="#">flutter.dev</a>',
content: '<a href="$link">flutter.dev</a>',
);

await tester.pumpApp(Html(block: block));

await tester.tap(
find.textContaining('flutter.dev', findRichText: true),
);
final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;

// workaround as taping a elements is not working.
widget.onLinkTap!(link, {}, domElement);

verifyNever(() => urlLauncher.launchUrl(any(), any()));
});

testWidgets('does not launch the url when it is invalid', (tester) async {
const link = '::Not valid URI::';
const block = HtmlBlock(
content: '<a href="::Not valid URI::">flutter.dev</a>',
content: '<a href="$link">flutter.dev</a>',
);

await tester.pumpApp(Html(block: block));

await tester.tap(
find.textContaining('flutter.dev', findRichText: true),
);
final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;

// workaround as taping a elements is not working.
widget.onLinkTap!(link, {}, domElement);

verifyNever(() => urlLauncher.launchUrl(any(), any()));
});

testWidgets('launches the url when it is a valid url', (tester) async {
const link = 'https://flutter.dev';
const block = HtmlBlock(
content: '<a href="https://flutter.dev">flutter.dev</a>',
content: '<a href="$link">flutter.dev</a>',
);

await tester.pumpApp(Html(block: block));

await tester.tap(
find.textContaining('flutter.dev', findRichText: true),
);
final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;

// workaround as taping a elements is not working.
widget.onLinkTap!(link, {}, domElement);

verify(
() => urlLauncher.launchUrl('https://flutter.dev', any()),
Expand Down Expand Up @@ -128,17 +141,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h1']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.displayLarge!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.displayLarge!.copyWith(letterSpacing: -0.25),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h1']!.generateTextStyle();

expect(style, expectedStyle);
});

testWidgets('<h2> tags correctly', (tester) async {
Expand All @@ -153,17 +164,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h2']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.displayMedium!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.displayMedium!.copyWith(letterSpacing: 0),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h2']!.generateTextStyle();

expect(style, expectedStyle);
});

testWidgets('<h3> tags correctly', (tester) async {
Expand All @@ -178,17 +187,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h3']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.displaySmall!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.displaySmall!.copyWith(letterSpacing: 0),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h3']!.generateTextStyle();

expect(style, expectedStyle);
});

testWidgets('<h4> tags correctly', (tester) async {
Expand All @@ -203,17 +210,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h4']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.headlineMedium!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.headlineMedium!.copyWith(letterSpacing: 0),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h4']!.generateTextStyle();

expect(style, expectedStyle);
});

testWidgets('<h5> tags correctly', (tester) async {
Expand All @@ -228,17 +233,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h5']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.headlineSmall!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.headlineSmall!.copyWith(letterSpacing: 0),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h5']!.generateTextStyle();

expect(style, expectedStyle);
});

testWidgets('<h6> tags correctly', (tester) async {
Expand All @@ -253,17 +256,15 @@ void main() {
),
);

expect(
find.byWidgetPredicate(
(widget) =>
widget is flutter_html.Html &&
widget.style['h6']!.generateTextStyle() ==
flutter_html.Style.fromTextStyle(
theme.textTheme.titleLarge!,
).generateTextStyle(),
),
findsOneWidget,
);
final expectedStyle = flutter_html.Style.fromTextStyle(
theme.textTheme.titleLarge!.copyWith(letterSpacing: 0),
).generateTextStyle();

final widget =
tester.widget(find.byType(flutter_html.Html)) as flutter_html.Html;
final style = widget.style['h6']!.generateTextStyle();

expect(style, expectedStyle);
});
});
});
Expand Down
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.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail_image_network/mocktail_image_network.dart';
import 'package:news_blocks/news_blocks.dart';
import 'package:news_blocks_ui/news_blocks_ui.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

import '../../helpers/helpers.dart';

void main() {
setUpAll(() {
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;

setUpTolerantComparator();
setUpMockPathProvider();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail_image_network/mocktail_image_network.dart';
import 'package:news_blocks/news_blocks.dart';
import 'package:news_blocks_ui/news_blocks_ui.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

import '../helpers/helpers.dart';

void main() {
group('PostSmall', () {
setUpAll(() {
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;

setUpTolerantComparator();
setUpMockPathProvider();
});
Expand Down
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.
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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail_image_network/mocktail_image_network.dart';
import 'package:news_blocks/news_blocks.dart';
import 'package:news_blocks_ui/news_blocks_ui.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

import '../helpers/helpers.dart';

void main() {
group('TrendingStory', () {
setUpAll(() {
// Initialize FFI
sqfliteFfiInit();
// Change the default factory
databaseFactory = databaseFactoryFfi;

setUpTolerantComparator();
setUpMockPathProvider();
});
Expand Down
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

0 comments on commit 0a4942c

Please sign in to comment.