Skip to content

Commit

Permalink
Revert "feat: Increasing coverage and adding way for people to add i1…
Browse files Browse the repository at this point in the history
…8n in their dynamic menu items. #4"

This reverts commit d1383a5.
  • Loading branch information
LuchoTurtle committed May 10, 2023
1 parent d1383a5 commit 9e92e64
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 63 deletions.
45 changes: 9 additions & 36 deletions assets/menu_items.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
{
"id": 1,
"index_in_level": 0,
"title": {
"en": "People",
"pt": "Pessoas"
},
"title": "People",
"text_color": "#Ffb97e",
"icon": {
"colour": "#Ffb97e",
Expand All @@ -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",
Expand All @@ -31,10 +25,7 @@
{
"id": 3,
"index_in_level": 0,
"title": {
"en": "Family",
"pt": "Família"
},
"title": "Family",
"text_color": "#FFFFFF",
"icon": {
"colour": "#Ffb97e",
Expand All @@ -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": []
}
Expand All @@ -76,10 +58,7 @@
{
"id": 7,
"index_in_level": 2,
"title": {
"en": "Work",
"pt": "Trabalho"
},
"title": "Work",
"text_color": "#FFFFFF",
"tiles": []
}
Expand All @@ -88,10 +67,7 @@
{
"id": 8,
"index_in_level": 1,
"title": {
"en": "Everyone",
"pt": "Todos"
},
"title": "Everyone",
"text_color": "#FFFFFF",
"tiles": []
}
Expand All @@ -100,10 +76,7 @@
{
"id": 9,
"index_in_level": 1,
"title": {
"en": "Potaro",
"pt": "Potaro"
},
"title": "Potaro",
"text_color": "#0baedc",
"tiles": []
}
Expand Down
2 changes: 1 addition & 1 deletion lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class MenuItemInfo {
Future<List<MenuItemInfo>> loadMenuItems() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();

//await prefs.remove(storageKey);
await prefs.remove(storageKey);

final String? jsonStringFromLocalStorage = prefs.getString(storageKey);

Expand Down
5 changes: 2 additions & 3 deletions test/models_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down
28 changes: 5 additions & 23 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -15,25 +13,16 @@ 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<String, Object> values = <String, Object>{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);
});

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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -285,20 +268,20 @@ 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();

expect(menuItemTitles, orderedEquals(["People", "Everyone", "Online Now", "Potaro"]));
});

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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand Down

0 comments on commit 9e92e64

Please sign in to comment.