Skip to content

Commit

Permalink
Merge pull request #19 from viralkachhadiya/master
Browse files Browse the repository at this point in the history
feat: Added unit test cases for helper classes
  • Loading branch information
oguzhnatly authored Aug 10, 2022
2 parents f333d4e + 4f9bce3 commit f0a1a6c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/helpers/carplay_helper_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter_carplay/flutter_carplay.dart';
import 'package:flutter_carplay/helpers/carplay_helper.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('FlutterCarplayHelper', () {
late FlutterCarplayHelper flutterCarplayHelper;

final cpListItem=CPListItem(text: '<CPListItem>');

final cpListTemplate = CPListTemplate(
title: '<CPListTemplate>',
sections: [
CPListSection(items: [cpListItem])
],
systemIcon: '<CarIcon>');

final templates = [
CPTabBarTemplate(title: '<CPTabBarTemplate>', templates: [cpListTemplate]),
cpListTemplate
];

setUp(() {
flutterCarplayHelper = FlutterCarplayHelper();
});

test('find CPListItem from dynamic list item and element id', () {
CPListItem? item = flutterCarplayHelper.findCPListItem(templates: templates, elementId: cpListItem.uniqueId);

expect(item, cpListItem);

CPListItem? nullableItem = flutterCarplayHelper.findCPListItem(
templates: templates, elementId: '');

expect(nullableItem, null);
});

test('make FCP channel id', () {
String channelId = flutterCarplayHelper.makeFCPChannelId(event: '/event');

expect(channelId, 'com.oguzhnatly.flutter_carplay/event');
});
});
}
30 changes: 30 additions & 0 deletions test/helpers/enum_utils_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter_carplay/flutter_carplay.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('CPEnumUtils', () {
test('convert string into any type of enum', () {
final cpListItemAccessoryType =
CPEnumUtils.enumFromString(CPListItemAccessoryTypes.values, 'cloud');

expect(cpListItemAccessoryType, CPListItemAccessoryTypes.cloud);

final cpListItemPlayingIndicatorLocation = CPEnumUtils.enumFromString(
CPListItemPlayingIndicatorLocations.values, 'trailing');

expect(cpListItemPlayingIndicatorLocation,
CPListItemPlayingIndicatorLocations.trailing);
});

test('convert dynamic type into string after the `.`', () {
final cpAlertActionStylesString = CPEnumUtils.stringFromEnum(CPAlertActionStyles.normal.toString());

expect(cpAlertActionStylesString, 'normal');

final fcpChannelTypesString =
CPEnumUtils.stringFromEnum('car.setAlert');

expect(fcpChannelTypesString, 'setAlert');
});
});
}

0 comments on commit f0a1a6c

Please sign in to comment.