AlertNinja 0.0.1

AlertNinja 0.0.1

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2014年12月

KAZUMA Ukyo 维护。



  • KAZUMA Ukyo

Alert Ninja

不可见的 UIAlertView 和间谍。

如何使用

文件复制或 Cocoapods。

pod 'AlertNinja'

使用

带有 OCUnit 示例。

对话框

- (void)showDialog {  
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ninja"
                                                  message:@"doron"
                                                 delegate:nil
                                        cancelButtonTitle:@"YES"
                                        otherButtonTitles:nil];
  [alert show];
}
- (void)testDialog
{   
    [[UIAlertView ninja] spy];
    [viewController showDialog];
    UIAlertView *alert = [[[[UIAlertView ninja] report] showedAlerts] lastObject];
    STAssertEqualObjects(@"Ninja", alert.title, @"alert title is Ninja");
    [[UIAlertView ninja] complete];

}

确认

- (void)showConfirm {    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Ninja"
                                                    message:@"Are you Ninja ?"
                                                   delegate:self
                                          cancelButtonTitle:@"NO"
                                          otherButtonTitles:@"YES", @"I'm Kunoichi", nil];
    [alert show];
}

和代理方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    self.calledClickedButtonAtIndex = YES;
    if(buttonIndex == 0) {
        self.result = @"NO";
    }
    else if(buttonIndex == 1) {
        self.result = @"YES";
    }
    else if(buttonIndex == 2) {
        self.result = @"Kunoichi";
    }
}

- (void)willPresentAlertView:(UIAlertView *)alertView {
    self.calledWillPresent = YES;
}

- (void)didPresentAlertView:(UIAlertView *)alertView {
    self.calledDidPresent = YES;
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    self.calledWillDismiss = YES;
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    self.calledDidDismiss = YES;
}

可以模拟按钮点击,使用 andSelectIndexAt:,并调用 UIAlertViewDelegate 方法。

- (void)testConfirm
{
    [[[UIAlertView ninja] spy] andSelectIndexAt:2];
    [viewController showConfirm];
    UIAlertView *alert = [[[[UIAlertView ninja] report] showedAlerts] lastObject];

    STAssertEqualObjects(@"Ninja", alert.title, @"alert title is Ninja");
    STAssertTrue(viewController.calledWillPresent, @"called will present delegate method");
    STAssertTrue(viewController.calledDidPresent, @"called did present delegate method");
    STAssertTrue(viewController.calledWillDismiss, @"called will dismiss delegate method");
    STAssertTrue(viewController.calledDidDismiss, @"called did dismiss delegate method");
    STAssertTrue(viewController.calledClickedButtonAtIndex, @"called did clicked button at Index");
    STAssertEqualObjects(@"Kunoichi", viewController.result, @"result is 'Kunoichi'");

    [[UIAlertView ninja] complete];
}

享受测试!

待办事项

  • 支持 UIActionSheet
  • 支持 UIAlertViewStyle(iOS5.0以后)