Skip to content

Commit 5613823

Browse files
committed
test: added test for all files under lib/models/storage directory
1 parent 79b8b53 commit 5613823

File tree

5 files changed

+224
-0
lines changed

5 files changed

+224
-0
lines changed

test/models/storage/client_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:mockito/mockito.dart';
3+
import 'package:package_info_plus/package_info_plus.dart';
4+
import 'package:taskwarrior/app/models/storage/client.dart';
5+
6+
class MockPackageInfo extends Mock implements PackageInfo {}
7+
8+
void main() {
9+
group('client', () {
10+
test('should return package name and version', () async {
11+
PackageInfo.setMockInitialValues(
12+
appName: 'App',
13+
packageName: 'com.example.app',
14+
version: '1.0.0',
15+
buildNumber: '1',
16+
buildSignature: '',
17+
);
18+
19+
final result = await client();
20+
21+
expect(result, 'com.example.app 1.0.0');
22+
});
23+
});
24+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:io';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:mockito/annotations.dart';
4+
import 'package:taskwarrior/app/models/storage/exceptions/bad_certificate_exception.dart';
5+
import 'bad_certificate_exception_test.mocks.dart';
6+
7+
@GenerateMocks([X509Certificate])
8+
void main() {
9+
group('BadCertificateException', () {
10+
test('should create an instance with correct properties', () {
11+
final home = Directory('/mock/home');
12+
final mockCertificate = MockX509Certificate();
13+
14+
final exception =
15+
BadCertificateException(home: home, certificate: mockCertificate);
16+
17+
expect(exception.home, home);
18+
expect(exception.certificate, mockCertificate);
19+
});
20+
});
21+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Mocks generated by Mockito 5.4.4 from annotations
2+
// in taskwarrior/test/models/storage/exceptions/bad_certificate_exception_test.dart.
3+
// Do not manually edit this file.
4+
5+
// ignore_for_file: no_leading_underscores_for_library_prefixes
6+
import 'dart:io' as _i2;
7+
import 'dart:typed_data' as _i3;
8+
9+
import 'package:mockito/mockito.dart' as _i1;
10+
import 'package:mockito/src/dummies.dart' as _i4;
11+
12+
// ignore_for_file: type=lint
13+
// ignore_for_file: avoid_redundant_argument_values
14+
// ignore_for_file: avoid_setters_without_getters
15+
// ignore_for_file: comment_references
16+
// ignore_for_file: deprecated_member_use
17+
// ignore_for_file: deprecated_member_use_from_same_package
18+
// ignore_for_file: implementation_imports
19+
// ignore_for_file: invalid_use_of_visible_for_testing_member
20+
// ignore_for_file: prefer_const_constructors
21+
// ignore_for_file: unnecessary_parenthesis
22+
// ignore_for_file: camel_case_types
23+
// ignore_for_file: subtype_of_sealed_class
24+
25+
class _FakeDateTime_0 extends _i1.SmartFake implements DateTime {
26+
_FakeDateTime_0(
27+
Object parent,
28+
Invocation parentInvocation,
29+
) : super(
30+
parent,
31+
parentInvocation,
32+
);
33+
}
34+
35+
/// A class which mocks [X509Certificate].
36+
///
37+
/// See the documentation for Mockito's code generation for more information.
38+
class MockX509Certificate extends _i1.Mock implements _i2.X509Certificate {
39+
MockX509Certificate() {
40+
_i1.throwOnMissingStub(this);
41+
}
42+
43+
@override
44+
_i3.Uint8List get der => (super.noSuchMethod(
45+
Invocation.getter(#der),
46+
returnValue: _i3.Uint8List(0),
47+
) as _i3.Uint8List);
48+
49+
@override
50+
String get pem => (super.noSuchMethod(
51+
Invocation.getter(#pem),
52+
returnValue: _i4.dummyValue<String>(
53+
this,
54+
Invocation.getter(#pem),
55+
),
56+
) as String);
57+
58+
@override
59+
_i3.Uint8List get sha1 => (super.noSuchMethod(
60+
Invocation.getter(#sha1),
61+
returnValue: _i3.Uint8List(0),
62+
) as _i3.Uint8List);
63+
64+
@override
65+
String get subject => (super.noSuchMethod(
66+
Invocation.getter(#subject),
67+
returnValue: _i4.dummyValue<String>(
68+
this,
69+
Invocation.getter(#subject),
70+
),
71+
) as String);
72+
73+
@override
74+
String get issuer => (super.noSuchMethod(
75+
Invocation.getter(#issuer),
76+
returnValue: _i4.dummyValue<String>(
77+
this,
78+
Invocation.getter(#issuer),
79+
),
80+
) as String);
81+
82+
@override
83+
DateTime get startValidity => (super.noSuchMethod(
84+
Invocation.getter(#startValidity),
85+
returnValue: _FakeDateTime_0(
86+
this,
87+
Invocation.getter(#startValidity),
88+
),
89+
) as DateTime);
90+
91+
@override
92+
DateTime get endValidity => (super.noSuchMethod(
93+
Invocation.getter(#endValidity),
94+
returnValue: _FakeDateTime_0(
95+
this,
96+
Invocation.getter(#endValidity),
97+
),
98+
) as DateTime);
99+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:taskwarrior/app/models/storage/exceptions/taskserver_configuration_exception.dart';
3+
4+
void main() {
5+
group('TaskserverConfigurationException', () {
6+
test('should create an instance with correct message', () {
7+
const message = 'Configuration error';
8+
final exception = TaskserverConfigurationException(message);
9+
10+
expect(exception.message, message);
11+
expect(exception.toString(), message);
12+
});
13+
});
14+
}

test/models/storage/tabs_test.dart

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import 'dart:io';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:taskwarrior/app/models/storage/tabs.dart';
4+
import 'package:uuid/uuid.dart';
5+
6+
void main() {
7+
late Directory testProfile;
8+
late Tabs tabs;
9+
10+
setUp(() {
11+
testProfile = Directory(
12+
'${Directory.systemTemp.path}/test_profile_${const Uuid().v1()}');
13+
testProfile.createSync();
14+
tabs = Tabs(testProfile);
15+
});
16+
17+
tearDown(() {
18+
if (testProfile.existsSync()) {
19+
testProfile.deleteSync(recursive: true);
20+
}
21+
});
22+
group("Tabs test", () {
23+
test('Initial tab index defaults to 0', () {
24+
expect(tabs.initialTabIndex(), 0);
25+
});
26+
27+
test('Can set and get initial tab index', () {
28+
tabs.setInitialTabIndex(2);
29+
expect(tabs.initialTabIndex(), 2);
30+
});
31+
32+
test('Can add a new tab', () {
33+
var initialTabCount = tabs.tabUuids().length;
34+
tabs.addTab();
35+
expect(tabs.tabUuids().length, initialTabCount + 1);
36+
});
37+
38+
test('Can remove a tab', () {
39+
var initialTabCount = tabs.tabUuids().length;
40+
tabs.addTab();
41+
tabs.removeTab(0);
42+
expect(tabs.tabUuids().length, initialTabCount);
43+
});
44+
45+
test('Removing a tab updates the initial index', () {
46+
tabs.addTab();
47+
tabs.addTab();
48+
tabs.setInitialTabIndex(1);
49+
tabs.removeTab(1);
50+
expect(tabs.initialTabIndex(), 0);
51+
});
52+
53+
test('Can rename a tab and retrieve its alias', () {
54+
tabs.addTab();
55+
var tabUuid = tabs.tabUuids().first;
56+
tabs.renameTab(tab: tabUuid, name: 'New Tab Name');
57+
expect(tabs.alias(tabUuid), 'New Tab Name');
58+
});
59+
60+
test('Alias returns null for non-existent alias files', () {
61+
tabs.addTab();
62+
var tabUuid = tabs.tabUuids().first;
63+
expect(tabs.alias(tabUuid), isNull);
64+
});
65+
});
66+
}

0 commit comments

Comments
 (0)