FBTVNavigationTrackerTests.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Copyright (c) 2018-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 "XCUIElementDouble.h"
  11. #import "FBTVNavigationTracker.h"
  12. #import "FBTVNavigationTracker-Private.h"
  13. @interface FBTVNavigationTrackerTests : XCTestCase
  14. @end
  15. @implementation FBTVNavigationTrackerTests
  16. - (void)testHorizontalDirectionWithItemShouldBeRight
  17. {
  18. XCUIElementDouble *el1 = XCUIElementDouble.new;
  19. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  20. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  21. FBTVDirection direction = [tracker horizontalDirectionWithItem:item andDelta:0.1];
  22. XCTAssertEqual(FBTVDirectionRight, direction);
  23. }
  24. - (void)testHorizontalDirectionWithItemShouldBeLeft
  25. {
  26. XCUIElementDouble *el1 = XCUIElementDouble.new;
  27. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  28. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  29. FBTVDirection direction = [tracker horizontalDirectionWithItem:item andDelta:-0.1];
  30. XCTAssertEqual(FBTVDirectionLeft, direction);
  31. }
  32. - (void)testHorizontalDirectionWithItemShouldBeNone
  33. {
  34. XCUIElementDouble *el1 = XCUIElementDouble.new;
  35. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  36. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  37. FBTVDirection direction = [tracker horizontalDirectionWithItem:item andDelta:DBL_EPSILON];
  38. XCTAssertEqual(FBTVDirectionNone, direction);
  39. }
  40. - (void)testVerticalDirectionWithItemShouldBeDown
  41. {
  42. XCUIElementDouble *el1 = XCUIElementDouble.new;
  43. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  44. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  45. FBTVDirection direction = [tracker verticalDirectionWithItem:item andDelta:0.1];
  46. XCTAssertEqual(FBTVDirectionDown, direction);
  47. }
  48. - (void)testVerticalDirectionWithItemShouldBeUp
  49. {
  50. XCUIElementDouble *el1 = XCUIElementDouble.new;
  51. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  52. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  53. FBTVDirection direction = [tracker verticalDirectionWithItem:item andDelta:-0.1];
  54. XCTAssertEqual(FBTVDirectionUp, direction);
  55. }
  56. - (void)testVerticalDirectionWithItemShouldBeNone
  57. {
  58. XCUIElementDouble *el1 = XCUIElementDouble.new;
  59. FBTVNavigationItem *item = [FBTVNavigationItem itemWithUid:@"123456789"];
  60. FBTVNavigationTracker *tracker = [FBTVNavigationTracker trackerWithTargetElement:(XCUIElement *)el1];
  61. FBTVDirection direction = [tracker verticalDirectionWithItem:item andDelta:DBL_EPSILON];
  62. XCTAssertEqual(FBTVDirectionNone, direction);
  63. }
  64. @end