Skip to content

Commit

Permalink
chore: code coverage 100% (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro authored Jan 28, 2025
1 parent d8362e5 commit c27262f
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/flutter-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./lcov.info
files: ./coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
directory: packages/disco
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)
[![Coverage](https://codecov.io/gh/our-creativity/disco/graph/badge.svg?token=Z19R32RJ22)](https://codecov.io/gh/our-creativity/disco)
[![GitHub issues](https://img.shields.io/github/issues/our-creativity/disco)](https://github.com/our-creativity/disco/issues/)
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/our-creativity/disco.svg)](https://gitHub.com/our-creativity/disco/pull/)
[![pub.dev Version (including pre-releases)](https://img.shields.io/pub/v/disco?include_prereleases)](https://pub.dev/packages/disco)
[![GitHub stars](https://img.shields.io/github/stars/our-creativity/disco)](https://gitHub.com/our-creativity/disco/stargazers/)

# Disco

<img src="https://raw.githubusercontent.com/our-creativity/disco/main/assets/disco.jpeg" height="400">
Expand Down
4 changes: 4 additions & 0 deletions packages/disco/lib/src/widgets/provider_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ class _InheritedProvider extends InheritedModel<Object> {

final ProviderScopeState state;

// coverage:ignore-start
@override
bool updateShouldNotify(covariant _InheritedProvider oldWidget) {
return false;
}
// coverage:ignore-end

bool isSupportedAspectWithType(
Provider? providerId,
Expand All @@ -391,13 +393,15 @@ class _InheritedProvider extends InheritedModel<Object> {
return state.isArgProviderInScope(argProviderId!);
}

// coverage:ignore-start
@override
bool updateShouldNotifyDependent(
covariant _InheritedProvider oldWidget,
Set<dynamic> dependencies,
) {
return false;
}
// coverage:ignore-end

/// The following two methods are taken from [InheritedModel] and modified
/// in order to find the first [_InheritedProvider] ancestor that contains
Expand Down
2 changes: 2 additions & 0 deletions packages/disco/lib/src/widgets/provider_scope_portal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class _InheritedProviderScopePortal extends InheritedWidget {

final BuildContext mainContext;

// coverage:ignore-start
@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
return false;
}
// coverage:ignore-end
}

/// {@template ProviderScopePortal}
Expand Down
148 changes: 148 additions & 0 deletions packages/disco/test/disco_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,53 @@ void main() {

expect(providerFinder(1, 100), findsOneWidget);
});
testWidgets('Test Provider.withArgument', (tester) async {
final doubleCountProvider =
Provider.withArgument((context, int arg) => arg * 2);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProviderScope(
providers: [doubleCountProvider(3)],
child: Builder(
builder: (context) {
final doubleCount = doubleCountProvider.of(context);
return Text(doubleCount.toString());
},
),
),
),
),
);

expect(find.text('6'), findsOneWidget);
});

testWidgets('Test Provider.withArgument not lazy', (tester) async {
var fired = false;

final doubleCountProvider = Provider.withArgument(
(context, int arg) {
fired = true;
return arg * 2;
},
lazy: false,
);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProviderScope(
providers: [doubleCountProvider(3)],
child: const Text('hello'),
),
),
),
);

expect(fired, true);
});

testWidgets('Test Provider.of within Provider create fn', (tester) async {
final numberProvider = Provider((_) => 5);
Expand Down Expand Up @@ -121,6 +168,59 @@ void main() {
);
});

testWidgets(
'''Test ProviderScope throws ArgProviderWithoutScopeError for a not found ArgProvider''',
(tester) async {
final numberProvider = Provider.withArgument((context, int arg) => arg);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) {
final ten = numberProvider.of(context);
return Text(ten.toString());
},
),
),
),
);
expect(
tester.takeException(),
const TypeMatcher<ArgProviderWithoutScopeError>().having(
(error) => error.argProvider,
'Matching the wrong ID should result in a ProviderError.',
equals(numberProvider),
),
);
});

testWidgets(
'''Test ProviderScope throws MultipleProviderOfSameInstance for multiple instances of ArgProvider''',
(tester) async {
final numberProvider = Provider.withArgument((context, int arg) => arg);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProviderScope(
providers: [numberProvider(1), numberProvider(2)],
child: Builder(
builder: (context) {
final ten = numberProvider.of(context);
return Text(ten.toString());
},
),
),
),
),
);
expect(
tester.takeException(),
const TypeMatcher<MultipleProviderOfSameInstance>(),
);
});

testWidgets(
'Test ProviderScope returns null for a not found provider (maybeOf)',
(tester) async {
Expand Down Expand Up @@ -566,4 +666,52 @@ void main() {
findsOneWidget,
);
});
testWidgets(
'''ProviderScopeOverride must throw a MultipleProviderOverrideOfSameProviderInstance for duplicated providers''',
(tester) async {
final numberProvider = Provider<int>((context) => 0);
await tester.pumpWidget(
ProviderScopeOverride(
overrides: [
numberProvider.overrideWithValue(1),
numberProvider.overrideWithValue(2),
],
child: const Text('hello'),
),
);

expect(
tester.takeException(),
const TypeMatcher<MultipleProviderOverrideOfSameProviderInstance>(),
);
});

testWidgets(
'''Test ProviderScopeOverride throws MultipleProviderOfSameInstance for multiple instances of ArgProvider''',
(tester) async {
final numberProvider = Provider.withArgument((context, int arg) => arg);

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ProviderScopeOverride(
overrides: [
numberProvider.overrideWithValue(1),
numberProvider.overrideWithValue(2),
],
child: Builder(
builder: (context) {
final ten = numberProvider.of(context);
return Text(ten.toString());
},
),
),
),
),
);
expect(
tester.takeException(),
const TypeMatcher<MultipleProviderOfSameInstance>(),
);
});
}

0 comments on commit c27262f

Please sign in to comment.