react-native-navigation的迁移库

ScreenStyle.test.js 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 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(':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.HIDE_LEFT_SIDE_MENU_BUTTON)).toBeNotVisible();
  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.HIDE_RIGHT_SIDE_MENU_BUTTON)).toBeNotVisible();
  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('custom button is tapable', async () => {
  110. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  111. await expect(elementByLabel(`Two`)).toExist();
  112. await elementByLabel(`Two`).tap();
  113. await expect(elementByLabel(`Thanks for that :)`)).toExist();
  114. });
  115. test('tab bar items visibility', async () => {
  116. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  117. await expect(elementById(testIDs.FIRST_TAB_BAR_BUTTON)).toBeVisible();
  118. await expect(elementById(testIDs.SECOND_TAB_BAR_BUTTON)).toBeVisible();
  119. });
  120. test('default options should apply to all screens in stack', async () => {
  121. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  122. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  123. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  124. await elementById(testIDs.PUSH_BUTTON).tap();
  125. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  126. });
  127. test('default options should not override static options', async () => {
  128. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  129. await elementById(testIDs.PUSH_DEFAULT_OPTIONS_BUTTON).tap();
  130. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeNotVisible();
  131. await elementById(testIDs.POP_BUTTON).tap();
  132. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  133. });
  134. test('supports user-provided id', async () => {
  135. await elementById(testIDs.PROVIDED_ID).tap();
  136. await expect(elementByLabel('User provided id')).toBeVisible();
  137. });
  138. test('stack options should not override component options', async () => {
  139. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  140. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  141. });
  142. test('set title component', async () => {
  143. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  144. await elementById(testIDs.SHOW_TOPBAR_REACT_VIEW).tap();
  145. await expect(elementByLabel('Press Me')).toBeVisible();
  146. });
  147. xit(':ios: set searchBar and handle onSearchUpdated event', async () => {
  148. await elementById(testIDs.SHOW_TOPBAR_SEARCHBAR).tap();
  149. await expect(elementByLabel('Start Typing')).toBeVisible();
  150. await elementByLabel('Start Typing').tap();
  151. const query = '124';
  152. await elementByLabel('Start Typing').typeText(query);
  153. await expect(elementById(testIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
  154. });
  155. test('default options should apply to all screens in stack', async () => {
  156. await elementById(testIDs.PUSH_BUTTON).tap();
  157. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  158. await expect(elementById(testIDs.TOP_BAR_BUTTON)).toBeVisible();
  159. });
  160. test(':android: Popping screen with yellow box in button, title and background components should not crash', async () => {
  161. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  162. await elementById(testIDs.SHOW_YELLOW_BOX).tap();
  163. Android.pressBack();
  164. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  165. });
  166. });