react-native-navigation的迁移库

ScreenStack.test.js 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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(':ios: set stack root component should be first in stack', async () => {
  74. await elementById(testIDs.PUSH_BUTTON).tap();
  75. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  76. await elementById(testIDs.SET_STACK_ROOT_BUTTON).tap();
  77. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  78. await elementById(testIDs.POP_BUTTON).tap();
  79. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  80. });
  81. });