-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Extensions): add unit tests for context media query extensions
Signed-off-by: arafaysaleem <[email protected]>
- Loading branch information
1 parent
0503264
commit 0cf4f37
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import 'package:ez_ticketz_app/helper/extensions/context_extensions.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import 'context_extension_test.mocks.dart'; | ||
|
||
@GenerateMocks([BuildContext]) | ||
void main() { | ||
group('ContextUtils', () { | ||
group('extensions related to MediaQuery', () { | ||
BuildContext _mockContextWithMediaQuery(Size size) { | ||
final context = MockBuildContext(); | ||
final mediaQuery = MediaQuery( | ||
data: MediaQueryData(size: size), | ||
child: const SizedBox.shrink(), | ||
); | ||
when(context.widget).thenReturn(const SizedBox.shrink()); | ||
when(context.findAncestorWidgetOfExactType()).thenReturn(mediaQuery); | ||
when(context.dependOnInheritedWidgetOfExactType<MediaQuery>()) | ||
.thenReturn(mediaQuery); | ||
return context; | ||
} | ||
|
||
group('screenWidth', () { | ||
test( | ||
'GIVEN a Size created with a screen width ' | ||
'AND a BuildContext with MediaQuery ' | ||
'AND that MediaQuery has that Size ' | ||
'WHEN extension method `.screenWidth` is called ' | ||
'THEN a double is returned ' | ||
'AND is equal to that screen width', | ||
() { | ||
//given | ||
const screenWidth = 500.0; | ||
const size = Size.fromWidth(screenWidth); | ||
final context = _mockContextWithMediaQuery(size); | ||
|
||
//when | ||
final actual = context.screenWidth; | ||
|
||
//then | ||
expect(actual, isA<double>()); | ||
expect(actual, screenWidth); | ||
}, | ||
); | ||
}); | ||
|
||
group('screenHeight', () { | ||
test( | ||
'GIVEN a Size created with a screen height ' | ||
'AND a BuildContext with MediaQuery ' | ||
'AND that MediaQuery has that Size ' | ||
'WHEN extension method `.screenHeight` is called ' | ||
'THEN a double is returned ' | ||
'AND is equal to that screen height', | ||
() { | ||
//given | ||
const screenHeight = 650.0; | ||
const size = Size.fromHeight(screenHeight); | ||
final context = _mockContextWithMediaQuery(size); | ||
|
||
//when | ||
final actual = context.screenHeight; | ||
|
||
//then | ||
expect(actual, isA<double>()); | ||
expect(actual, screenHeight); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
} |