react-native-navigation的迁移库

app.test.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 and pop screen', async () => {
  38. await elementByLabel('Push').tap();
  39. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  40. await elementByLabel('Pop').tap();
  41. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  42. });
  43. it('pop screen deep in the stack', async () => {
  44. await elementByLabel('Push').tap();
  45. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  46. await elementByLabel('Push').tap();
  47. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  48. await elementByLabel('Pop Previous').tap();
  49. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  50. await elementByLabel('Pop').tap();
  51. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  52. });
  53. it('pop to specific id', async () => {
  54. await elementByLabel('Push').tap();
  55. await elementByLabel('Push').tap();
  56. await elementByLabel('Push').tap();
  57. await expect(elementByLabel('Stack Position: 3')).toBeVisible();
  58. await elementByLabel('Pop To Stack Position 1').tap();
  59. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  60. });
  61. it('pop to root', async () => {
  62. await elementByLabel('Push').tap();
  63. await elementByLabel('Push').tap();
  64. await elementByLabel('Push').tap();
  65. await elementByLabel('Pop To Root').tap();
  66. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  67. });
  68. });
  69. describe('modal', () => {
  70. beforeEach(async () => {
  71. await device.relaunchApp();
  72. });
  73. it('show modal', async () => {
  74. await elementByLabel('Show Modal').tap();
  75. await expect(elementByLabel('Modal Screen')).toBeVisible();
  76. });
  77. it('dismiss modal', async () => {
  78. await elementByLabel('Show Modal').tap();
  79. await expect(elementByLabel('Modal Screen')).toBeVisible();
  80. await elementByLabel('Dismiss Modal').tap();
  81. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  82. });
  83. it('show multiple modals', async () => {
  84. await elementByLabel('Show Modal').tap();
  85. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  86. await elementByLabel('Show Modal').tap();
  87. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  88. await elementByLabel('Dismiss Modal').tap();
  89. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  90. await elementByLabel('Dismiss Modal').tap();
  91. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  92. });
  93. it('dismiss unknown screen id', async () => {
  94. await elementByLabel('Show Modal').tap();
  95. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  96. await elementByLabel('Dismiss Unknown Modal').tap();
  97. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  98. await elementByLabel('Dismiss Modal').tap();
  99. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  100. });
  101. it('dismiss modal by id which is not the top most', async () => {
  102. await elementByLabel('Show Modal').tap();
  103. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  104. await elementByLabel('Show Modal').tap();
  105. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  106. await elementByLabel('Dismiss Previous Modal').tap();
  107. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  108. await elementByLabel('Dismiss Modal').tap();
  109. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  110. });
  111. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  112. await elementByLabel('Show Modal').tap();
  113. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  114. await elementByLabel('Show Modal').tap();
  115. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  116. await elementByLabel('Show Modal').tap();
  117. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  118. await elementByLabel('Dismiss ALL Previous Modals').tap();
  119. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  120. await elementByLabel('Dismiss Modal').tap();
  121. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  122. });
  123. it('dismiss some modal by id deep in the stack', async () => {
  124. await elementByLabel('Show Modal').tap();
  125. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  126. await elementByLabel('Show Modal').tap();
  127. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  128. await elementByLabel('Show Modal').tap();
  129. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  130. await elementByLabel('Dismiss First In Stack').tap();
  131. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  132. await elementByLabel('Dismiss Modal').tap();
  133. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  134. await elementByLabel('Dismiss Modal').tap();
  135. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  136. });
  137. it('dismissAllModals', async () => {
  138. await elementByLabel('Show Modal').tap();
  139. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  140. await elementByLabel('Show Modal').tap();
  141. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  142. await elementByLabel('Dismiss All Modals').tap();
  143. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  144. });
  145. });
  146. describe('reload app', async () => {
  147. beforeEach(async () => {
  148. await device.relaunchApp();
  149. });
  150. it('push a screen to ensure its not there after reload', async () => {
  151. await elementByLabel('Push').tap();
  152. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  153. await device.reloadReactNative();
  154. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  155. });
  156. });
  157. describe('screen style - static', () => {
  158. beforeEach(async () => {
  159. await device.relaunchApp();
  160. });
  161. it('declare a navigationStyle on container component', async () => {
  162. await elementByLabel('Push').tap();
  163. await expect(element(by.label('Static Title').and(by.type('UILabel')))).toBeVisible();
  164. });
  165. });
  166. function elementByLabel(label) {
  167. return element(by.label(label));
  168. }