react-native-navigation的迁移库

ScreenStack.test.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. it('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. it(':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. it('pop screen deep in the stack', async () => {
  22. await elementById(testIDs.PUSH_BUTTON).tap();
  23. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  24. await elementById(testIDs.PUSH_BUTTON).tap();
  25. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  26. await elementById(testIDs.POP_PREVIOUS_BUTTON).tap();
  27. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  28. await elementById(testIDs.POP_BUTTON).tap();
  29. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  30. });
  31. it('pop to specific id', async () => {
  32. await elementById(testIDs.PUSH_BUTTON).tap();
  33. await elementById(testIDs.PUSH_BUTTON).tap();
  34. await elementById(testIDs.PUSH_BUTTON).tap();
  35. await expect(elementByLabel('Stack Position: 3')).toBeVisible();
  36. await elementById(testIDs.POP_STACK_POSITION_ONE_BUTTON).tap();
  37. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  38. });
  39. it('pop to root', async () => {
  40. await elementById(testIDs.PUSH_BUTTON).tap();
  41. await elementById(testIDs.PUSH_BUTTON).tap();
  42. await elementById(testIDs.PUSH_BUTTON).tap();
  43. await elementById(testIDs.POP_TO_ROOT).tap();
  44. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  45. });
  46. it('switch to tab', async () => {
  47. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  48. await expect(elementByLabel('This is tab 1')).toBeVisible();
  49. await elementById(testIDs.SWITCH_SECOND_TAB_BUTTON).tap();
  50. await expect(elementByLabel('This is tab 1')).toBeNotVisible();
  51. await expect(elementByLabel('This is tab 2')).toBeVisible();
  52. });
  53. it('switch to tab by cotnainerId', async () => {
  54. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  55. await expect(elementByLabel('This is tab 1')).toBeVisible();
  56. await elementById(testIDs.SWITCH_SECOND_TAB_BUTTON).tap();
  57. await expect(elementByLabel('This is tab 2')).toBeVisible();
  58. await elementById(testIDs.SWITCH_FIRST_TAB_BUTTON).tap();
  59. await expect(elementByLabel('This is tab 1')).toBeVisible();
  60. });
  61. it('push stack with multiple children', async () => {
  62. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  63. await elementById(testIDs.MODAL_WITH_STACK_BUTTON).tap();
  64. await expect(elementByLabel('Screen 2')).toBeVisible();
  65. await elementById(testIDs.POP_BUTTON).tap();
  66. await expect(elementByLabel('Screen 1')).toBeVisible();
  67. });
  68. it('push external component with options', async () => {
  69. await elementById(testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON).tap();
  70. await expect(elementByLabel('This is an external component')).toBeVisible();
  71. await expect(elementById(testIDs.TOP_BAR_ELEMENT)).toBeVisible();
  72. });
  73. it('push into a stack from BottomTabs', async () => {
  74. await elementById(testIDs.TAB_BASED_APP_BUTTON).tap();
  75. await elementById(testIDs.PUSH_BUTTON).tap();
  76. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  77. await elementById(testIDs.POP_BUTTON).tap();
  78. await expect(elementByLabel('This is tab 1')).toBeVisible();
  79. });
  80. it(':ios: set stack root component should be first in stack', async () => {
  81. await elementById(testIDs.PUSH_BUTTON).tap();
  82. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  83. await elementById(testIDs.SET_STACK_ROOT_BUTTON).tap();
  84. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  85. await elementById(testIDs.POP_BUTTON).tap();
  86. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  87. });
  88. it('push to stack with static id from SideMenu', async () => {
  89. await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
  90. await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
  91. await elementById(testIDs.LEFT_SIDE_MENU_PUSH_BUTTON).tap();
  92. await expect(elementByLabel('Text Screen')).toBeVisible();
  93. await elementById(testIDs.POP_BUTTON).tap();
  94. await expect(elementByLabel('This is a side menu center screen tab 1')).toBeVisible();
  95. });
  96. });