File size: 1,716 Bytes
b225a21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'package:auto_gpt_flutter_client/models/task.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('Task', () {
    // Test the properties of the Task class
    test('Task properties', () {
      final task = Task(id: 1, title: 'Test Task');

      expect(task.id, 1);
      expect(task.title, 'Test Task');
    });

    // Test Task.fromMap method
    test('Task.fromMap', () {
      final task = Task.fromMap({'id': 1, 'title': 'Test Task'});

      expect(task.id, 1);
      expect(task.title, 'Test Task');
    });

    // Test creating a Task with an empty title
    test('Task with empty title', () {
      expect(() => Task(id: 2, title: ''), throwsA(isA<AssertionError>()));
    });

    // Test that two Task objects with the same id and title are equal
    test('Two tasks with same properties are equal', () {
      final task1 = Task(id: 4, title: 'Same Task');
      final task2 = Task(id: 4, title: 'Same Task');

      expect(task1, task2);
    });

    // Test that toString() returns a string representation of the Task
    test('toString returns string representation', () {
      final task = Task(id: 5, title: 'Test toString');

      expect(task.toString(), 'Task(id: 5, title: Test toString)');
    });

    // Test that title of Task can be modified
    test('Modify task title', () {
      final task = Task(id: 6, title: 'Initial Title');
      task.title = 'Modified Title';

      expect(task.title, 'Modified Title');
    });

    // Test that setting an empty title throws an error
    test('Set empty title', () {
      final task = Task(id: 7, title: 'Valid Title');

      expect(() => task.title = '', throwsA(isA<ArgumentError>()));
    });
  });
}