react-native-navigation的迁移库

RNNOverlayManagerTest.m 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "RNNOverlayManager.h"
  4. @interface RNNOverlayManagerTest : XCTestCase
  5. @property (nonatomic, retain) RNNOverlayManager* overlayManager;
  6. @property (nonatomic, retain) UIViewController* overlayVC;
  7. @property (nonatomic, retain) RNNOverlayWindow* overlayWindow;
  8. @end
  9. @implementation RNNOverlayManagerTest
  10. - (void)setUp {
  11. [super setUp];
  12. _overlayManager = [RNNOverlayManager new];
  13. _overlayVC = [UIViewController new];
  14. _overlayWindow = [OCMockObject partialMockForObject:[RNNOverlayWindow new]];
  15. OCMStub([_overlayWindow makeKeyAndVisible]);
  16. _overlayWindow.rootViewController = _overlayVC;
  17. }
  18. - (void)testShowOverlayShouldAddWindowWithVCAsRoot {
  19. [_overlayManager showOverlayWindow:_overlayWindow];
  20. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  21. XCTAssertTrue([window.rootViewController isEqual:_overlayVC]);
  22. }
  23. - (void)testShowOverlayShouldSetKeyAndVisibleWindow {
  24. id window = _overlayManager.overlayWindows.lastObject;
  25. [[window expect] makeKeyAndVisible];
  26. [_overlayManager showOverlayWindow:_overlayWindow];
  27. [window verify];
  28. }
  29. - (void)testShowOverlayShouldCreateTransparentView {
  30. [_overlayManager showOverlayWindow:_overlayWindow];
  31. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  32. XCTAssertTrue(window.rootViewController.view.backgroundColor == [UIColor clearColor]);
  33. }
  34. - (void)testDismissOverlayShouldCleanWindowRootVC {
  35. [_overlayManager showOverlayWindow:_overlayWindow];
  36. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  37. [_overlayManager dismissOverlay:_overlayVC];
  38. XCTAssertNil(window.rootViewController);
  39. }
  40. - (void)testDismissOverlayShouldHideWindow {
  41. [_overlayManager showOverlayWindow:_overlayWindow];
  42. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  43. [_overlayManager dismissOverlay:_overlayVC];
  44. XCTAssertTrue(window.hidden);
  45. }
  46. - (void)testDismissOverlayShouldRemoveOverlayWindow {
  47. [_overlayManager showOverlayWindow:_overlayWindow];
  48. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  49. [_overlayManager dismissOverlay:_overlayVC];
  50. XCTAssertFalse([_overlayManager.overlayWindows containsObject:window]);
  51. }
  52. - (void)testDismissOverlayShouldNotRemoveWrongVC {
  53. [_overlayManager showOverlayWindow:_overlayWindow];
  54. UIWindow* window = _overlayManager.overlayWindows.lastObject;
  55. [_overlayManager dismissOverlay:[UIViewController new]];
  56. XCTAssertTrue([_overlayManager.overlayWindows containsObject:window]);
  57. }
  58. @end