-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b12a971
commit 317a570
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/sprightly/test/features/settings/domain/entities/setting_entities_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:sprightly/features/settings/domain/entities/setting_entities.dart'; | ||
import 'package:sprightly/models/constants/enums.dart'; | ||
import 'package:sprightly/models/repositories/settings.dart' as db; | ||
|
||
class MockDbAppSettings extends Mock implements db.AppSettings {} | ||
|
||
MockDbAppSettings mockSettings; | ||
|
||
void main() { | ||
testAppDetails(); | ||
testAppSettings(); | ||
} | ||
|
||
void testAppDetails() { | ||
AppDetails entity; | ||
group('test AppDetails', () { | ||
setUp(() { | ||
mockSettings = MockDbAppSettings(); | ||
// arrange | ||
when(mockSettings.appName).thenReturn('Sprightly'); | ||
when(mockSettings.packageName).thenReturn('com.marganam.sprightly'); | ||
when(mockSettings.version).thenReturn('1.0.0'); | ||
when(mockSettings.buildNumber).thenReturn('100'); | ||
when(mockSettings.dbVersion).thenReturn(1); | ||
|
||
// act | ||
entity = AppDetails.fromDB(mockSettings); | ||
}); | ||
tearDown(() { | ||
reset(mockSettings); | ||
}); | ||
test('success', () { | ||
// assert | ||
expect(entity, isA<AppDetails>()); | ||
expect(entity.appName, 'Sprightly'); | ||
expect(entity.packageName, 'com.marganam.sprightly'); | ||
expect(entity.version, '1.0.0'); | ||
expect(entity.buildNumber, '100'); | ||
expect(entity.dbVersion, 1); | ||
}); | ||
test('singleton instance', () { | ||
// re-arrange | ||
reset(mockSettings); | ||
final anotherEntity = AppDetails.fromDB(mockSettings); | ||
|
||
// assert | ||
expect(entity, anotherEntity); | ||
}); | ||
}); | ||
} | ||
|
||
void testAppSettings() { | ||
AppSettings entity; | ||
group('test AppSettings', () { | ||
setUp(() { | ||
mockSettings = MockDbAppSettings(); | ||
entity = AppSettings.fromDB(mockSettings); | ||
}); | ||
tearDown(() { | ||
reset(mockSettings); | ||
}); | ||
test('success', () { | ||
// arrange | ||
when(mockSettings.environment).thenReturn('Test'); | ||
when(mockSettings.debug).thenReturn(false); | ||
when(mockSettings.primarySetupComplete).thenReturn(false); | ||
when(mockSettings.themeMode).thenReturn(ThemeMode.Dark); | ||
|
||
// assert | ||
expect(entity, isA<AppSettings>()); | ||
expect(entity.environment, 'Test'); | ||
expect(entity.debug, false); | ||
expect(entity.primarySetupComplete, false); | ||
expect(entity.themeMode, ThemeMode.Dark); | ||
}); | ||
test('singleton instance', () { | ||
// act | ||
final anotherEntity = AppSettings.fromDB(mockSettings); | ||
|
||
// assert | ||
expect(entity, anotherEntity); | ||
}); | ||
}); | ||
} |