FBScrollingTests.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. FBAssertInvisibleCell(@"30");
  37. FBAssertInvisibleCell(@"50");
  38. }
  39. - (void)testSimpleScroll
  40. {
  41. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  42. // This test is unstable in CI env
  43. return;
  44. }
  45. FBAssertVisibleCell(@"0");
  46. FBAssertVisibleCell(@"10");
  47. [self.scrollView fb_scrollDownByNormalizedDistance:1.0];
  48. FBAssertInvisibleCell(@"0");
  49. FBAssertInvisibleCell(@"10");
  50. XCTAssertTrue(self.testedApplication.staticTexts.count > 0);
  51. [self.scrollView fb_scrollUpByNormalizedDistance:1.0];
  52. FBAssertVisibleCell(@"0");
  53. FBAssertVisibleCell(@"10");
  54. }
  55. - (void)testScrollToVisible
  56. {
  57. NSString *cellName = @"30";
  58. FBAssertInvisibleCell(cellName);
  59. NSError *error;
  60. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_scrollToVisibleWithError:&error]);
  61. XCTAssertNil(error);
  62. FBAssertVisibleCell(cellName);
  63. }
  64. - (void)testFarScrollToVisible
  65. {
  66. NSString *cellName = @"80";
  67. NSError *error;
  68. FBAssertInvisibleCell(cellName);
  69. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_scrollToVisibleWithError:&error]);
  70. XCTAssertNil(error);
  71. FBAssertVisibleCell(cellName);
  72. }
  73. - (void)testNativeFarScrollToVisible
  74. {
  75. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  76. // This test is unstable in CI env
  77. return;
  78. }
  79. NSString *cellName = @"80";
  80. NSError *error;
  81. FBAssertInvisibleCell(cellName);
  82. XCTAssertTrue([FBCellElementWithLabel(cellName) fb_nativeScrollToVisibleWithError:&error]);
  83. XCTAssertNil(error);
  84. FBAssertVisibleCell(cellName);
  85. }
  86. - (void)testAttributeWithNullScrollToVisible
  87. {
  88. NSError *error;
  89. NSArray<XCUIElement *> *queryMatches = [self.testedApplication fb_descendantsMatchingClassChain:@"**/XCUIElementTypeTable/XCUIElementTypeCell[60]" shouldReturnAfterFirstMatch:NO];
  90. XCTAssertEqual(queryMatches.count, 1);
  91. XCUIElement *element = queryMatches.firstObject;
  92. XCTAssertFalse(element.fb_isVisible);
  93. [element fb_scrollToVisibleWithError:&error];
  94. XCTAssertNil(error);
  95. XCTAssertTrue(element.fb_isVisible);
  96. if (SYSTEM_VERSION_LESS_THAN(@"16.0")) {
  97. // This test is unstable in CI env
  98. return;
  99. }
  100. [element tap];
  101. XCTAssertTrue(element.wdSelected);
  102. }
  103. @end