react-native-navigation的迁移库

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