react-native-navigation的迁移库

app.test.js 6.3KB

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