react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. });
  66. describe('modal', () => {
  67. beforeEach(async () => {
  68. await device.relaunchApp();
  69. });
  70. it('show modal', async () => {
  71. await elementByLabel('Show Modal').tap();
  72. await expect(elementByLabel('Modal Screen')).toBeVisible();
  73. });
  74. it('dismiss modal', async () => {
  75. await elementByLabel('Show Modal').tap();
  76. await expect(elementByLabel('Modal Screen')).toBeVisible();
  77. await elementByLabel('Dismiss Modal').tap();
  78. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  79. });
  80. it('show multiple modals', async () => {
  81. await elementByLabel('Show Modal').tap();
  82. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  83. await elementByLabel('Show Modal').tap();
  84. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  85. await elementByLabel('Dismiss Modal').tap();
  86. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  87. await elementByLabel('Dismiss Modal').tap();
  88. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  89. });
  90. it('dismiss unknown screen id', async () => {
  91. await elementByLabel('Show Modal').tap();
  92. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  93. await elementByLabel('Dismiss Unknown Modal').tap();
  94. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  95. await elementByLabel('Dismiss Modal').tap();
  96. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  97. });
  98. it('dismiss modal by id which is not the top most', async () => {
  99. await elementByLabel('Show Modal').tap();
  100. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  101. await elementByLabel('Show Modal').tap();
  102. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  103. await elementByLabel('Dismiss Previous Modal').tap();
  104. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  105. await elementByLabel('Dismiss Modal').tap();
  106. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  107. });
  108. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  109. await elementByLabel('Show Modal').tap();
  110. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  111. await elementByLabel('Show Modal').tap();
  112. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  113. await elementByLabel('Show Modal').tap();
  114. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  115. await elementByLabel('Dismiss ALL Previous Modals').tap();
  116. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  117. await elementByLabel('Dismiss Modal').tap();
  118. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  119. });
  120. it('dismiss some modal by id deep in the stack', async () => {
  121. await elementByLabel('Show Modal').tap();
  122. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  123. await elementByLabel('Show Modal').tap();
  124. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  125. await elementByLabel('Show Modal').tap();
  126. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  127. await elementByLabel('Dismiss First In Stack').tap();
  128. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  129. await elementByLabel('Dismiss Modal').tap();
  130. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  131. await elementByLabel('Dismiss Modal').tap();
  132. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  133. });
  134. it('dismissAllModals', async () => {
  135. await elementByLabel('Show Modal').tap();
  136. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  137. await elementByLabel('Show Modal').tap();
  138. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  139. await elementByLabel('Dismiss All Modals').tap();
  140. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  141. });
  142. });
  143. describe('reload app', async () => {
  144. beforeEach(async () => {
  145. await device.relaunchApp();
  146. });
  147. it('push a screen to ensure its not there after reload', async () => {
  148. await elementByLabel('Push').tap();
  149. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  150. await device.reloadReactNative();
  151. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  152. });
  153. });
  154. function elementByLabel(label) {
  155. return element(by.label(label));
  156. }