Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
andreamazz committed May 14, 2015
1 parent f262ff1 commit 85dc181
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 2 deletions.
1 change: 1 addition & 0 deletions PopTipDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ target "PopTipDemoTests" do
pod 'Specta'
pod 'Expecta'
pod 'Expecta+Snapshots'
pod 'OCMock'
end

inhibit_all_warnings!
3 changes: 3 additions & 0 deletions PopTipDemo/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ PODS:
- Expecta (~> 0.3)
- FBSnapshotTestCase (= 1.6)
- FBSnapshotTestCase (1.6)
- OCMock (3.1.2)
- Specta (1.0.0)

DEPENDENCIES:
- Expecta
- Expecta+Snapshots
- OCMock
- Specta

SPEC CHECKSUMS:
Expecta: 78b4e8b0c8291fa4524d7f74016b6065c2e391ec
Expecta+Snapshots: 40c5ec43b43da3bae957f14fed5dc9177d08ec8b
FBSnapshotTestCase: 9d5fe43b29ae3a0ed8fc829477971b281038f748
OCMock: a10ea9f0a6e921651f96f78b6faee95ebc813b92
Specta: 96fe05fe5c7348b5223f85e862904f6e832abb14

COCOAPODS: 0.37.1
129 changes: 127 additions & 2 deletions PopTipDemo/PopTipDemoTests/PopTipDemoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <Specta/Specta.h>
#import <Expecta/Expecta.h>
#import <Expecta+Snapshots/EXPMatchers+FBSnapshotTest.h>
#import <OCMock/OCMock.h>

#import "AMPopTip.h"

Expand All @@ -29,6 +30,27 @@
subject = [AMPopTip popTip];
});

sharedExamplesFor(@"init method", ^(NSDictionary *data) {
it(@"should register a new gesture recognizer", ^{
expect([subject valueForKey:@"removeGesture"]).to.beKindOf([UITapGestureRecognizer class]);
});
});

describe(@"popTip", ^{
subject = [AMPopTip popTip];
itShouldBehaveLike(@"init method", nil);
});

describe(@"init", ^{
subject = [[AMPopTip alloc] init];
itShouldBehaveLike(@"init method", nil);
});

describe(@"initWithFrame:", ^{
subject = [[AMPopTip alloc] initWithFrame:CGRectZero];
itShouldBehaveLike(@"init method", nil);
});

describe(@"AMPopTipEntranceAnimationCustom", ^{
it(@"calls the provided block", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
Expand Down Expand Up @@ -103,7 +125,74 @@
});
});

context(@"showText:direction:maxWidth:inView:fromFrame:", ^{
describe(@"showText:direction:maxWidth:inView:fromFrame:", ^{
it(@"should set the properties", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero];
expect([subject valueForKey:@"attributedText"]).to.beNil();
expect([subject valueForKey:@"text"]).to.equal(@"Hi");
expect([subject valueForKey:@"accessibilityLabel"]).to.equal(@"Hi");
expect([subject valueForKey:@"direction"]).to.equal(AMPopTipDirectionUp);
expect([subject valueForKey:@"containerView"]).to.equal(view);
expect([subject valueForKey:@"maxWidth"]).to.equal(200);
});
});

describe(@"showAttributedText:direction:maxWidth:inView:fromFrame:", ^{
it(@"should set the properties", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:@"Hi" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]}];
[subject showAttributedText:attributed direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero];
expect([subject valueForKey:@"text"]).to.beNil();
expect([subject valueForKey:@"attributedText"]).to.equal(attributed);
expect([subject valueForKey:@"accessibilityLabel"]).to.equal(@"Hi");
expect([subject valueForKey:@"direction"]).to.equal(AMPopTipDirectionUp);
expect([subject valueForKey:@"containerView"]).to.equal(view);
expect([subject valueForKey:@"maxWidth"]).to.equal(200);
});
});

describe(@"showText:direction:maxWidth:inView:fromFrame:duration:", ^{
it(@"should set the properties", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero duration:1];
expect([subject valueForKey:@"attributedText"]).to.beNil();
expect([subject valueForKey:@"text"]).to.equal(@"Hi");
expect([subject valueForKey:@"accessibilityLabel"]).to.equal(@"Hi");
expect([subject valueForKey:@"direction"]).to.equal(AMPopTipDirectionUp);
expect([subject valueForKey:@"containerView"]).to.equal(view);
expect([subject valueForKey:@"maxWidth"]).to.equal(200);
});

it(@"should setup a timer", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero duration:1];
expect([subject valueForKey:@"dismissTimer"]).toNot.beNil();
});
});

describe(@"showAttributedText:direction:maxWidth:inView:fromFrame:duration:", ^{
it(@"should set the properties", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:@"Hi" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]}];
[subject showAttributedText:attributed direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero duration:1];
expect([subject valueForKey:@"text"]).to.beNil();
expect([subject valueForKey:@"attributedText"]).to.equal(attributed);
expect([subject valueForKey:@"accessibilityLabel"]).to.equal(@"Hi");
expect([subject valueForKey:@"direction"]).to.equal(AMPopTipDirectionUp);
expect([subject valueForKey:@"containerView"]).to.equal(view);
expect([subject valueForKey:@"maxWidth"]).to.equal(200);
});

it(@"should setup a timer", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:@"Hi" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12]}];
[subject showAttributedText:attributed direction:AMPopTipDirectionUp maxWidth:200 inView:view fromFrame:CGRectZero duration:1];
expect([subject valueForKey:@"dismissTimer"]).toNot.beNil();
});
});

context(@"calling show on a poptip", ^{
it(@"displays well in the top left", ^{
UIViewController *controller = [[UIViewController alloc] init];

Expand Down Expand Up @@ -196,7 +285,43 @@
expect(controller.view).to.haveValidSnapshotNamed(@"BottomRight-Left");
});
});


describe(@"hide", ^{
it(@"invaldiates the dismiss timer", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
subject.animationIn = 0;
subject.delayIn = 0;
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:140 inView:view fromFrame:CGRectZero];
[subject hide];
expect([subject valueForKey:@"dismissTimer"]).to.beNil();
});

it(@"calls the dismiss handler", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
subject.animationIn = 0;
subject.delayIn = 0;
subject.entranceAnimation = AMPopTipEntranceAnimationNone;
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:140 inView:view fromFrame:CGRectZero];

__block BOOL dismissCalled = NO;
subject.dismissHandler = ^{
dismissCalled = YES;
};
[subject hide];
expect(dismissCalled).after(1).to.beTruthy();
});

it(@"removes the popover from the superview", ^{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
subject.animationIn = 0;
subject.delayIn = 0;
subject.entranceAnimation = AMPopTipEntranceAnimationNone;
[subject showText:@"Hi" direction:AMPopTipDirectionUp maxWidth:140 inView:view fromFrame:CGRectZero];

[subject hide];
expect(subject.superview).after(1).to.beNil();
});
});
});

SpecEnd

0 comments on commit 85dc181

Please sign in to comment.