Skip to content

Commit 53e3cfd

Browse files
committed
Merge pull request #107 from NUBIC/repeater_dependent
Questions/Labels dependent on a question in a repeater doesn't work
2 parents 828e2b5 + 8542c98 commit 53e3cfd

File tree

6 files changed

+134
-8
lines changed

6 files changed

+134
-8
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Feature:
2+
As an user
3+
I want to take the red green survey
4+
So I can test labels depenendent on repeater questions
5+
6+
Background:
7+
Given I launch the app using iOS 5.1 and the ipad simulator
8+
And the device is in portrait orientation
9+
And I touch the button marked "Inspect"
10+
And I touch the button marked "loadRedGreen"
11+
And I wait for animations
12+
13+
Scenario: The label dependent on the repeater question should not show when dependency not is satisfied
14+
When I touch the table cell marked "Red"
15+
And I wait for animations
16+
Then I should not see a "You Win!!" label
17+
18+
Scenario: The label dependent on the repeater question should show when dependency is satisfied
19+
When I touch the table cell marked "Green"
20+
And I wait for animations
21+
Then I should see a "You Win!!" label
22+
23+
Scenario: The label dependent on the repeater question should show with multiple responses when dependency is satisfied
24+
When I touch the table cell marked "Red"
25+
And I wait for animations
26+
When I touch the button marked "+ add row"
27+
And I wait for animations
28+
And touch the 2nd table cell marked "Green"
29+
And I wait for animations
30+
Then I should see a "You Win!!" label

Frank/features/step_definitions/response_set_steps.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
check_element_exists("label marked:'#{expected_mark}'")
5858
end
5959

60+
Then /^I should not see a "([^\"]*)" label$/ do |expected_mark|
61+
check_element_does_not_exist("label marked:'#{expected_mark}'")
62+
end
63+
64+
When /^touch the (\d*)(?:st|nd|rd|th)? table cell marked "(.*?)"$/ do |ordinal, mark|
65+
total_found = frankly_map( "tableViewCell marked:'#{mark}'", 'tag' ).count
66+
ordinal = total_found - (ordinal.to_i) # Order is always reversed for some reason
67+
touch("tableViewCell marked:'#{mark}' index:#{ordinal}")
68+
end
69+
6070
Then /^I touch a "(.*)" marked "(.*)"$/ do |viewClass, mark|
6171
touch("view:'#{viewClass}' marked:'#{mark}'")
6272
end

NUSurveyor.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
0002A26816A5FC52004F3B5E /* NSDateFormatterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0002A26716A5FC52004F3B5E /* NSDateFormatterTest.m */; };
1111
0030EA2616C1FB2A00694153 /* double_dependency.json in Resources */ = {isa = PBXBuildFile; fileRef = 0030EA2516C1FB2A00694153 /* double_dependency.json */; };
12+
0030EA3816C458E900694153 /* red-green.json in Resources */ = {isa = PBXBuildFile; fileRef = 0030EA3716C458E900694153 /* red-green.json */; };
13+
0030EA3E16C459D200694153 /* repeater_conditions.feature in Resources */ = {isa = PBXBuildFile; fileRef = 0030EA3D16C459D200694153 /* repeater_conditions.feature */; };
1214
005AA64B1521F04B00E67C10 /* NUResponseSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 006CE3B815214DB400DD32A2 /* NUResponseSetTest.m */; };
1315
005AA64C1521F04B00E67C10 /* NUResponseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 005AA6491521676300E67C10 /* NUResponseTest.m */; };
1416
005AA64F152208DE00E67C10 /* NUResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 005AA64D152208DE00E67C10 /* NUResponse.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -212,6 +214,8 @@
212214
0002A26616A5FC52004F3B5E /* NSDateFormatterTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSDateFormatterTest.h; sourceTree = "<group>"; };
213215
0002A26716A5FC52004F3B5E /* NSDateFormatterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSDateFormatterTest.m; sourceTree = "<group>"; };
214216
0030EA2516C1FB2A00694153 /* double_dependency.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = double_dependency.json; sourceTree = "<group>"; };
217+
0030EA3716C458E900694153 /* red-green.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "red-green.json"; sourceTree = "<group>"; };
218+
0030EA3D16C459D200694153 /* repeater_conditions.feature */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = repeater_conditions.feature; sourceTree = "<group>"; };
215219
005AA6481521676300E67C10 /* NUResponseTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NUResponseTest.h; sourceTree = "<group>"; };
216220
005AA6491521676300E67C10 /* NUResponseTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NUResponseTest.m; sourceTree = "<group>"; };
217221
005AA64D152208DE00E67C10 /* NUResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NUResponse.h; path = Models/NUResponse.h; sourceTree = "<group>"; };
@@ -980,6 +984,7 @@
980984
67DB49AC14D09454009CC8C3 /* Supporting Files */ = {
981985
isa = PBXGroup;
982986
children = (
987+
0030EA3716C458E900694153 /* red-green.json */,
983988
00D61CA716B02E7400565A8B /* shoes.json */,
984989
3B5ACC17162F5203007EED1A /* sesame.json */,
985990
3BC61A9315211EC900A8C20C /* complex-responses.json */,
@@ -1022,6 +1027,7 @@
10221027
67DB4A0B14D09EB6009CC8C3 /* support */,
10231028
00DD775616A74E1900D78EBE /* complex_dependencies.feature */,
10241029
00C58E4016AF391300A77DE4 /* repeater.feature */,
1030+
0030EA3D16C459D200694153 /* repeater_conditions.feature */,
10251031
);
10261032
path = features;
10271033
sourceTree = "<group>";
@@ -1320,6 +1326,8 @@
13201326
00DD775716A74E1900D78EBE /* complex_dependencies.feature in Resources */,
13211327
00D61CA816B02E7400565A8B /* shoes.json in Resources */,
13221328
16F5F2B316C056C5007F0AD9 /* dependencyToolbox.json in Resources */,
1329+
0030EA3816C458E900694153 /* red-green.json in Resources */,
1330+
0030EA3E16C459D200694153 /* repeater_conditions.feature in Resources */,
13231331
);
13241332
runOnlyForDeploymentPostprocessing = 0;
13251333
};

