react-native-navigation的迁移库

ScreenStyle.test.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 options on a 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 TopBar when pressing on Hide TopBar and shows it when pressing on Show TopBar',
  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('set Tab Bar badge on a current Tab appear once', async () => {
  53. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  54. await elementById(testIDs.SET_TAB_BADGE_BUTTON).tap();
  55. await expect(element(by.text('TeSt'))).toBeVisible();
  56. });
  57. test(':ios: set Tab Bar badge null on a current Tab should reset badge', async () => {
  58. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  59. await elementById(testIDs.SET_TAB_BADGE_BUTTON).tap();
  60. await expect(element(by.text('TeSt'))).toBeVisible();
  61. await elementById(testIDs.SET_TAB_BADGE_BUTTON_NULL).tap();
  62. await expect(element(by.text('TeSt'))).toBeNotVisible();
  63. });
  64. test(':android: hide Tab Bar', async () => {
  65. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  66. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  67. await elementById(testIDs.HIDE_BOTTOM_TABS_BUTTON).tap();
  68. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  69. });
  70. test(':android: show Tab Bar', async () => {
  71. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  72. await elementById(testIDs.HIDE_BOTTOM_TABS_BUTTON).tap();
  73. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  74. await elementById(testIDs.SHOW_BOTTOM_TABS_BUTTON).tap();
  75. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  76. });
  77. test('hide Tab Bar on push', async () => {
  78. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  79. await elementById(testIDs.HIDE_BOTTOM_TABS_ON_PUSH_BUTTON).tap();
  80. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeNotVisible();
  81. await elementById(testIDs.POP_BUTTON).tap();
  82. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  83. });
  84. test('side menu visibility - left', async () => {
  85. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  86. await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
  87. await expect(elementById(testIDs.HIDE_LEFT_SIDE_MENU_BUTTON)).toBeVisible();
  88. await elementById(testIDs.HIDE_LEFT_SIDE_MENU_BUTTON).tap();
  89. await expect(elementById(testIDs.HIDE_LEFT_SIDE_MENU_BUTTON)).toBeNotVisible();
  90. });
  91. test('side menu visibility - right', async () => {
  92. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  93. await elementById(testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON).tap();
  94. await expect(elementById(testIDs.HIDE_RIGHT_SIDE_MENU_BUTTON)).toBeVisible();
  95. await elementById(testIDs.HIDE_RIGHT_SIDE_MENU_BUTTON).tap();
  96. await expect(elementById(testIDs.HIDE_RIGHT_SIDE_MENU_BUTTON)).toBeNotVisible();
  97. });
  98. test('set right buttons', async () => {
  99. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  100. await expect(elementById('buttonOne')).toBeVisible();
  101. await elementById('buttonOne').tap();
  102. await expect(elementById('buttonTwo')).toBeVisible();
  103. await elementById('buttonTwo').tap();
  104. await expect(elementById('buttonOne')).toBeVisible();
  105. });
  106. test('set left buttons', async () => {
  107. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  108. await expect(elementById('buttonLeft')).toBeVisible();
  109. });
  110. test('pass props to custom button component', async () => {
  111. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  112. await expect(elementByLabel(`Two`)).toExist();
  113. });
  114. test('pass props to custom button component should exist after push pop', async () => {
  115. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  116. await expect(elementByLabel(`Two`)).toExist();
  117. await elementById(testIDs.SCROLLVIEW_SCREEN_BUTTON).tap();
  118. await elementById(testIDs.POP_BUTTON).tap();
  119. await expect(elementByLabel(`Two`)).toExist();
  120. });
  121. test('custom button is tapable', async () => {
  122. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  123. await expect(elementByLabel(`Two`)).toExist();
  124. await elementByLabel(`Two`).tap();
  125. await expect(elementByLabel(`Thanks for that :)`)).toExist();
  126. });
  127. test('tab bar items visibility', async () => {
  128. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  129. await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();
  130. await expect(elementById(testIDs.SECOND_TAB_BAR_BUTTON)).toBeVisible();
  131. });
  132. test('default options should apply to all screens in stack', async () => {
  133. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  134. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  135. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  136. await elementById(testIDs.PUSH_BUTTON).tap();
  137. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  138. });
  139. test('default options should not override static options', async () => {
  140. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  141. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  142. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  143. await elementById(testIDs.POP_BUTTON).tap();
  144. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  145. });
  146. test('supports user-provided id', async () => {
  147. await elementById(testIDs.PROVIDED_ID).tap();
  148. await expect(elementByLabel('User provided id')).toBeVisible();
  149. });
  150. test('stack options should not override component options', async () => {
  151. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  152. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  153. });
  154. test('set title component', async () => {
  155. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  156. await elementById(testIDs.SHOW_TOPBAR_REACT_VIEW).tap();
  157. await expect(elementByLabel('Press Me')).toBeVisible();
  158. });
  159. xit(':ios: set searchBar and handle onSearchUpdated event', async () => {
  160. await elementById(testIDs.SHOW_TOPBAR_SEARCHBAR).tap();
  161. await expect(elementByLabel('Start Typing')).toBeVisible();
  162. await elementByLabel('Start Typing').tap();
  163. const query = '124';
  164. await elementByLabel('Start Typing').typeText(query);
  165. await expect(elementById(testIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
  166. });
  167. test('default options should apply to all screens in stack', async () => {
  168. await elementById(testIDs.PUSH_BUTTON).tap();
  169. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  170. await expect(elementById(testIDs.TOP_BAR_BUTTON)).toBeVisible();
  171. });
  172. test(':android: Popping screen with yellow box in button, title and background components should not crash', async () => {
  173. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  174. await elementById(testIDs.SHOW_YELLOW_BOX).tap();
  175. Android.pressBack();
  176. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  177. });
  178. });