react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. describe('top level api', () => {
  2. beforeEach(async () => {
  3. await device.relaunchApp();
  4. });
  5. it('shows welcome screen', async () => {
  6. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  7. });
  8. it('switch to tab based app, passProps and functions', async () => {
  9. await elementByLabel('Switch to tab based app').tap();
  10. await expect(elementByLabel('This is tab 1')).toBeVisible();
  11. await expect(elementByLabel('Hello from a function!')).toBeVisible();
  12. });
  13. it('switch to tabs with side menus', async () => {
  14. await elementByLabel('Switch to app with side menus').tap();
  15. await elementByLabel('This is a side menu center screen tab 1').swipe('right');
  16. await expect(elementByLabel('This is a left side menu screen')).toBeVisible();
  17. });
  18. it('screen lifecycle', async () => {
  19. await elementByLabel('Push lifecycle screen').tap();
  20. await expect(elementByLabel('onStart!')).toBeVisible();
  21. await elementByLabel('Push to test onStop').tap();
  22. await expect(elementByLabel('Alert')).toBeVisible();
  23. await expect(elementByLabel('onStop')).toBeVisible();
  24. });
  25. it('unmount is called on pop', async () => {
  26. await elementByLabel('Push lifecycle screen').tap();
  27. await expect(elementByLabel('onStart!')).toBeVisible();
  28. await element(by.traits(['button']).and(by.label('Back'))).tap();
  29. await expect(elementByLabel('onStop')).toBeVisible();
  30. await expect(elementByLabel('componentWillUnmount')).toBeVisible();
  31. });
  32. });
  33. describe('screen stack', () => {
  34. beforeEach(async () => {
  35. await device.relaunchApp();
  36. });
  37. it('push screen', async () => {
  38. await elementByLabel('Push').tap();
  39. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  40. });
  41. it('pop screen', async () => {
  42. await elementByLabel('Push').tap();
  43. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  44. await elementByLabel('Pop').tap();
  45. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  46. });
  47. it('pop screen deep in the stack', async () => {
  48. await elementByLabel('Push').tap();
  49. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  50. await elementByLabel('Push').tap();
  51. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  52. await elementByLabel('Pop Previous').tap();
  53. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  54. await elementByLabel('Pop').tap();
  55. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  56. });
  57. it('pop to specific id', async () => {
  58. await elementByLabel('Push').tap();
  59. await elementByLabel('Push').tap();
  60. await elementByLabel('Push').tap();
  61. await expect(elementByLabel('Stack Position: 3')).toBeVisible();
  62. await elementByLabel('Pop To Stack Position 1').tap();
  63. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  64. });
  65. it('pop to root', async () => {
  66. await elementByLabel('Push').tap();
  67. await elementByLabel('Push').tap();
  68. await elementByLabel('Push').tap();
  69. await elementByLabel('Pop To Root').tap();
  70. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  71. });
  72. });
  73. describe('modal', () => {
  74. beforeEach(async () => {
  75. await device.relaunchApp();
  76. });
  77. it('show modal', async () => {
  78. await elementByLabel('Show Modal').tap();
  79. await expect(elementByLabel('Modal Screen')).toBeVisible();
  80. });
  81. it('dismiss modal', async () => {
  82. await elementByLabel('Show Modal').tap();
  83. await expect(elementByLabel('Modal Screen')).toBeVisible();
  84. await elementByLabel('Dismiss Modal').tap();
  85. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  86. });
  87. it('show multiple modals', async () => {
  88. await elementByLabel('Show Modal').tap();
  89. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  90. await elementByLabel('Show Modal').tap();
  91. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  92. await elementByLabel('Dismiss Modal').tap();
  93. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  94. await elementByLabel('Dismiss Modal').tap();
  95. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  96. });
  97. it('dismiss unknown screen id', async () => {
  98. await elementByLabel('Show Modal').tap();
  99. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  100. await elementByLabel('Dismiss Unknown Modal').tap();
  101. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  102. await elementByLabel('Dismiss Modal').tap();
  103. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  104. });
  105. it('dismiss modal by id which is not the top most', async () => {
  106. await elementByLabel('Show Modal').tap();
  107. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  108. await elementByLabel('Show Modal').tap();
  109. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  110. await elementByLabel('Dismiss Previous Modal').tap();
  111. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  112. await elementByLabel('Dismiss Modal').tap();
  113. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  114. });
  115. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  116. await elementByLabel('Show Modal').tap();
  117. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  118. await elementByLabel('Show Modal').tap();
  119. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  120. await elementByLabel('Show Modal').tap();
  121. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  122. await elementByLabel('Dismiss ALL Previous Modals').tap();
  123. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  124. await elementByLabel('Dismiss Modal').tap();
  125. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  126. });
  127. it('dismiss some modal by id deep in the stack', async () => {
  128. await elementByLabel('Show Modal').tap();
  129. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  130. await elementByLabel('Show Modal').tap();
  131. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  132. await elementByLabel('Show Modal').tap();
  133. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  134. await elementByLabel('Dismiss First In Stack').tap();
  135. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  136. await elementByLabel('Dismiss Modal').tap();
  137. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  138. await elementByLabel('Dismiss Modal').tap();
  139. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  140. });
  141. it('dismissAllModals', async () => {
  142. await elementByLabel('Show Modal').tap();
  143. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  144. await elementByLabel('Show Modal').tap();
  145. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  146. await elementByLabel('Dismiss All Modals').tap();
  147. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  148. });
  149. });
  150. describe('reload app', async () => {
  151. beforeEach(async () => {
  152. await device.relaunchApp();
  153. });
  154. it('push a screen to ensure its not there after reload', async () => {
  155. await elementByLabel('Push').tap();
  156. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  157. await device.reloadReactNative();
  158. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  159. });
  160. });
  161. function elementByLabel(label) {
  162. return element(by.label(label));
  163. }