react-native-navigation的迁移库

ScreenStyle.test.js 8.5KB

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