Skip to content

Commit

Permalink
Merge branch 'main' into theme-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SGI-CAPP-AT2 committed Jan 11, 2025
2 parents 1c8b712 + 49bb285 commit 10bdf67
Show file tree
Hide file tree
Showing 15 changed files with 685 additions and 47 deletions.
29 changes: 17 additions & 12 deletions lib/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,23 @@ String baseUrl = 'http://YOUR_IP:8000';
String origin = 'http://localhost:8080';

Future<List<Tasks>> fetchTasks(String uuid, String encryptionSecret) async {
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';

var response = await http.get(Uri.parse(url), headers: {
"Content-Type": "application/json",
}).timeout(const Duration(seconds: 10000));
if (response.statusCode == 200) {
List<dynamic> allTasks = jsonDecode(response.body);
debugPrint(allTasks.toString());
return allTasks.map((task) => Tasks.fromJson(task)).toList();
} else {
throw Exception('Failed to load tasks');
try {
String url =
'$baseUrl/tasks?email=email&origin=$origin&UUID=$uuid&encryptionSecret=$encryptionSecret';

var response = await http.get(Uri.parse(url), headers: {
"Content-Type": "application/json",
}).timeout(const Duration(seconds: 10000));
if (response.statusCode == 200) {
List<dynamic> allTasks = jsonDecode(response.body);
debugPrint(allTasks.toString());
return allTasks.map((task) => Tasks.fromJson(task)).toList();
} else {
throw Exception('Failed to load tasks');
}
} catch (e) {
debugPrint('Error fetching tasks: $e');
return [];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class DetailRouteController extends GetxController {
void setAttribute(String name, dynamic newValue) {
modify.set(name, newValue);
onEdit.value = true;
if(name == 'start'){
debugPrint('Start Value Changed to $newValue');
startValue.value = newValue;
}
initValues();
}

Expand Down Expand Up @@ -82,7 +86,7 @@ class DetailRouteController extends GetxController {
statusValue.value = modify.draft.status;
entryValue.value = modify.draft.entry;
modifiedValue.value = modify.draft.modified;
startValue.value = modify.draft.start;
startValue.value ??= null;
endValue.value = modify.draft.end;
dueValue.value = modify.draft.due;
waitValue.value = modify.draft.wait;
Expand Down
13 changes: 12 additions & 1 deletion lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,18 @@ class HomeController extends GetxController {
final projectcontroller = TextEditingController();
var due = Rxn<DateTime>();
RxString dueString = ''.obs;
RxString priority = 'M'.obs;
final priorityList = ['L','X','M','H'];
final priorityColors = [
TaskWarriorColors.green,
TaskWarriorColors.grey,
TaskWarriorColors.yellow,
TaskWarriorColors.red,



];
RxString priority = 'X'.obs;

final tagcontroller = TextEditingController();
RxList<String> tags = <String>[].obs;
RxBool inThePast = false.obs;
Expand Down
62 changes: 41 additions & 21 deletions lib/app/modules/home/views/add_task_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,48 @@ class AddTaskBottomSheet extends StatelessWidget {
),
textAlign: TextAlign.left,
),
const SizedBox(width: 2,),
Obx(
() => DropdownButton<String>(
dropdownColor: tColors.dialogBackgroundColor,
value: homeController.priority.value,
elevation: 16,
style: GoogleFonts.poppins(
color: tColors.primaryTextColor,
),
underline: Container(
height: 1.5,
color: tColors.secondaryBackgroundColor,
),
onChanged: (String? newValue) {
homeController.priority.value = newValue!;
},
items: <String>['H', 'M', 'L', 'None']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(' $value'),
);
}).toList(),
() => Row(
children: [
for(int i=0;i<homeController.priorityList.length;i++)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.5),
child: GestureDetector(
onTap: () {
homeController.priority.value = homeController.priorityList[i];
debugPrint(homeController.priority.value);
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
height: 30,
width: 37,
decoration: BoxDecoration(

borderRadius: BorderRadius.circular(8),
border: Border.all(
color: homeController.priority.value == homeController.priorityList[i]
? tColors.primaryTextColor!
: tColors.primaryBackgroundColor!,
)
),
child: Center(
child: Text(
homeController.priorityList[i],
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontWeight: FontWeight.bold,
fontSize: 17,
color: homeController.priorityColors[i]
),
),
),
),

),
)

],
),
)
],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ packages:
source: hosted
version: "7.2.11"
built_collection:
dependency: transitive
dependency: "direct main"
description:
name: built_collection
sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100"
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ dev_dependencies:
build_runner: null
flutter_gen_runner: null
flutter_lints: 4.0.0
http_mock_adapter: ^0.3.0
sqflite_common_ffi: ^2.0.0

