summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2019-08-07 16:29:52 -0400
committerJoel Fischer <joeljfischer@gmail.com>2019-08-07 16:29:52 -0400
commitf0e6c968a2ac0ba47c36b192eb42655d2f358d46 (patch)
tree7ed652e5d9697f8eae2197bd86d2dc0f68ea8c97
parent4b0703159a535911d89a24692a0a37113402ed19 (diff)
downloadsdl_ios-f0e6c968a2ac0ba47c36b192eb42655d2f358d46.tar.gz
Add tests
-rw-r--r--SmartDeviceLink/SDLSoftButtonObject.h1
-rw-r--r--SmartDeviceLink/SDLSoftButtonObject.m5
-rw-r--r--SmartDeviceLinkTests/SDLSoftButtonObjectSpec.m31
3 files changed, 37 insertions, 0 deletions
diff --git a/SmartDeviceLink/SDLSoftButtonObject.h b/SmartDeviceLink/SDLSoftButtonObject.h
index abcb36d46..eb2512fca 100644
--- a/SmartDeviceLink/SDLSoftButtonObject.h
+++ b/SmartDeviceLink/SDLSoftButtonObject.h
@@ -10,6 +10,7 @@
#import "SDLNotificationConstants.h"
+@class SDLArtwork;
@class SDLSoftButton;
@class SDLSoftButtonObject;
@class SDLSoftButtonState;
diff --git a/SmartDeviceLink/SDLSoftButtonObject.m b/SmartDeviceLink/SDLSoftButtonObject.m
index 427421590..3d74c168a 100644
--- a/SmartDeviceLink/SDLSoftButtonObject.m
+++ b/SmartDeviceLink/SDLSoftButtonObject.m
@@ -53,6 +53,11 @@ NS_ASSUME_NONNULL_BEGIN
return [self initWithName:name states:@[state] initialStateName:state.name handler:eventHandler];
}
+- (instancetype)initWithName:(NSString *)name text:(nullable NSString *)text artwork:(nullable SDLArtwork *)artwork handler:(nullable SDLRPCButtonNotificationHandler)eventHandler {
+ SDLSoftButtonState *implicitState = [[SDLSoftButtonState alloc] initWithStateName:name text:text artwork:artwork];
+ return [self initWithName:name state:implicitState handler:eventHandler];
+}
+
- (BOOL)transitionToStateNamed:(NSString *)stateName {
if ([self stateWithName:stateName] == nil) {
SDLLogE(@"Attempted to transition to state: %@ on soft button: %@ but no state with that name was found", stateName, self.name);
diff --git a/SmartDeviceLinkTests/SDLSoftButtonObjectSpec.m b/SmartDeviceLinkTests/SDLSoftButtonObjectSpec.m
index 6122c6a8b..201b08dd3 100644
--- a/SmartDeviceLinkTests/SDLSoftButtonObjectSpec.m
+++ b/SmartDeviceLinkTests/SDLSoftButtonObjectSpec.m
@@ -2,6 +2,7 @@
#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>
+#import "SDLArtwork.h"
#import "SDLSoftButton.h"
#import "SDLSoftButtonObject.h"
#import "SDLSoftButtonState.h"
@@ -45,6 +46,36 @@ describe(@"a soft button object", ^{
});
});
+ context(@"with a single state implicitly created", ^{
+ NSString *testText = @"Hello";
+ SDLArtwork *testArt = [[SDLArtwork alloc] initWithStaticIcon:SDLStaticIconNameKey];
+
+ beforeEach(^{
+ testObject = [[SDLSoftButtonObject alloc] initWithName:testObjectName text:testText artwork:testArt handler:nil];
+ });
+
+ it(@"should create correctly", ^{
+ expect(testObject.name).to(equal(testObjectName));
+ expect(testObject.currentState.name).to(equal(testObjectName));
+ expect(testObject.currentState.text).to(equal(testText));
+ expect(testObject.currentState.artwork).to(equal(testArt));
+ expect(testObject.states).to(haveCount(1));
+ });
+
+ it(@"should not allow transitioning to another state", ^{
+ BOOL performedTransition = [testObject transitionToStateNamed:@"Some other state"];
+ expect(performedTransition).to(beFalse());
+ });
+
+ it(@"should return a state when asked and not when incorrect", ^{
+ SDLSoftButtonState *returnedState = [testObject stateWithName:testObjectName];
+ expect(returnedState).toNot(beNil());
+
+ returnedState = [testObject stateWithName:@"Some other state"];
+ expect(returnedState).to(beNil());
+ });
+ });
+
context(@"with multiple states", ^{
__block SDLSoftButtonState *testFirstState = OCMClassMock([SDLSoftButtonState class]);
__block NSString *testFirstStateName = @"Test First Name";