Skip to content

Commit

Permalink
test(fli_config): added tests for fli config
Browse files Browse the repository at this point in the history
  • Loading branch information
RatakondalaArun committed Jul 10, 2022
1 parent 542e7fe commit d3c061d
Show file tree
Hide file tree
Showing 2 changed files with 401 additions and 0 deletions.
152 changes: 152 additions & 0 deletions test/flutter_launcher_icons_config_test.dart
@@ -0,0 +1,152 @@
import 'package:flutter_launcher_icons/custom_exceptions.dart';
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import './templates.dart' as templates;

void main() {
group('FlutterLauncherIconsConfig', () {
late String prefixPath;
setUpAll(() {
prefixPath = path.join(d.sandbox, 'fli_test');
});
group('#loadConfigFromPath', () {
setUpAll(() async {
await d.dir('fli_test', [
d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate),
d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate),
]).create();
});
test('should return valid configs', () {
final configs = FlutterLauncherIconsConfig.loadConfigFromPath('flutter_launcher_icons.yaml', prefixPath);
expect(configs, isNotNull);
// android configs
expect(configs!.android, isTrue);
expect(configs.imagePath, isNotNull);
expect(configs.imagePathAndroid, isNotNull);
expect(configs.adaptiveIconBackground, isNotNull);
expect(configs.adaptiveIconForeground, isNotNull);
// ios configs
expect(configs.ios, isTrue);
expect(configs.imagePathIOS, isNotNull);
// web configs
expect(configs.webConfig, isNotNull);
expect(configs.webConfig!.generate, isTrue);
expect(configs.webConfig!.backgroundColor, isNotNull);
expect(configs.webConfig!.imagePath, isNotNull);
expect(configs.webConfig!.themeColor, isNotNull);
expect(
configs.webConfig!.toJson(),
equals(<String, dynamic>{
'generate': true,
'image_path': 'app_icon.png',
'background_color': '#0175C2',
'theme_color': '#0175C2',
}),
);
});

test('should return null when invalid filePath is given', () {
final configs = FlutterLauncherIconsConfig.loadConfigFromPath('file_that_dont_exist.yaml', prefixPath);
expect(configs, isNull);
});

test('should throw InvalidConfigException when config is invalid', () {
expect(
() => FlutterLauncherIconsConfig.loadConfigFromPath('invalid_fli_config.yaml', prefixPath),
throwsA(isA<InvalidConfigException>()),
);
});
});

group('#loadConfigFromPubSpec', () {
setUpAll(() async {
await d.dir('fli_test', [
d.file('pubspec.yaml', templates.pubspecTemplate),
d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate),
d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate),
]).create();
});
test('should return valid configs', () {
final configs = FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath);
expect(configs, isNotNull);
// android configs
expect(configs!.android, isTrue);
expect(configs.imagePath, isNotNull);
expect(configs.imagePathAndroid, isNotNull);
expect(configs.adaptiveIconBackground, isNotNull);
expect(configs.adaptiveIconForeground, isNotNull);
// ios configs
expect(configs.ios, isTrue);
expect(configs.imagePathIOS, isNotNull);
// web configs
expect(configs.webConfig, isNotNull);
expect(configs.webConfig!.generate, isTrue);
expect(configs.webConfig!.backgroundColor, isNotNull);
expect(configs.webConfig!.imagePath, isNotNull);
expect(configs.webConfig!.themeColor, isNotNull);
expect(
configs.webConfig!.toJson(),
equals(<String, dynamic>{
'generate': true,
'image_path': 'app_icon.png',
'background_color': '#0175C2',
'theme_color': '#0175C2',
}),
);
});

group('should throw', () {
setUp(() async {
await d.dir('fli_test', [
d.file('pubspec.yaml', templates.invalidPubspecTemplate),
d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate),
d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate),
]).create();
});
test('InvalidConfigException when config is invalid', () {
expect(
() => FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath),
throwsA(isA<InvalidConfigException>()),
);
});
});
});
group('#loadConfigFromFlavor', () {
setUpAll(() async {
await d.dir('fli_test', [
d.file('flutter_launcher_icons-development.yaml', templates.flavorFLIConfigTemplate),
]).create();
});
test('should return valid config', () {
final configs = FlutterLauncherIconsConfig.loadConfigFromFlavor('development', prefixPath);
expect(configs, isNotNull);
expect(configs!.android, isTrue);
expect(configs.imagePath, isNotNull);
expect(configs.imagePathAndroid, isNotNull);
expect(configs.adaptiveIconBackground, isNotNull);
expect(configs.adaptiveIconForeground, isNotNull);
// ios configs
expect(configs.ios, isTrue);
expect(configs.imagePathIOS, isNotNull);
// web configs
expect(configs.webConfig, isNotNull);
expect(configs.webConfig!.generate, isTrue);
expect(configs.webConfig!.backgroundColor, isNotNull);
expect(configs.webConfig!.imagePath, isNotNull);
expect(configs.webConfig!.themeColor, isNotNull);
expect(
configs.webConfig!.toJson(),
equals(<String, dynamic>{
'generate': true,
'image_path': 'app_icon.png',
'background_color': '#0175C2',
'theme_color': '#0175C2',
}),
);
});
});
});
}

0 comments on commit d3c061d

Please sign in to comment.