From d3c061d572cfff14cb2d18462b04bc98d097ae84 Mon Sep 17 00:00:00 2001 From: Ratakondala Arun Date: Sun, 10 Jul 2022 12:54:04 +0530 Subject: [PATCH] test(fli_config): added tests for fli config --- test/flutter_launcher_icons_config_test.dart | 152 +++++++++++ test/templates.dart | 249 +++++++++++++++++++ 2 files changed, 401 insertions(+) create mode 100644 test/flutter_launcher_icons_config_test.dart create mode 100644 test/templates.dart diff --git a/test/flutter_launcher_icons_config_test.dart b/test/flutter_launcher_icons_config_test.dart new file mode 100644 index 0000000000..a73e414410 --- /dev/null +++ b/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({ + '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()), + ); + }); + }); + + 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({ + '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()), + ); + }); + }); + }); + 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({ + 'generate': true, + 'image_path': 'app_icon.png', + 'background_color': '#0175C2', + 'theme_color': '#0175C2', + }), + ); + }); + }); + }); +} diff --git a/test/templates.dart b/test/templates.dart new file mode 100644 index 0000000000..c50cde7875 --- /dev/null +++ b/test/templates.dart @@ -0,0 +1,249 @@ +const fliConfigTemplate = r''' +flutter_icons: + android: true + ios: true + image_path: "assets/images/icon-128x128.png" + image_path_android: "assets/images/icon-710x599-android.png" + image_path_ios: "assets/images/icon-1024x1024.png" + adaptive_icon_background: "assets/images/christmas-background.png" + adaptive_icon_foreground: "assets/images/icon-foreground-432x432.png" + web: + generate: true + image_path: "app_icon.png" # filepath + background_color: "#0175C2" # hex_color + theme_color: "#0175C2" # hex_color + apple_mobile_web_app_title: "demo" + apple_mobile_web_app_status_bar_style: "hex_color" +'''; + +const flavorFLIConfigTemplate = fliConfigTemplate; + +const invlaidfliConfigTemplate = r''' +# flutter_icons +android: true +ios: true +image_path: "assets/images/icon-128x128.png" + ad +image_path_android: "assets/images/icon-710x599-android.png" +image_path_ios: "assets/images/icon-1024x1024.png" +adaptive_icon_background: "assets/images/christmas-background.png" +adaptive_icon_foreground: "assets/images/icon-foreground-432x432.png" +web: + generate: true + image_path: "app_icon.png" # filepath + background_color: "#0175C2" # hex_color + theme_color: "#0175C2" # hex_color + apple_mobile_web_app_title: "demo" + apple_mobile_web_app_status_bar_style: "hex_color" +'''; + +const pubspecTemplate = r''' +name: demo +description: A new Flutter project. +publish_to: 'none' +version: 1.0.0+1 + +environment: + sdk: '>=2.18.0-44.1.beta <3.0.0' + +dependencies: + flutter: + sdk: flutter + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + flutter_launcher_icons: + path: C:/Users/asus/projects/flutter_launcher_icons + +flutter: + uses-material-design: true + assets: + - images/a_dot_burr.jpeg + - images/a_dot_ham.jpeg + fonts: + - family: Schyler + fonts: + - asset: fonts/Schyler-Regular.ttf + - asset: fonts/Schyler-Italic.ttf + style: italic + - family: Trajan Pro + fonts: + - asset: fonts/TrajanPro.ttf + - asset: fonts/TrajanPro_Bold.ttf + weight: 700 + +flutter_icons: + android: true + ios: true + image_path: "assets/images/icon-128x128.png" + image_path_android: "assets/images/icon-710x599-android.png" + image_path_ios: "assets/images/icon-1024x1024.png" + adaptive_icon_background: "assets/images/christmas-background.png" + adaptive_icon_foreground: "assets/images/icon-foreground-432x432.png" + web: + generate: true + image_path: "app_icon.png" # filepath + background_color: "#0175C2" # hex_color + theme_color: "#0175C2" # hex_color + apple_mobile_web_app_title: "demo" + apple_mobile_web_app_status_bar_style: "hex_color" +'''; + +const invalidPubspecTemplate = r''' +name: demo +description: A new Flutter project. +publish_to: 'none' +version: 1.0.0+1 + +environment: + sdk: '>=2.18.0-44.1.beta <3.0.0' + +dependencies: + flutter: + sdk: flutter + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + flutter_launcher_icons: + path: C:/Users/asus/projects/flutter_launcher_icons + +flutter: + uses-material-design: true + assets: + - images/a_dot_burr.jpeg + - images/a_dot_ham.jpeg + fonts: + - family: Schyler + fonts: + - asset: fonts/Schyler-Regular.ttf + - asset: fonts/Schyler-Italic.ttf + style: italic + - family: Trajan Pro + fonts: + - asset: fonts/TrajanPro.ttf + - asset: fonts/TrajanPro_Bold.ttf + weight: 700 + +flutter_icons: + android: true + invalid_indented_key_key + ios: true + image_path: "assets/images/icon-128x128.png" + image_path_android: "assets/images/icon-710x599-android.png" + image_path_ios: "assets/images/icon-1024x1024.png" + adaptive_icon_background: "assets/images/christmas-background.png" + adaptive_icon_foreground: "assets/images/icon-foreground-432x432.png" + web: + generate: true + image_path: "app_icon.png" # filepath + background_color: "#0175C2" # hex_color + theme_color: "#0175C2" # hex_color + apple_mobile_web_app_title: "demo" + apple_mobile_web_app_status_bar_style: "hex_color" +'''; + +const webManifestTemplate = r''' +{ + "name": "demo", + "short_name": "demo", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} +'''; + +const webIndexTemplate = r''' + + + + + + + + + + + + + + + + + + + + demo + + + + + + + + + + + +''';