|
| 1 | +import 'package:flutter_launcher_icons/custom_exceptions.dart'; |
| 2 | +import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart'; |
| 3 | +import 'package:path/path.dart' as path; |
| 4 | +import 'package:test/test.dart'; |
| 5 | +import 'package:test_descriptor/test_descriptor.dart' as d; |
| 6 | + |
| 7 | +import './templates.dart' as templates; |
| 8 | + |
| 9 | +void main() { |
| 10 | + group('FlutterLauncherIconsConfig', () { |
| 11 | + late String prefixPath; |
| 12 | + setUpAll(() { |
| 13 | + prefixPath = path.join(d.sandbox, 'fli_test'); |
| 14 | + }); |
| 15 | + group('#loadConfigFromPath', () { |
| 16 | + setUpAll(() async { |
| 17 | + await d.dir('fli_test', [ |
| 18 | + d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate), |
| 19 | + d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate), |
| 20 | + ]).create(); |
| 21 | + }); |
| 22 | + test('should return valid configs', () { |
| 23 | + final configs = FlutterLauncherIconsConfig.loadConfigFromPath('flutter_launcher_icons.yaml', prefixPath); |
| 24 | + expect(configs, isNotNull); |
| 25 | + // android configs |
| 26 | + expect(configs!.android, isTrue); |
| 27 | + expect(configs.imagePath, isNotNull); |
| 28 | + expect(configs.imagePathAndroid, isNotNull); |
| 29 | + expect(configs.adaptiveIconBackground, isNotNull); |
| 30 | + expect(configs.adaptiveIconForeground, isNotNull); |
| 31 | + // ios configs |
| 32 | + expect(configs.ios, isTrue); |
| 33 | + expect(configs.imagePathIOS, isNotNull); |
| 34 | + // web configs |
| 35 | + expect(configs.webConfig, isNotNull); |
| 36 | + expect(configs.webConfig!.generate, isTrue); |
| 37 | + expect(configs.webConfig!.backgroundColor, isNotNull); |
| 38 | + expect(configs.webConfig!.imagePath, isNotNull); |
| 39 | + expect(configs.webConfig!.themeColor, isNotNull); |
| 40 | + expect( |
| 41 | + configs.webConfig!.toJson(), |
| 42 | + equals(<String, dynamic>{ |
| 43 | + 'generate': true, |
| 44 | + 'image_path': 'app_icon.png', |
| 45 | + 'background_color': '#0175C2', |
| 46 | + 'theme_color': '#0175C2', |
| 47 | + }), |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + test('should return null when invalid filePath is given', () { |
| 52 | + final configs = FlutterLauncherIconsConfig.loadConfigFromPath('file_that_dont_exist.yaml', prefixPath); |
| 53 | + expect(configs, isNull); |
| 54 | + }); |
| 55 | + |
| 56 | + test('should throw InvalidConfigException when config is invalid', () { |
| 57 | + expect( |
| 58 | + () => FlutterLauncherIconsConfig.loadConfigFromPath('invalid_fli_config.yaml', prefixPath), |
| 59 | + throwsA(isA<InvalidConfigException>()), |
| 60 | + ); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + group('#loadConfigFromPubSpec', () { |
| 65 | + setUpAll(() async { |
| 66 | + await d.dir('fli_test', [ |
| 67 | + d.file('pubspec.yaml', templates.pubspecTemplate), |
| 68 | + d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate), |
| 69 | + d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate), |
| 70 | + ]).create(); |
| 71 | + }); |
| 72 | + test('should return valid configs', () { |
| 73 | + final configs = FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath); |
| 74 | + expect(configs, isNotNull); |
| 75 | + // android configs |
| 76 | + expect(configs!.android, isTrue); |
| 77 | + expect(configs.imagePath, isNotNull); |
| 78 | + expect(configs.imagePathAndroid, isNotNull); |
| 79 | + expect(configs.adaptiveIconBackground, isNotNull); |
| 80 | + expect(configs.adaptiveIconForeground, isNotNull); |
| 81 | + // ios configs |
| 82 | + expect(configs.ios, isTrue); |
| 83 | + expect(configs.imagePathIOS, isNotNull); |
| 84 | + // web configs |
| 85 | + expect(configs.webConfig, isNotNull); |
| 86 | + expect(configs.webConfig!.generate, isTrue); |
| 87 | + expect(configs.webConfig!.backgroundColor, isNotNull); |
| 88 | + expect(configs.webConfig!.imagePath, isNotNull); |
| 89 | + expect(configs.webConfig!.themeColor, isNotNull); |
| 90 | + expect( |
| 91 | + configs.webConfig!.toJson(), |
| 92 | + equals(<String, dynamic>{ |
| 93 | + 'generate': true, |
| 94 | + 'image_path': 'app_icon.png', |
| 95 | + 'background_color': '#0175C2', |
| 96 | + 'theme_color': '#0175C2', |
| 97 | + }), |
| 98 | + ); |
| 99 | + }); |
| 100 | + |
| 101 | + group('should throw', () { |
| 102 | + setUp(() async { |
| 103 | + await d.dir('fli_test', [ |
| 104 | + d.file('pubspec.yaml', templates.invalidPubspecTemplate), |
| 105 | + d.file('flutter_launcher_icons.yaml', templates.fliConfigTemplate), |
| 106 | + d.file('invalid_fli_config.yaml', templates.invlaidfliConfigTemplate), |
| 107 | + ]).create(); |
| 108 | + }); |
| 109 | + test('InvalidConfigException when config is invalid', () { |
| 110 | + expect( |
| 111 | + () => FlutterLauncherIconsConfig.loadConfigFromPubSpec(prefixPath), |
| 112 | + throwsA(isA<InvalidConfigException>()), |
| 113 | + ); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | + group('#loadConfigFromFlavor', () { |
| 118 | + setUpAll(() async { |
| 119 | + await d.dir('fli_test', [ |
| 120 | + d.file('flutter_launcher_icons-development.yaml', templates.flavorFLIConfigTemplate), |
| 121 | + ]).create(); |
| 122 | + }); |
| 123 | + test('should return valid config', () { |
| 124 | + final configs = FlutterLauncherIconsConfig.loadConfigFromFlavor('development', prefixPath); |
| 125 | + expect(configs, isNotNull); |
| 126 | + expect(configs!.android, isTrue); |
| 127 | + expect(configs.imagePath, isNotNull); |
| 128 | + expect(configs.imagePathAndroid, isNotNull); |
| 129 | + expect(configs.adaptiveIconBackground, isNotNull); |
| 130 | + expect(configs.adaptiveIconForeground, isNotNull); |
| 131 | + // ios configs |
| 132 | + expect(configs.ios, isTrue); |
| 133 | + expect(configs.imagePathIOS, isNotNull); |
| 134 | + // web configs |
| 135 | + expect(configs.webConfig, isNotNull); |
| 136 | + expect(configs.webConfig!.generate, isTrue); |
| 137 | + expect(configs.webConfig!.backgroundColor, isNotNull); |
| 138 | + expect(configs.webConfig!.imagePath, isNotNull); |
| 139 | + expect(configs.webConfig!.themeColor, isNotNull); |
| 140 | + expect( |
| 141 | + configs.webConfig!.toJson(), |
| 142 | + equals(<String, dynamic>{ |
| 143 | + 'generate': true, |
| 144 | + 'image_path': 'app_icon.png', |
| 145 | + 'background_color': '#0175C2', |
| 146 | + 'theme_color': '#0175C2', |
| 147 | + }), |
| 148 | + ); |
| 149 | + }); |
| 150 | + }); |
| 151 | + }); |
| 152 | +} |
0 commit comments