Add tests to AI scribe calculcateModalPosition
This commit is contained in:
@@ -67,7 +67,7 @@ Future<void> showAIScribeDialog({
|
||||
);
|
||||
|
||||
if (buttonPosition != null) {
|
||||
final position = _calculateModalPosition(
|
||||
final position = calculateModalPosition(
|
||||
context: context,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: AIScribeSizes.barWidth,
|
||||
@@ -127,7 +127,7 @@ Future<void> showAIScribeDialog({
|
||||
? screenSize.width * AIScribeSizes.mobileWidthPercentage
|
||||
: AIScribeSizes.modalMaxWidthLargeScreen;
|
||||
|
||||
final position = _calculateModalPosition(
|
||||
final position = calculateModalPosition(
|
||||
context: context,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: modalWidth,
|
||||
@@ -158,7 +158,7 @@ Future<void> showAIScribeDialog({
|
||||
);
|
||||
}
|
||||
|
||||
({double left, double bottom}) _calculateModalPosition({
|
||||
({double left, double bottom}) calculateModalPosition({
|
||||
required BuildContext context,
|
||||
required Offset buttonPosition,
|
||||
required double modalWidth,
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:scribe/scribe/ai/presentation/styles/ai_scribe_styles.dart';
|
||||
import 'package:scribe/scribe/ai/presentation/widgets/ai_scribe.dart';
|
||||
|
||||
void main() {
|
||||
group('calculateModalPosition::', () {
|
||||
testWidgets('should adjust left position when modal would go off-screen to the right', (tester) async {
|
||||
// Arrange
|
||||
const screenSize = Size(800, 600);
|
||||
const buttonPosition = Offset(700, 300); // Close to right edge
|
||||
const modalWidth = 440.0;
|
||||
BuildContext? capturedContext;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(size: screenSize),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
capturedContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Act
|
||||
final position = calculateModalPosition(
|
||||
context: capturedContext!,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: modalWidth,
|
||||
);
|
||||
|
||||
// Assert
|
||||
final expectedLeft = screenSize.width - modalWidth - AIScribeSizes.screenEdgePadding;
|
||||
expect(position.left, expectedLeft);
|
||||
});
|
||||
|
||||
testWidgets('should adjust left position to screenEdgePadding when modal would go off-screen to the left', (tester) async {
|
||||
// Arrange
|
||||
const screenSize = Size(800, 600);
|
||||
const buttonPosition = Offset(5, 300); // Very close to left edge
|
||||
const modalWidth = 440.0;
|
||||
BuildContext? capturedContext;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(size: screenSize),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
capturedContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Act
|
||||
final position = calculateModalPosition(
|
||||
context: capturedContext!,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: modalWidth,
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(position.left, AIScribeSizes.screenEdgePadding);
|
||||
});
|
||||
|
||||
testWidgets('should adjust bottom position when modal height is provided and would go off-screen to the top', (tester) async {
|
||||
// Arrange
|
||||
const screenSize = Size(800, 600);
|
||||
const buttonPosition = Offset(100, 50); // Close to top
|
||||
const modalWidth = 440.0;
|
||||
const modalHeight = 400.0;
|
||||
BuildContext? capturedContext;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(size: screenSize),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
capturedContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Act
|
||||
final position = calculateModalPosition(
|
||||
context: capturedContext!,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: modalWidth,
|
||||
modalHeight: modalHeight,
|
||||
);
|
||||
|
||||
// Assert
|
||||
final expectedBottom = screenSize.height - modalHeight - AIScribeSizes.screenEdgePadding;
|
||||
expect(position.bottom, expectedBottom);
|
||||
});
|
||||
|
||||
testWidgets('should adjust bottom position to screenEdgePadding when calculated bottom is too small', (tester) async {
|
||||
// Arrange
|
||||
const screenSize = Size(800, 600);
|
||||
const buttonPosition = Offset(100, 595); // Very close to bottom edge
|
||||
const modalWidth = 440.0;
|
||||
const modalHeight = 400.0;
|
||||
BuildContext? capturedContext;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: const MediaQueryData(size: screenSize),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
capturedContext = context;
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Act
|
||||
final position = calculateModalPosition(
|
||||
context: capturedContext!,
|
||||
buttonPosition: buttonPosition,
|
||||
modalWidth: modalWidth,
|
||||
modalHeight: modalHeight,
|
||||
);
|
||||
|
||||
// Assert
|
||||
// bottom = 600 - 595 + 8 = 13, which is < 16, so it should be adjusted to 16
|
||||
expect(position.bottom, AIScribeSizes.screenEdgePadding);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user