react-native-navigation的迁移库

ScreenStack.test.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const Utils = require('./Utils');
  2. const testIDs = require('../playground/src/testIDs');
  3. const Android = require('./AndroidUtils');
  4. const { elementByLabel, elementById, sleep } = Utils;
  5. describe('screen stack', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. });
  9. test('push and pop screen', async () => {
  10. await elementById(testIDs.PUSH_BUTTON).tap();
  11. await expect(elementById(testIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  12. await elementById(testIDs.POP_BUTTON).tap();
  13. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  14. });
  15. test(':android: push and pop screen without animation', async () => {
  16. await elementById(testIDs.PUSH_OPTIONS_BUTTON).tap();
  17. await expect(elementById(testIDs.OPTIONS_SCREEN_HEADER)).toBeVisible();
  18. Android.pressBack();
  19. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  20. });
  21. test('pop to specific id', async () => {
  22. await elementById(testIDs.PUSH_BUTTON).tap();
  23. await elementById(testIDs.PUSH_BUTTON).tap();
  24. await elementById(testIDs.PUSH_BUTTON).tap();
  25. await expect(elementByLabel('Stack Position: 3')).toBeVisible();
  26. await elementById(testIDs.POP_STACK_POSITION_ONE_BUTTON).tap();
  27. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  28. });
  29. test('pop to root', async () => {
  30. await elementById(testIDs.PUSH_BUTTON).tap();
  31. await elementById(testIDs.PUSH_BUTTON).tap();
  32. await elementById(testIDs.PUSH_BUTTON).tap();
  33. await elementById(testIDs.POP_TO_ROOT).tap();
  34. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  35. });
  36. test('switch to tab', async () => {
  37. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  38. await expect(elementByLabel('This is tab 1')).toBeVisible();
  39. await elementById(testIDs.SWITCH_SECOND_TAB_BUTTON).tap();
  40. await expect(elementByLabel('This is tab 1')).toBeNotVisible();
  41. await expect(elementByLabel('This is tab 2')).toBeVisible();
  42. });
  43. test('switch to tab by cotnainerId', async () => {
  44. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  45. await expect(elementByLabel('This is tab 1')).toBeVisible();
  46. await elementById(testIDs.SWITCH_SECOND_TAB_BUTTON).tap();
  47. await expect(elementByLabel('This is tab 2')).toBeVisible();
  48. await elementById(testIDs.SWITCH_FIRST_TAB_BUTTON).tap();
  49. await expect(elementByLabel('This is tab 1')).toBeVisible();
  50. });
  51. test('push stack with multiple children', async () => {
  52. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  53. await elementById(testIDs.MODAL_WITH_STACK_BUTTON).tap();
  54. await expect(elementByLabel('Screen 2')).toBeVisible();
  55. await elementById(testIDs.POP_BUTTON).tap();
  56. await expect(elementByLabel('Screen 1')).toBeVisible();
  57. });
  58. test('push external component with options', async () => {
  59. await elementById(testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON).tap();
  60. await expect(elementByLabel('This is an external component')).toBeVisible();
  61. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  62. });
  63. test('push into a stack from BottomTabs', async () => {
  64. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  65. await elementById(testIDs.PUSH_BUTTON).tap();
  66. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  67. await elementById(testIDs.POP_BUTTON).tap();
  68. await expect(elementByLabel('This is tab 1')).toBeVisible();
  69. });
  70. test(':ios: set stack root component should be first in stack', async () => {
  71. await elementById(testIDs.PUSH_BUTTON).tap();
  72. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  73. await elementById(testIDs.SET_STACK_ROOT_BUTTON).tap();
  74. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  75. await elementById(testIDs.POP_BUTTON).tap();
  76. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  77. });
  78. test('push to stack with static id from SideMenu', async () => {
  79. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  80. await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
  81. await elementById(testIDs.LEFT_SIDE_MENU_PUSH_BUTTON).tap();
  82. await expect(elementByLabel('Text Screen')).toBeVisible();
  83. await elementById(testIDs.POP_BUTTON).tap();
  84. await expect(elementByLabel('This is a side menu center screen tab 1')).toBeVisible();
  85. });
  86. test('pop component should not deatch component if can`t pop', async () => {
  87. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  88. await elementById(testIDs.POP_BUTTON).tap();
  89. await elementById(testIDs.PUSH_BUTTON).tap();
  90. await expect(elementById(testIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  91. });
  92. test('push bottom tabs', async () => {
  93. await elementById(testIDs.PUSH_BUTTON).tap();
  94. await expect(elementById(testIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  95. await elementById(testIDs.PUSH_BOTTOM_TABS_BUTTON).tap();
  96. await expect(elementById(testIDs.BOTTOM_TABS_ELEMENT)).toBeVisible();
  97. });
  98. test(':android: custom back button', async () => {
  99. await elementById(testIDs.PUSH_BUTTON).tap();
  100. await elementById(testIDs.PUSH_CUSTOM_BACK_BUTTON).tap();
  101. await elementById(testIDs.CUSTOM_BACK_BUTTON).tap();
  102. await expect(elementByLabel('back button clicked')).toBeVisible();
  103. });
  104. });