Skip to content

Commit

Permalink
test(web): added tests for web icon generator
Browse files Browse the repository at this point in the history
  • Loading branch information
RatakondalaArun committed Jul 10, 2022
1 parent 3e2578e commit 96a54a5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
Binary file added test/assets/app_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/templates.dart
Expand Up @@ -18,6 +18,17 @@ flutter_icons:

const flavorFLIConfigTemplate = fliConfigTemplate;

const fliWebConfig = r'''
flutter_icons:
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 invlaidfliConfigTemplate = r'''
# flutter_icons
android: true
Expand Down
67 changes: 67 additions & 0 deletions test/web/web_icon_generator_test.dart
@@ -0,0 +1,67 @@
import 'dart:io';

import 'package:flutter_launcher_icons/abs/icon_generator.dart';
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
import 'package:flutter_launcher_icons/logger.dart';
import 'package:flutter_launcher_icons/web/web_icon_generator.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('WebIconGenerator', () {
late IconGeneratorContext context;
late IconGenerator generator;
late FlutterLauncherIconsConfig config;
late String prefixPath;
final assetPath = path.join(Directory.current.path, 'test', 'assets');

setUp(() async {
final imageFile = File(path.join(assetPath, 'app_icon.png'));
expect(imageFile.existsSync(), isTrue);
await d.dir('fli_test', [
d.dir('web', [
d.dir('icons'),
d.file('index.html', templates.webIndexTemplate),
d.file('manifest.json', templates.webManifestTemplate),
]),
d.file('flutter_launcher_icons.yaml', templates.fliWebConfig),
d.file('pubspec.yaml', templates.pubspecTemplate),
d.file('app_icon.png', imageFile.readAsBytesSync()),
]).create();
prefixPath = path.join(d.sandbox, 'fli_test');
config = FlutterLauncherIconsConfig.loadConfigFromPath('flutter_launcher_icons.yaml', prefixPath)!;
context = IconGeneratorContext(config: config, prefixPath: prefixPath, logger: FLILogger(false));
generator = WebIconGenerator(context);
});

// end to end test
test('should generate valid icons', () async {
expect(generator.validateRequirments(), isTrue);
generator.createIcons();
await expectLater(
d.dir('fli_test', [
d.dir('web', [
d.dir('icons', [
// this icons get created in fs
d.file('Icon-192.png', anything),
d.file('Icon-512.png', anything),
d.file('Icon-maskable-192.png', anything),
d.file('Icon-maskable-512.png', anything),
]),
// this favicon get created in fs
d.file('favicon.png', anything),
d.file('index.html', anything),
// this manifest.json get updated in fs
d.file('manifest.json', anything),
]),
d.file('flutter_launcher_icons.yaml', anything),
d.file('pubspec.yaml', templates.pubspecTemplate)
]).validate(),
completes,
);
});
});
}

0 comments on commit 96a54a5

Please sign in to comment.