forked from intentkit/IntentKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
INKHandlerSharedExampleSpec.m
145 lines (116 loc) · 4.46 KB
/
INKHandlerSharedExampleSpec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// INKHandlerSharedExampleSpec.m
// INKOpenInKitTests
//
// Created by Michael Walker on 11/26/13.
// Copyright (c) 2013 Mike Walker. All rights reserved.
//
#define EXP_SHORTHAND
#define HC_SHORTHAND
#define MOCKITO_SHORTHAND
#import "Specta.h"
#import "Expecta.h"
#import <OCHamcrest/OCHamcrest.h>
#import <OCMockito/OCMockito.h>
#import "INKHandler.h"
#import "NSString+Helpers.h"
#import "INKApplicationList.h"
#import "INKActivityPresenter.h"
#import "INKActivityViewController.h"
#import "INKDefaultsManager.h"
#import "INKActivity.h"
@interface INKHandler (Spec)
@property UIApplication *application;
@property INKApplicationList *appList;
@property INKDefaultsManager *defaultsManager;
@end
@interface INKActivityViewController (Spec)
@property NSArray *activityItems;
@property NSArray *applicationActivities;
@end
@interface INKApplicationList (Spec)
@property UIApplication *application;
@end
SharedExamplesBegin(INKHandler)
sharedExamplesFor(@"a handler action", ^(NSDictionary *data) {
__block INKHandler *handler;
__block NSString *urlString;
__block NSString *appName;
__block INKActivityPresenter *(^subjectAction)(void);
__block INKActivityPresenter *presenter;
beforeEach(^{
handler = data[@"handler"];
urlString = data[@"urlString"];
appName = data[@"appName"];
subjectAction = data[@"subjectAction"];
handler.defaultsManager = mock([INKDefaultsManager class]);
});
context(@"when only one application is available", ^{
beforeEach(^{
[given([handler.application canOpenURL:[NSURL URLWithString:urlString.urlScheme]]) willReturnBool:YES];
presenter = subjectAction();
});
it(@"should return a valid presenter", ^{
expect([presenter isKindOfClass:[INKActivityPresenter class]]).to.beTruthy;
});
it(@"should not have a view controller", ^{
expect(presenter.activitySheet).to.beNil();
});
it(@"should have an activity", ^{
expect(presenter.activity).to.beKindOf([INKActivity class]);
});
});
context(@"when a default has been set", ^{
beforeEach(^{
[given([handler.application canOpenURL:anything()]) willReturnBool:YES];
[given([handler.defaultsManager defaultApplicationForHandler:anything()]) willReturn:appName];
presenter = subjectAction();
});
it(@"should return a valid presenter", ^{
expect([presenter isKindOfClass:[INKActivityPresenter class]]).to.beTruthy;
});
it(@"should not have a view controller", ^{
expect(presenter.activitySheet).to.beNil();
});
it(@"should have the correct activity", ^{
expect(presenter.activity).to.beKindOf([INKActivity class]);
expect(presenter.activity.name).to.equal(appName);
});
});
context(@"when multiple applications are available", ^{
beforeEach(^{
[given([handler.application canOpenURL:anything()]) willReturnBool:YES];
presenter = subjectAction();
});
it(@"should return a valid presenter", ^{
expect([presenter isKindOfClass:[INKActivityPresenter class]]).to.beTruthy;
});
it(@"should have multiple activities", ^{
expect([presenter.activitySheet numberOfApplications]).to.beGreaterThan(0);
});
it(@"should have a delegate", ^{
expect(presenter.activitySheet.delegate).to.equal(handler);
});
it(@"should not have an activity", ^{
expect(presenter.activity).to.beNil();
});
});
});
sharedExamplesFor(@"an optional handler property", ^(NSDictionary *data) {
__block INKHandler *handler;
__block NSString *urlStringWithParam;
__block INKActivityPresenter *(^subjectAction)(void);
beforeEach(^{
handler.application = mock([UIApplication class]);
handler = data[@"handler"];
urlStringWithParam = data[@"urlStringWithParam"];
subjectAction = data[@"subjectAction"];
});
it(@"should include the given param", ^{
[given([handler.application canOpenURL:[NSURL URLWithString:urlStringWithParam.urlScheme]]) willReturnBool:YES];
INKActivityPresenter *presenter = subjectAction();
[presenter presentModalActivitySheetFromViewController:nil];
[(UIApplication *)verify(handler.application) openURL:[NSURL URLWithString:urlStringWithParam]];
});
});
SharedExamplesEnd