diff --git a/.github/workflows/very_good_core_hooks.yaml b/.github/workflows/very_good_core_hooks.yaml new file mode 100644 index 00000000..735d6cb2 --- /dev/null +++ b/.github/workflows/very_good_core_hooks.yaml @@ -0,0 +1,21 @@ +name: very_good_core_hooks + +on: + pull_request: + paths: + - ".github/workflows/very_good_core_hooks.yaml" + - "brick/hooks/**" + push: + branches: + - main + paths: + - ".github/workflows/very_good_core_hooks.yaml" + - "brick/hooks/**" + +jobs: + build: + uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 + with: + working_directory: "brick/hooks" + analyze_directories: "test" + report_on: "pre_gen.dart" diff --git a/brick/hooks/pubspec.yaml b/brick/hooks/pubspec.yaml index 9ef2c47c..3ba9afb5 100644 --- a/brick/hooks/pubspec.yaml +++ b/brick/hooks/pubspec.yaml @@ -7,4 +7,6 @@ dependencies: mason: ^0.1.0-dev.50 dev_dependencies: - very_good_analysis: ^5.1.0 \ No newline at end of file + mocktail: ^1.0.0 + test: ^1.19.2 + very_good_analysis: ^5.1.0 diff --git a/brick/hooks/test/pre_gen_test.dart b/brick/hooks/test/pre_gen_test.dart new file mode 100644 index 00000000..ef10f41a --- /dev/null +++ b/brick/hooks/test/pre_gen_test.dart @@ -0,0 +1,83 @@ +import 'package:mason/mason.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:test/test.dart'; + +import '../pre_gen.dart' as pre_gen; + +class _MockHookContext extends Mock implements HookContext {} + +void main() { + group('pre_gen', () { + late HookContext context; + + setUp(() { + context = _MockHookContext(); + }); + + group('application_id_android', () { + test('when specified is unmodified', () { + final vars = { + 'project_name': 'project_name', + 'org_name': 'org_name', + 'application_id': 'com.example.app', + }; + when(() => context.vars).thenReturn(vars); + + pre_gen.run(context); + + expect(context.vars['application_id_android'], 'com.example.app'); + }); + + test( + '''when not specified is set to `org_name + "." + project_name(snake_case)`''', + () { + final vars = { + 'project_name': 'Project Name', + 'org_name': 'org_name', + }; + when(() => context.vars).thenReturn(vars); + + pre_gen.run(context); + + expect( + context.vars['application_id_android'], + 'org_name.project_name', + ); + }, + ); + }); + + group('application_id', () { + test('when specified is unmodified', () { + final vars = { + 'project_name': 'project_name', + 'org_name': 'org_name', + 'application_id': 'com.example.app', + }; + when(() => context.vars).thenReturn(vars); + + pre_gen.run(context); + + expect(context.vars['application_id'], 'com.example.app'); + }); + + test( + '''when not specified is set to `org_name + "." + project_name(param-case)`''', + () { + final vars = { + 'project_name': 'Project Name', + 'org_name': 'org_name', + }; + when(() => context.vars).thenReturn(vars); + + pre_gen.run(context); + + expect( + context.vars['application_id'], + 'org_name.project-name', + ); + }, + ); + }); + }); +}