react-native-navigation的迁移库

ScreenStyle.test.js 7.6KB

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