NUSurveyor/Models/NUResponseSet.m

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,23 @@ - (NSArray *) responsesForQuestion:(NSString *)qid {
9999
// Look up responses
100100
//
101101

102-
- (NSArray *) responsesForQuestion:(NSString *)qid Answer:(NSString *)aid {
103-
return [self responsesForQuestion:qid Answer:aid Response:NULL];
102+
- (NSArray *)responsesForQuestion:(NSString *)qid Answer:(NSString *)aid {
103+
NSPredicate *predicate = [NSPredicate predicateWithFormat:
104+
@"(responseSet == %@) AND (question == %@) AND (answer == %@)",
105+
self, qid, aid];
106+
107+
return [self responsesWithPredicate:predicate];
108+
}
109+
110+
- (NSArray *)responsesForQuestion:(NSString *)qid Answer:(NSString *)aid Response:(NSNumber*)rgid {
111+
NSPredicate *predicate = [NSPredicate predicateWithFormat:
112+
@"(responseSet == %@) AND (question == %@) AND (answer == %@) AND (responseGroup == %@)",
113+
self, qid, aid, rgid];
114+
115+
return [self responsesWithPredicate:predicate];
104116
}
105117

106-
- (NSArray *) responsesForQuestion:(NSString *)qid Answer:(NSString *)aid Response:(NSNumber*)rgid {
118+
- (NSArray*)responsesWithPredicate:(NSPredicate*)predicate {
107119
// DLog(@"responsesForQuestion %@ answer %@", qid, aid);
108120
// setup fetch request
109121
NSError *error = nil;
@@ -112,9 +124,6 @@ - (NSArray *) responsesForQuestion:(NSString *)qid Answer:(NSString *)aid Respon
112124
[request setEntity:entity];
113125

114126
// Set predicate
115-
NSPredicate *predicate = [NSPredicate predicateWithFormat:
116-
@"(responseSet == %@) AND (question == %@) AND (answer == %@) AND (responseGroup == %@)",
117-
self, qid, aid, rgid];
118127
[request setPredicate:predicate];
119128

120129
NSArray *results = [self.managedObjectContext executeFetchRequest:request error:&error];
@@ -131,6 +140,7 @@ - (NSArray *) responsesForQuestion:(NSString *)qid Answer:(NSString *)aid Respon
131140
// DLog(@"responseForAnswer #:%d", [results count]);
132141
return results;
133142
}
143+
134144
//
135145
// Create a response with value
136146
//

NUSurveyorExample/NUSpyVC.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ @interface NUSpyVC()
1919
@property (nonatomic, strong) UIButton *statesAndDates;
2020
@property (nonatomic, strong) UIButton *animals;
2121
@property (nonatomic, strong) UIButton *shoes;
22+
@property (nonatomic, strong) UIButton *redGreen;
2223
- (void) loadKitchenSink;
2324
- (void) loadComplexResponses;
2425
- (void) loadMustache;
@@ -40,7 +41,8 @@ @implementation NUSpyVC
4041
pbj = _pbj,
4142
sesame = _sesame,
4243
blankMustache = _blankMustache,
43-
statesAndDates = _statesAndDates;
44+
statesAndDates = _statesAndDates,
45+
redGreen = _redGreen;
4446

4547
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
4648
{
@@ -141,11 +143,18 @@ - (void)viewDidLoad
141143
[self.view addSubview:self.shoes];
142144

143145
self.shoes = [UIButton buttonWithType:UIButtonTypeRoundedRect];
144-
self.shoes.frame = CGRectMake(10, 15.0 + 10*36.0 + 9*10.0, 400.0, 36.0);
146+
self.shoes.frame = CGRectMake(10, 10.0 + 10*36.0 + 10*10.0, 400.0, 36.0);
145147
self.shoes.accessibilityLabel = @"loadDependencyToolbox";
146148
[self.shoes setTitle:@"Load Dependency Toolbox" forState:UIControlStateNormal];
147149
[self.shoes addTarget:self action:@selector(loadDependencyToolbox) forControlEvents:UIControlEventTouchUpInside];
148150
[self.view addSubview:self.shoes];
151+
152+
self.redGreen = [UIButton buttonWithType:UIButtonTypeRoundedRect];
153+
self.redGreen.frame = CGRectMake(10, 15.0 + 11*36.0 + 11*10.0, 400.0, 36.0);
154+
self.redGreen.accessibilityLabel = @"loadRedGreen";
155+
[self.redGreen setTitle:@"Load Red Green (Repeater Conditions)" forState:UIControlStateNormal];
156+
[self.redGreen addTarget:self action:@selector(loadRedGreen) forControlEvents:UIControlEventTouchUpInside];
157+
[self.view addSubview:self.redGreen];
149158

150159
}
151160
- (void) loadKitchenSink{
@@ -183,6 +192,10 @@ - (void) loadDependencyToolbox {
183192
[self.delegate loadSurvey:@"dependencyToolbox"];
184193
}
185194

195+
- (void) loadRedGreen {
196+
[self.delegate loadSurvey:@"red-green"];
197+
}
198+
186199
- (void)viewWillAppear:(BOOL)animated {
187200
self.responseSetCount.text = [NSString stringWithFormat:@"%d %@", [self.sectionTVC.responseSet responseCount], ([self.sectionTVC.responseSet responseCount] == 1 ? @"response" : @"responses")];
188201
}

NUSurveyorExample/red-green.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
3+
"title": "Repeater Condition",
4+
"uuid": "23f58c43-c606-49f5-b7fd-69ef1fcb2d3f",
5+
"sections": [
6+
{
7+
"title": "One",
8+
"display_order": 0,
9+
"questions_and_groups": [
10+
{
11+
"uuid": "742f152a-b45d-43e3-ba52-3d9c59dd2c9e",
12+
"text": "Colors",
13+
"type": "repeater",
14+
"questions": [
15+
{
16+
"uuid": "53ce7fe0-0c79-4ba9-a33d-87212e21c544",
17+
"text": "Red or Green?",
18+
"reference_identifier": "color",
19+
"pick": "one",
20+
"answers": [
21+
{
22+
"uuid": "9cc39117-42b0-4946-a0c0-e332f555f568",
23+
"text": "Red",
24+
"reference_identifier": "red"
25+
},
26+
{
27+
"uuid": "0463e911-27f6-4882-a3bd-456dbd24989f",
28+
"text": "Green",
29+
"reference_identifier": "green"
30+
}
31+
]
32+
}
33+
]
34+
},
35+
{
36+
"uuid": "1bf4b42b-fcab-45d7-894c-5e247ebe5308",
37+
"text": "You Win!!",
38+
"type": "label",
39+
"dependency": {
40+
"rule": "A",
41+
"conditions": [
42+
{
43+
"rule_key": "A",
44+
"operator": "==",
45+
"question": "53ce7fe0-0c79-4ba9-a33d-87212e21c544",
46+
"answer": "0463e911-27f6-4882-a3bd-456dbd24989f"
47+
}
48+
]
49+
}
50+
}
51+
]
52+
}
53+
]
54+
55+
}

0 commit comments

Comments
 (0)