react-native-navigation的迁移库

ScreenStyle.test.js 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const Utils = require('./Utils');
  2. const Android = require('./AndroidUtils');
  3. const testIDs = require('../playground/src/testIDs');
  4. const { elementById, elementByLabel } = Utils;
  5. describe('screen style', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. });
  9. test('declare a options on component component', async () => {
  10. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  11. await expect(elementByLabel('Static Title')).toBeVisible();
  12. });
  13. test('change title on component component', async () => {
  14. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  15. await expect(elementByLabel('Static Title')).toBeVisible();
  16. await elementById(testIDs.DYNAMIC_OPTIONS_BUTTON).tap();
  17. await expect(elementByLabel('Dynamic Title')).toBeVisible();
  18. });
  19. test(
  20. 'set dynamic options with valid options will do something and not crash',
  21. async () => {
  22. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  23. await elementById(testIDs.DYNAMIC_OPTIONS_BUTTON).tap();
  24. await expect(elementById(testIDs.OPTIONS_SCREEN_HEADER)).toBeVisible();
  25. }
  26. );
  27. test(
  28. 'hides Tab Bar when pressing on Hide Top Bar and shows it when pressing on Show Top Bar',
  29. async () => {
  30. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  31. await elementById(testIDs.HIDE_TOP_BAR_BUTTON).tap();
  32. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  33. await elementById(testIDs.SHOW_TOP_BAR_BUTTON).tap();
  34. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  35. }
  36. );
  37. xit('hides topBar onScroll down and shows it on scroll up', async () => {
  38. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  39. await elementById(testIDs.SCROLLVIEW_SCREEN_BUTTON).tap();
  40. await elementById(testIDs.TOGGLE_TOP_BAR_HIDE_ON_SCROLL).tap();
  41. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  42. await element(by.id(testIDs.SCROLLVIEW_ELEMENT)).swipe('up', 'slow');
  43. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  44. await element(by.id(testIDs.SCROLLVIEW_ELEMENT)).swipe('down', 'fast');
  45. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  46. });
  47. test('set Tab Bar badge on a current Tab', async () => {
  48. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  49. await elementById(testIDs.SET_TAB_BADGE_BUTTON).tap();
  50. await expect(element(by.text('TeSt'))).toBeVisible();
  51. });
  52. test(':android: hide Tab Bar', async () => {
  53. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  54. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  55. await elementById(testIDs.HIDE_BOTTOM_TABS_BUTTON).tap();
  56. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  57. });
  58. test(':android: show Tab Bar', async () => {
  59. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  60. await elementById(testIDs.HIDE_BOTTOM_TABS_BUTTON).tap();
  61. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  62. await elementById(testIDs.SHOW_BOTTOM_TABS_BUTTON).tap();
  63. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  64. });
  65. test('hide Tab Bar on push', async () => {
  66. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  67. await elementById(testIDs.HIDE_BOTTOM_TABS_ON_PUSH_BUTTON).tap();
  68. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  69. await elementById(testIDs.POP_BUTTON).tap();
  70. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  71. });
  72. test('side menu visibility - left', async () => {
  73. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  74. await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
  75. await expect(elementById(testIDs.HIDE_LEFT_SIDE_MENU_BUTTON)).toBeVisible();
  76. await elementById(testIDs.HIDE_LEFT_SIDE_MENU_BUTTON).tap();
  77. await expect(elementById(testIDs.CENTERED_TEXT_HEADER)).toBeVisible();
  78. });
  79. test('side menu visibility - right', async () => {
  80. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  81. await elementById(testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON).tap();
  82. await expect(elementById(testIDs.HIDE_RIGHT_SIDE_MENU_BUTTON)).toBeVisible();
  83. await elementById(testIDs.HIDE_RIGHT_SIDE_MENU_BUTTON).tap();
  84. await expect(elementById(testIDs.CENTERED_TEXT_HEADER)).toBeVisible();
  85. });
  86. test('set right buttons', async () => {
  87. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  88. await expect(elementById('buttonOne')).toBeVisible();
  89. await elementById('buttonOne').tap();
  90. await expect(elementById('buttonTwo')).toBeVisible();
  91. await elementById('buttonTwo').tap();
  92. await expect(elementById('buttonOne')).toBeVisible();
  93. });
  94. test('set left buttons', async () => {
  95. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  96. await expect(elementById('buttonLeft')).toBeVisible();
  97. });
  98. test('pass props to custom button component', async () => {
  99. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  100. await expect(elementByLabel(`Two`)).toExist();
  101. });
  102. test('pass props to custom button component should exist after push pop', async () => {
  103. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  104. await expect(elementByLabel(`Two`)).toExist();
  105. await elementById(testIDs.SCROLLVIEW_SCREEN_BUTTON).tap();
  106. await elementById(testIDs.POP_BUTTON).tap();
  107. await expect(elementByLabel(`Two`)).toExist();
  108. });
  109. test('tab bar items visibility', async () => {
  110. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  111. await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();
  112. await expect(elementById(testIDs.SECOND_TAB_BAR_BUTTON)).toBeVisible();
  113. });
  114. test('default options should apply to all screens in stack', async () => {
  115. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  116. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  117. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  118. await elementById(testIDs.PUSH_BUTTON).tap();
  119. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  120. });
  121. test('default options should not override static options', async () => {
  122. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  123. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  124. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  125. await elementById(testIDs.POP_BUTTON).tap();
  126. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  127. });
  128. test('supports user-provided id', async () => {
  129. await elementById(testIDs.PROVIDED_ID).tap();
  130. await expect(elementByLabel('User provided id')).toBeVisible();
  131. });
  132. test('stack options should not override component options', async () => {
  133. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  134. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  135. });
  136. test('set title component', async () => {
  137. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  138. await elementById(testIDs.SHOW_TOPBAR_REACT_VIEW).tap();
  139. await expect(elementByLabel('Press Me')).toBeVisible();
  140. });
  141. xit(':ios: set searchBar and handle onSearchUpdated event', async () => {
  142. await elementById(testIDs.SHOW_TOPBAR_SEARCHBAR).tap();
  143. await expect(elementByLabel('Start Typing')).toBeVisible();
  144. await elementByLabel('Start Typing').tap();
  145. const query = '124';
  146. await elementByLabel('Start Typing').typeText(query);
  147. await expect(elementById(testIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
  148. });
  149. test('default options should apply to all screens in stack', async () => {
  150. await elementById(testIDs.PUSH_BUTTON).tap();
  151. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  152. await expect(elementById(testIDs.TOP_BAR_BUTTON)).toBeVisible();
  153. });
  154. test(':android: Popping screen with yellow box in button, title and background components should not crash', async () => {
  155. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  156. await elementById(testIDs.SHOW_YELLOW_BOX).tap();
  157. Android.pressBack();
  158. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  159. });
  160. });