Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

test: add tests for pre generation hook #41

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions brick/hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ dependencies:
mason: ^0.1.0-dev.50

dev_dependencies:
mocktail: ^1.0.0
test: ^1.19.2
very_good_analysis: ^5.1.0
50 changes: 50 additions & 0 deletions brick/hooks/test/pre_gen_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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', () {
test('when specified is unmodified', () {
final vars = <String, String>{
'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(snake-case)`''',
() {
final vars = <String, String>{
'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',
);
},
);
});
});
}