From fbfcb82ab7b549830559db84027d14ac7d3d2610 Mon Sep 17 00:00:00 2001 From: Ammel <77129284+Ammelll@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:14:02 -0800 Subject: [PATCH] Fixed duplicate tests not being passed --- lib/pages/project/project_page.dart | 28 +++++++++++++++++++---- test/main_test.dart | 2 +- test/pages/project/project_page_test.dart | 13 ++++++++++- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/pages/project/project_page.dart b/lib/pages/project/project_page.dart index 91eb0701..7560c350 100644 --- a/lib/pages/project/project_page.dart +++ b/lib/pages/project/project_page.dart @@ -922,16 +922,20 @@ class _ProjectPageState extends State { String pathName = _paths[i].name; RegExp exp = RegExp(r'\(\d+\)'); String source = pathName.substring(pathName.length - 3); - while (pathNames.contains(pathName)) { + String originalPathName = pathName; + while (pathNames.contains(pathName) || pathName == '$originalPathName (0)') { + source = pathName.substring(pathName.length - 3); if (exp.hasMatch(source)) { RegExpMatch? match = exp.firstMatch(source); - int index = int.parse(match![0]!.substring(1, 2)) + 1; - pathName = '${pathName.substring(0, pathName.length - 3)}($index)'; + int index = int.parse(match![0]!.substring(1, 2)); + while(pathNames.contains(pathName) || pathName.substring(pathName.length-3) == '(0)'){ + index++; + pathName = '${pathName.substring(0, pathName.length - 3)}($index)'; + } } else { - pathName = '$pathName (1)'; + pathName = '$pathName (0)'; } } - setState(() { _paths.add(_paths[i].duplicate(pathName)); _sortPaths(_pathSortValue); @@ -1477,6 +1481,20 @@ class _ProjectPageState extends State { String autoName = _autos[i].name; RegExp exp = RegExp(r'\(\d+\)'); String source = autoName.substring(autoName.length - 3); + String originalAutoName = autoName; + while (autoNames.contains(autoName) || autoName == '$originalAutoName (0)') { + source = autoName.substring(autoName.length - 3); + if (exp.hasMatch(source)) { + RegExpMatch? match = exp.firstMatch(source); + int index = int.parse(match![0]!.substring(1, 2)); + while(autoNames.contains(autoName) || autoName.substring(autoName.length-3) == '(0)'){ + index++; + autoName = '${autoName.substring(0, autoName.length - 3)}($index)'; + } + } else { + autoName = '$autoName (0)'; + } + } while (autoNames.contains(autoName)) { if (exp.hasMatch(source)) { RegExpMatch? match = exp.firstMatch(source); diff --git a/test/main_test.dart b/test/main_test.dart index 881081f7..87c3631b 100644 --- a/test/main_test.dart +++ b/test/main_test.dart @@ -41,4 +41,4 @@ void main() { )); await widgetTester.pumpAndSettle(); }); -} +} \ No newline at end of file diff --git a/test/pages/project/project_page_test.dart b/test/pages/project/project_page_test.dart index 89a12315..e118548c 100644 --- a/test/pages/project/project_page_test.dart +++ b/test/pages/project/project_page_test.dart @@ -483,9 +483,20 @@ void main() { await widgetTester.tap(find.text('Duplicate')); await widgetTester.pumpAndSettle(); - + for (var element in widgetTester.allWidgets){ + print("TEXT ELEMENT " + element.toStringDeep()); + } expect(find.widgetWithText(ProjectItemCard, 'Example Path (2)'), findsOneWidget); + + await widgetTester.tap(menuButton); + await widgetTester.pumpAndSettle(); + + await widgetTester.tap(find.text('Duplicate')); + await widgetTester.pumpAndSettle(); + + expect(find.widgetWithText(ProjectItemCard, 'Example Path (3)'), + findsOneWidget); }); testWidgets('duplicate auto', (widgetTester) async {