Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Jul 10, 2024
1 parent dc0780a commit 717c0ce
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class VeryGoodCoreConfiguration extends Equatable {

/// Deserializes a [VeryGoodCoreConfiguration] from a `Map<String, dynamic>`
/// used to represent the configuration in the `HookContext.vars` map.
factory VeryGoodCoreConfiguration.fromHooksVars(Map<String, dynamic> vars) {
factory VeryGoodCoreConfiguration.fromHookVars(Map<String, dynamic> vars) {
final projectName =
vars[_VeryGoodCoreConfigurationVariables.projectName.key];
if (projectName is! String?) {
Expand Down
2 changes: 1 addition & 1 deletion very_good_core/hooks/pre_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:mason/mason.dart';
import 'package:very_good_core_hooks/very_good_core_hooks.dart';

void run(HookContext context) {
final configuration = VeryGoodCoreConfiguration.fromHooksVars(context.vars);
final configuration = VeryGoodCoreConfiguration.fromHookVars(context.vars);

context.vars = {
/// Below are all the variables that are accessible in the templates.
Expand Down
92 changes: 16 additions & 76 deletions very_good_core/hooks/test/pre_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,29 @@ void main() {
final vars = {
'project_name': 'my_app',
'org_name': 'com.example',
'application_id': 'app_id',
'application_id': 'app.id',
'description': 'A new Flutter project.',
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(
context.vars,
{
'project_name': 'my_app',
'org_name': 'com.example',
'application_id': 'app_id',
'description': 'A new Flutter project.',
'application_id_android': 'com.example.my_app',
'application_id': 'com.example.my-app',
},
);
});

group('application_id_android', () {
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);
final newVars = verify(() => context.vars = captureAny()).captured.last
as Map<String, dynamic>;

expect(context.vars['application_id_android'], '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_android'],
'org_name.project_name',
);
},
);
});

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(param-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',
);
},
expect(
newVars,
equals(
{
'project_name': 'my_app',
'org_name': 'com.example',
'description': 'A new Flutter project.',
'android_namespace': 'app.id',
'android_application_id': 'app.id',
'ios_application_id': 'app.id',
'windows_application_id': 'app.id',
},
),
);
});
});
Expand Down
34 changes: 34 additions & 0 deletions very_good_core/hooks/test/src/models/ios_application_id_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';
import 'package:very_good_core_hooks/very_good_core_hooks.dart';

void main() {
group('$IosApplicationId', () {
group('fallback', () {
test(
'concatenates organization name with project name in param case',
() {
const organizationName = 'com.example.hello-world';
const projectName = 'my app';
final iOsApplicationId = IosApplicationId.fallback(
organizationName: organizationName,
projectName: projectName,
);
expect(iOsApplicationId.value, 'com.example.hello-world.my-app');
},
);

test(
'ignores empty parts',
() {
const organizationName = 'com.example.hello_world';
const projectName = 'my app';
final iOsApplicationId = IosApplicationId.fallback(
organizationName: organizationName,
projectName: projectName,
);
expect(iOsApplicationId.value, 'com.example.hello-world.my-app');
},
);
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void main() {
});
});

group('fromHooksVars', () {
group('fromHookVars', () {
test('decodes as expected', () {
final vars = {
'project_name': 'very good app',
Expand All @@ -76,7 +76,7 @@ void main() {
'description': 'A Very Good App',
};

final configuration = VeryGoodCoreConfiguration.fromHooksVars(vars);
final configuration = VeryGoodCoreConfiguration.fromHookVars(vars);
expect(
configuration,
equals(
Expand All @@ -100,7 +100,7 @@ void main() {
final vars = <String, dynamic>{'project_name': 42};

expect(
() => VeryGoodCoreConfiguration.fromHooksVars(vars),
() => VeryGoodCoreConfiguration.fromHookVars(vars),
throwsA(
isA<ArgumentError>().having(
(error) => error.message,
Expand All @@ -115,7 +115,7 @@ void main() {
final vars = <String, dynamic>{'org_name': 42};

expect(
() => VeryGoodCoreConfiguration.fromHooksVars(vars),
() => VeryGoodCoreConfiguration.fromHookVars(vars),
throwsA(
isA<ArgumentError>().having(
(error) => error.message,
Expand All @@ -130,7 +130,7 @@ void main() {
final vars = <String, dynamic>{'application_id': 42};

expect(
() => VeryGoodCoreConfiguration.fromHooksVars(vars),
() => VeryGoodCoreConfiguration.fromHookVars(vars),
throwsA(
isA<ArgumentError>().having(
(error) => error.message,
Expand All @@ -145,7 +145,7 @@ void main() {
final vars = <String, dynamic>{'description': 42};

expect(
() => VeryGoodCoreConfiguration.fromHooksVars(vars),
() => VeryGoodCoreConfiguration.fromHookVars(vars),
throwsA(
isA<ArgumentError>().having(
(error) => error.message,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:test/test.dart';
import 'package:very_good_core_hooks/very_good_core_hooks.dart';

void main() {
group('$WindowsApplicationId', () {
group('fallback', () {
test(
'concatenates organization name with project name in param case',
() {
const organizationName = 'com.example.hello-world';
const projectName = 'my app';
final windowsApplicationId = WindowsApplicationId.fallback(
organizationName: organizationName,
projectName: projectName,
);
expect(windowsApplicationId.value, 'com.example.hello-world.my-app');
},
);

test(
'ignores empty parts',
() {
const organizationName = 'com.example.hello_world';
const projectName = 'my app';
final windowsApplicationId = WindowsApplicationId.fallback(
organizationName: organizationName,
projectName: projectName,
);
expect(windowsApplicationId.value, 'com.example.hello-world.my-app');
},
);
});
});
}

0 comments on commit 717c0ce

Please sign in to comment.