flutter_gen:
output: lib/app/utils/gen/
Expand Down
164 changes: 164 additions & 0 deletions test/api_service_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:http/http.dart' as http;
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:taskwarrior/api_service.dart';
import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart';

import 'api_service_test.mocks.dart';

class MockCredentialsStorage extends Mock implements CredentialsStorage {}

class MockMethodChannel extends Mock implements MethodChannel {}

@GenerateMocks([MockMethodChannel, http.Client])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

databaseFactory = databaseFactoryFfi;
MockClient mockClient = MockClient();

setUpAll(() {
sqfliteFfiInit();
});

group('Tasks model', () {
test('fromJson creates Tasks object', () {
final json = {
'id': 1,
'description': 'Task 1',
'project': 'Project 1',
'status': 'pending',
'uuid': '123',
'urgency': 5.0,
'priority': 'H',
'due': '2024-12-31',
'end': null,
'entry': '2024-01-01',
'modified': '2024-11-01',
};

final task = Tasks.fromJson(json);

expect(task.id, 1);
expect(task.description, 'Task 1');
expect(task.project, 'Project 1');
expect(task.status, 'pending');
expect(task.uuid, '123');
expect(task.urgency, 5.0);
expect(task.priority, 'H');
expect(task.due, '2024-12-31');
expect(task.entry, '2024-01-01');
expect(task.modified, '2024-11-01');
});

test('toJson converts Tasks object to JSON', () {
final task = Tasks(
id: 1,
description: 'Task 1',
project: 'Project 1',
status: 'pending',
uuid: '123',
urgency: 5.0,
priority: 'H',
due: '2024-12-31',
end: null,
entry: '2024-01-01',
modified: '2024-11-01',
);

final json = task.toJson();

expect(json['id'], 1);
expect(json['description'], 'Task 1');
expect(json['project'], 'Project 1');
expect(json['status'], 'pending');
expect(json['uuid'], '123');
expect(json['urgency'], 5.0);
expect(json['priority'], 'H');
expect(json['due'], '2024-12-31');
});
});

group('fetchTasks', () {
test('Fetch data successfully', () async {
final responseJson = jsonEncode({'data': 'Mock data'});
when(mockClient.get(
Uri.parse(
'$baseUrl/tasks?email=email&origin=$origin&UUID=123&encryptionSecret=secret'),
headers: {
"Content-Type": "application/json",
})).thenAnswer((_) async => http.Response(responseJson, 200));

final result = await fetchTasks('123', 'secret');

expect(result, isA<List<Tasks>>());
});

test('fetchTasks returns empty array', () async {
const uuid = '123';
const encryptionSecret = 'secret';

expect(await fetchTasks(uuid, encryptionSecret), isEmpty);
});
});

group('TaskDatabase', () {
late TaskDatabase taskDatabase;

setUp(() async {
taskDatabase = TaskDatabase();
await taskDatabase.open();
});

test('insertTask adds a task to the database', () async {
final task = Tasks(
id: 1,
description: 'Task 1',
project: 'Project 1',
status: 'pending',
uuid: '123',
urgency: 5.0,
priority: 'H',
due: '2024-12-31',
end: null,
entry: '2024-01-01',
modified: '2024-11-01',
);

await taskDatabase.insertTask(task);

final tasks = await taskDatabase.fetchTasksFromDatabase();

expect(tasks.length, 1);
expect(tasks[0].description, 'Task 1');
});

test('deleteAllTasksInDB removes all tasks', () async {
final task = Tasks(
id: 1,
description: 'Task 1',
project: 'Project 1',
status: 'pending',
uuid: '123',
urgency: 5.0,
priority: 'H',
due: '2024-12-31',
end: null,
entry: '2024-01-01',
modified: '2024-11-01',
);

await taskDatabase.insertTask(task);
await taskDatabase.deleteAllTasksInDB();

final tasks = await taskDatabase.fetchTasksFromDatabase();

expect(tasks.length, 0);
});
});
}
Loading

0 comments on commit 10bdf67

Please sign in to comment.