FBScrollingTests.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import "FBIntegrationTestCase.h"
  11. #import "FBTestMacros.h"
  12. #import "FBMacros.h"
  13. #import "XCUIElement+FBIsVisible.h"
  14. #import "XCUIElement+FBScrolling.h"
  15. #import "XCUIElement+FBClassChain.h"
  16. #import "FBXCodeCompatibility.h"
  17. @interface FBScrollingTests : FBIntegrationTestCase
  18. @property (nonatomic, strong) XCUIElement *scrollView;
  19. @end
  20. @implementation FBScrollingTests
  21. + (BOOL)shouldShowCells
  22. {
  23. return YES;
  24. }
  25. - (void)setUp
  26. {
  27. [super setUp];
  28. [self launchApplication];
  29. [self goToScrollPageWithCells:YES];
  30. self.scrollView = [[self.testedApplication.query descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"scrollView"].element;
  31. }
  32. - (void)testCellVisibility
  33. {
  34. FBAssertVisibleCell(@"0");
  35. FBAssertVisibleCell(@"10");
  36. XCUIElement *cell10 = FBCellElementWithLabel(@"10");
  37. XCTAssertEqual([cell10 isWDHittable], [cell10 isHittable]);
  38. FBAssertInvisibleCell(@"30");
  39. FBAssertInvisibleCell(@"50");
  40. XCUIElement *cell50 = FBCellElementWithLabel(@"50");
  41. XCTAssertEqual([cell50 isWDHittable], [cell50 isHittable]);
  42. }
  43. - (void)testSimpleScroll
  44. {
  45. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  46. // This test is unstable in CI env
  47. return;
  48. }
  49. FBAssertVisibleCell(@"0");
  50. FBAssertVisibleCell(@"10");
  51. [self.scrollView fb_scrollDownByNormalizedDistance:1.0];
  52. FBAssertInvisibleCell(@"0");
  53. FBAssertInvisibleCell(@"10");
  54. XCTAssertTrue(self.testedApplication.staticTexts.count > 0);
  55. [self.scrollView fb_scrollUpByNormalizedDistance:1.0];
  56. FBAssertVisibleCell(@"0");
  57. FBAssertVisibleCell(@"10");
  58. }
  59. - (void)testScrollToVisible
  60. {
  61. NSString *cellName = @"30";
  62. FBAssertInvisibleCell(cellName);
  63. NSError *error;
  64. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_scrollToVisibleWithError:&error]);
  65. XCTAssertNil(error);
  66. FBAssertVisibleCell(cellName);
  67. }
  68. - (void)testFarScrollToVisible
  69. {
  70. NSString *cellName = @"80";
  71. NSError *error;
  72. FBAssertInvisibleCell(cellName);
  73. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_scrollToVisibleWithError:&error]);
  74. XCTAssertNil(error);
  75. FBAssertVisibleCell(cellName);
  76. }
  77. - (void)testNativeFarScrollToVisible
  78. {
  79. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  80. // This test is unstable in CI env
  81. return;
  82. }
  83. NSString *cellName = @"80";
  84. NSError *error;
  85. FBAssertInvisibleCell(cellName);
  86. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_nativeScrollToVisibleWithError:&error]);
  87. XCTAssertNil(error);
  88. FBAssertVisibleCell(cellName);
  89. }
  90. - (void)testAttributeWithNullScrollToVisible
  91. {
  92. NSError *error;
  93. NSArray<XCUIElement *> *queryMatches = [self.testedApplication fb_descendantsMatchingClassChain:@"**/XCUIElementTypeTable/XCUIElementTypeCell[60]" shouldReturnAfterFirstMatch:NO];
  94. XCTAssertEqual(queryMatches.count, 1);
  95. XCUIElement *element = queryMatches.firstObject;
  96. XCTAssertFalse(element.fb_isVisible);
  97. [element fb_scrollToVisibleWithError:&error];
  98. XCTAssertNil(error);
  99. XCTAssertTrue(element.fb_isVisible);
  100. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  101. // This test is unstable in CI env
  102. return;
  103. }
  104. [element tap];
  105. XCTAssertTrue(element.wdSelected);
  106. }
  107. @end