-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listener for airside logs + Widget to display airside logs #22
Changes from 30 commits
af6ceae
54d2d13
2f3cf5e
bc0432b
47ea3f2
88088a7
9409632
e96c835
ea6bb06
1d22293
ce1819e
4581d68
454dd4b
389fb00
9293379
ffaa035
54e89be
1ec4c89
3018222
0a03690
c54e01d
258522d
af52c86
73af95e
0f0e590
82fa1b6
1a34e0f
9bea345
482dcc8
7789072
e0c4893
6a2c81b
152cb9d
e304fcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'dart:io'; | ||
|
||
class GetAirsideLogs { | ||
final String pathToDirectory; | ||
|
||
GetAirsideLogs({required this.pathToDirectory}); | ||
|
||
List<File> getFiles() { | ||
return Directory(pathToDirectory) | ||
.listSync(recursive: true, followLinks: true) | ||
.whereType<File>() | ||
.toList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class LogDisplayerScreen extends StatelessWidget { | ||
final String fileContext; | ||
final String fileName; | ||
const LogDisplayerScreen( | ||
{Key? key, required this.fileContext, required this.fileName}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(fileName), | ||
), | ||
body: SingleChildScrollView( | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text(fileContext), | ||
), | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:imacs/modules/get_airside_logs.dart'; | ||
import 'package:imacs/screens/log_displayer_screen.dart'; | ||
|
||
class LogsList extends StatelessWidget { | ||
const LogsList({ | ||
super.key, | ||
required this.getAirsideLogs, | ||
}); | ||
|
||
final GetAirsideLogs getAirsideLogs; | ||
|
||
static Route _logDisplayerRoute(BuildContext context, Object? arguments) { | ||
final args = arguments as Map<String, String>; | ||
return MaterialPageRoute( | ||
builder: (context) => LogDisplayerScreen( | ||
fileContext: args['fileContent']!, fileName: args['fileName']!), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: SizedBox( | ||
width: 600, | ||
child: AspectRatio( | ||
aspectRatio: 4 / 3, | ||
child: ListView.builder( | ||
itemCount: getAirsideLogs.getFiles().length, | ||
itemBuilder: (context, index) { | ||
List<String> filePath = | ||
getAirsideLogs.getFiles()[index].uri.pathSegments; | ||
String fileName = filePath.length == 1 | ||
? filePath.last | ||
: filePath | ||
.sublist(filePath.length - 2, filePath.length) | ||
.join('/'); | ||
return Padding( | ||
BalajiLeninrajan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
padding: const EdgeInsets.all(8.0), | ||
child: Card( | ||
child: ListTile( | ||
title: Text(fileName), | ||
onTap: () { | ||
String fileContent = | ||
getAirsideLogs.getFiles()[index].readAsStringSync(); | ||
Navigator.of(context).restorablePush( | ||
_logDisplayerRoute, // restorable push wouldn't function without static method | ||
arguments: { | ||
'fileContent': fileContent, | ||
'fileName': fileName, | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:imacs/modules/get_airside_logs.dart'; | ||
import 'package:imacs/screens/log_displayer_screen.dart'; | ||
import 'package:imacs/widgets/display_all_logs_widget.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group( | ||
'Display All Logs Widget', | ||
() { | ||
testWidgets( | ||
'Displays airside logs by showing their respective path', | ||
(WidgetTester tester) async { | ||
const String pathToDirectory = 'C:\\Users\\emmao\\Documents\\logs'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CI/CD pipeline will fail with the current path, try creating a folder with test logs and pushing that as well. It's not that elegant, but it works (also use unix directory structure: ./folder/subfolder/etc.) |
||
final getAirsideLogs = | ||
GetAirsideLogs(pathToDirectory: pathToDirectory); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Scaffold( | ||
body: LogsList( | ||
getAirsideLogs: | ||
GetAirsideLogs(pathToDirectory: pathToDirectory), | ||
), | ||
), | ||
), | ||
); | ||
await tester.pump(); | ||
final expectedFiles = getAirsideLogs.getFiles(); | ||
|
||
final lastFile = expectedFiles.last; | ||
final lastFileSegments = lastFile.uri.pathSegments; | ||
final lastFileName = lastFileSegments.length == 1 | ||
? lastFileSegments.last | ||
: lastFileSegments | ||
.sublist(lastFileSegments.length - 2, lastFileSegments.length) | ||
.join('/'); | ||
|
||
final firstFile = expectedFiles.first; | ||
final firstFileSegments = firstFile.uri.pathSegments; | ||
final firstFileName = firstFileSegments.length == 1 | ||
? firstFileSegments.last | ||
: firstFileSegments | ||
.sublist( | ||
firstFileSegments.length - 2, firstFileSegments.length) | ||
.join('/'); | ||
|
||
//testing scroll | ||
await tester.drag( | ||
find.byType(SingleChildScrollView), const Offset(0, -400)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.text(lastFileName), | ||
findsOneWidget); // don't know if this effectively checks if it can scroll | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scrolling isn't something that can be tested well, checking for a |
||
|
||
// test if all files show up | ||
expect(find.byType(Card), findsNWidgets(expectedFiles.length)); | ||
|
||
// test that the names show up properly for each one | ||
for (var file in expectedFiles) { | ||
final filePath = file.uri.pathSegments; | ||
final fileName = filePath.length == 1 | ||
? filePath.last | ||
: filePath | ||
.sublist(filePath.length - 2, filePath.length) | ||
.join('/'); | ||
expect(find.text(fileName), findsOneWidget); | ||
} | ||
|
||
// testing tapping the first file | ||
await tester.tap(find.text(firstFileName)); | ||
await tester.pumpAndSettle(); | ||
|
||
//testing LogDisplayerScreen navigation | ||
final fileContent = firstFile.readAsStringSync(); | ||
expect(find.byType(LogDisplayerScreen), findsOneWidget); | ||
expect(find.text(fileContent), findsOneWidget); | ||
expect(find.text(firstFileName), findsOneWidget); | ||
}, | ||
); | ||
}, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove once you're done testing, there will be a task to add the widgets we've developed so far to main in the future