From 9e92e64fd48c63165854bd5604cb2e9d8c7250e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lui=CC=81s=20Arteiro?= Date: Wed, 10 May 2023 11:17:24 +0100 Subject: [PATCH] Revert "feat: Increasing coverage and adding way for people to add i18n in their dynamic menu items. #4" This reverts commit d1383a5e1e3271de6f409f844fe34f33cb9f3685. --- assets/menu_items.json | 45 +++++++++--------------------------------- lib/settings.dart | 2 +- test/models_test.dart | 5 ++--- test/widget_test.dart | 28 +++++--------------------- 4 files changed, 17 insertions(+), 63 deletions(-) diff --git a/assets/menu_items.json b/assets/menu_items.json index ccce298..dcbc3a4 100644 --- a/assets/menu_items.json +++ b/assets/menu_items.json @@ -2,10 +2,7 @@ { "id": 1, "index_in_level": 0, - "title": { - "en": "People", - "pt": "Pessoas" - }, + "title": "People", "text_color": "#Ffb97e", "icon": { "colour": "#Ffb97e", @@ -17,10 +14,7 @@ { "id": 2, "index_in_level": 0, - "title": { - "en": "Online Now", - "pt": "Online agora" - }, + "title": "Online Now", "text_color": "#FFFFFF", "icon": { "colour": "#Ffb97e", @@ -31,10 +25,7 @@ { "id": 3, "index_in_level": 0, - "title": { - "en": "Family", - "pt": "Família" - }, + "title": "Family", "text_color": "#FFFFFF", "icon": { "colour": "#Ffb97e", @@ -45,29 +36,20 @@ { "id": 4, "index_in_level": 1, - "title": { - "en": "Friends", - "pt": "Amigos" - }, + "title": "Friends", "text_color": "#FFFFFF", "tiles": [ { "id": 5, "index_in_level": 0, - "title": { - "en": "Sports Team", - "pt": "Clube" - }, + "title": "Sports Team", "text_color": "#FFFFFF", "tiles": [] }, { "id": 6, "index_in_level": 1, - "title": { - "en": "Gamerz", - "pt": "Gamerz" - }, + "title": "Gamerz", "text_color": "#FFFFFF", "tiles": [] } @@ -76,10 +58,7 @@ { "id": 7, "index_in_level": 2, - "title": { - "en": "Work", - "pt": "Trabalho" - }, + "title": "Work", "text_color": "#FFFFFF", "tiles": [] } @@ -88,10 +67,7 @@ { "id": 8, "index_in_level": 1, - "title": { - "en": "Everyone", - "pt": "Todos" - }, + "title": "Everyone", "text_color": "#FFFFFF", "tiles": [] } @@ -100,10 +76,7 @@ { "id": 9, "index_in_level": 1, - "title": { - "en": "Potaro", - "pt": "Potaro" - }, + "title": "Potaro", "text_color": "#0baedc", "tiles": [] } diff --git a/lib/settings.dart b/lib/settings.dart index 8e2e777..c33e06a 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -154,7 +154,7 @@ class MenuItemInfo { Future> loadMenuItems() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); - //await prefs.remove(storageKey); + await prefs.remove(storageKey); final String? jsonStringFromLocalStorage = prefs.getString(storageKey); diff --git a/test/models_test.dart b/test/models_test.dart index 8d49c8d..f9e15a6 100644 --- a/test/models_test.dart +++ b/test/models_test.dart @@ -3,10 +3,9 @@ import 'package:flutter_test/flutter_test.dart'; void main() { test('Menu item info model', () { - final title = {"en": "title", "pt": "título"}; - var item = MenuItemInfo(id: 0, title: title, tiles: []); + var item = MenuItemInfo(id: 0, title: 'title', tiles: []); - expect(item.title['en'], equals('title')); + expect(item.title, equals('title')); }); test('Menu item info icon model', () { diff --git a/test/widget_test.dart b/test/widget_test.dart index ba6384f..2338b4a 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -1,8 +1,6 @@ -import 'package:app/app_localization.dart'; import 'package:app/menu.dart'; import 'package:app/pages.dart'; import 'package:app/dynamic_menu.dart'; -import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -15,17 +13,9 @@ void main() { const storageKey = 'menuItems'; group('Open menu and simple navigation', () { - /// Function to set mock shared preferences in unit tests - setUp(() async { - final String jsonString = await rootBundle.loadString(jsonFilePath); - final Map values = {storageKey: jsonString}; - SharedPreferences.setMockInitialValues(values); - }); - testWidgets('Normal setup', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); // Verify that our counter starts at 0. expect(find.text('This is the main page'), findsOneWidget); @@ -33,7 +23,6 @@ void main() { testWidgets('Tapping on todo item should make menu button appear', (WidgetTester tester) async { await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -51,7 +40,6 @@ void main() { testWidgets('Tapping on icon menu should show drawer menu', (WidgetTester tester) async { await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -83,7 +71,6 @@ void main() { testWidgets('Navigating into Tours Page', (WidgetTester tester) async { await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -121,7 +108,6 @@ void main() { testWidgets('Navigating into Settings Page', (WidgetTester tester) async { await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -182,7 +168,6 @@ void main() { testWidgets('Normal setup with shared preferences should show dynamic menu', (WidgetTester tester) async { // Initialize app await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -205,7 +190,6 @@ void main() { testWidgets('Click on first expandable menu item', (WidgetTester tester) async { // Initialize app await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -240,7 +224,6 @@ void main() { testWidgets('Drag and drop nested elements', (WidgetTester tester) async { // Initialize app await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -267,7 +250,7 @@ void main() { var menuItemTitles = find.byType(MenuItem).evaluate().toList().map( (e) { var menuItem = e.widget as MenuItem; - return menuItem.info.title['en']; + return menuItem.info.title; }, ).toList(); @@ -285,7 +268,7 @@ void main() { menuItemTitles = find.byType(MenuItem).evaluate().toList().map( (e) { var menuItem = e.widget as MenuItem; - return menuItem.info.title['en']; + return menuItem.info.title; }, ).toList(); @@ -293,12 +276,12 @@ void main() { }); testWidgets('Drag and drop nested elements on third level', (WidgetTester tester) async { + // To mock the icons fetching images from Network. // See https://github.com/stelynx/network_image_mock. mockNetworkImagesFor(() async { // Initialize app await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -340,7 +323,6 @@ void main() { testWidgets('Drag and drop root elements', (WidgetTester tester) async { // Initialize app await tester.pumpWidget(const App()); - await tester.pumpAndSettle(); final menuButton = find.byKey(iconKey); final todoItem = find.byKey(todoItemKey); @@ -361,7 +343,7 @@ void main() { var menuItemTitles = find.byType(MenuItem).evaluate().toList().map( (e) { var menuItem = e.widget as MenuItem; - return menuItem.info.title['en']; + return menuItem.info.title; }, ).toList(); @@ -379,7 +361,7 @@ void main() { menuItemTitles = find.byType(MenuItem).evaluate().toList().map( (e) { var menuItem = e.widget as MenuItem; - return menuItem.info.title['en']; + return menuItem.info.title; }, ).toList();