|
| 1 | +import 'dart:io'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:taskwarrior/app/utils/taskfunctions/profiles.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + late Directory testDirectory; |
| 7 | + late Profiles profiles; |
| 8 | + |
| 9 | + setUp(() async { |
| 10 | + testDirectory = await Directory.systemTemp.createTemp('test_directory'); |
| 11 | + profiles = Profiles(testDirectory); |
| 12 | + }); |
| 13 | + |
| 14 | + tearDown(() { |
| 15 | + testDirectory.deleteSync(recursive: true); |
| 16 | + }); |
| 17 | + |
| 18 | + test('Add and list profiles', () { |
| 19 | + var profileId = profiles.addProfile(); |
| 20 | + |
| 21 | + expect(profiles.listProfiles(), contains(profileId)); |
| 22 | + }); |
| 23 | + |
| 24 | + test('Set and get alias', () { |
| 25 | + var profileId = profiles.addProfile(); |
| 26 | + |
| 27 | + profiles.setAlias(profile: profileId, alias: 'Test Alias'); |
| 28 | + |
| 29 | + var alias = profiles.getAlias(profileId); |
| 30 | + expect(alias, 'Test Alias'); |
| 31 | + }); |
| 32 | + |
| 33 | + test('Set and get current profile', () { |
| 34 | + var profileId = profiles.addProfile(); |
| 35 | + |
| 36 | + profiles.setCurrentProfile(profileId); |
| 37 | + |
| 38 | + var currentProfile = profiles.getCurrentProfile(); |
| 39 | + expect(currentProfile, profileId); |
| 40 | + }); |
| 41 | + |
| 42 | + test('Delete profile', () { |
| 43 | + var profileId = profiles.addProfile(); |
| 44 | + |
| 45 | + profiles.deleteProfile(profileId); |
| 46 | + |
| 47 | + expect(profiles.listProfiles(), isNot(contains(profileId))); |
| 48 | + }); |
| 49 | + |
| 50 | + test('Copy configuration to new profile', () { |
| 51 | + var profileId = profiles.addProfile(); |
| 52 | + |
| 53 | + profiles.copyConfigToNewProfile(profileId); |
| 54 | + |
| 55 | + expect(Directory('${testDirectory.path}/profiles').listSync(), |
| 56 | + hasLength(greaterThan(1))); |
| 57 | + }); |
| 58 | + |
| 59 | + test('Get current storage', () { |
| 60 | + var profileId = profiles.addProfile(); |
| 61 | + profiles.setCurrentProfile(profileId); |
| 62 | + |
| 63 | + var storage = profiles.getCurrentStorage(); |
| 64 | + |
| 65 | + expect(storage, isNotNull); |
| 66 | + }); |
| 67 | +} |
0 commit comments