react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const Utils = require('./Utils');
  2. const TestIDs = require('../playground/src/testIDs');
  3. const { elementByLabel, elementById, sleep } = Utils;
  4. const Android = require('./AndroidUtils');
  5. describe('Stack', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. await elementById(TestIDs.STACK_BTN).tap();
  9. });
  10. it('push and pop screen', async () => {
  11. await elementById(TestIDs.PUSH_BTN).tap();
  12. await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  13. await elementById(TestIDs.POP_BTN).tap();
  14. await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
  15. });
  16. it('push and pop screen without animation', async () => {
  17. await elementById(TestIDs.PUSH_BTN).tap();
  18. await elementById(TestIDs.PUSH_NO_ANIM_BTN).tap();
  19. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  20. await elementById(TestIDs.POP_BTN).tap();
  21. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  22. });
  23. it('pop to specific id', async () => {
  24. await elementById(TestIDs.PUSH_BTN).tap();
  25. await elementById(TestIDs.PUSH_BTN).tap();
  26. await elementById(TestIDs.PUSH_BTN).tap();
  27. await expect(elementByLabel('Stack Position: 3')).toBeVisible();
  28. await elementById(TestIDs.POP_TO_FIRST_SCREEN_BTN).tap();
  29. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  30. });
  31. it('pop to root', async () => {
  32. await elementById(TestIDs.PUSH_BTN).tap();
  33. await elementById(TestIDs.PUSH_BTN).tap();
  34. await elementById(TestIDs.PUSH_BTN).tap();
  35. await elementById(TestIDs.POP_TO_ROOT_BTN).tap();
  36. await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
  37. });
  38. it('pop component should not detach component if can`t pop', async () => {
  39. await elementById(TestIDs.POP_NONE_EXISTENT_SCREEN_BTN).tap();
  40. await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
  41. });
  42. it(':android: custom back button', async () => {
  43. await elementById(TestIDs.PUSH_CUSTOM_BACK_BTN).tap();
  44. await elementById(TestIDs.CUSTOM_BACK_BTN).tap();
  45. await expect(elementByLabel('back button clicked')).toBeVisible();
  46. });
  47. it('screen lifecycle', async () => {
  48. await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
  49. await expect(elementByLabel('didAppear')).toBeVisible();
  50. await elementById(TestIDs.PUSH_TO_TEST_DID_DISAPPEAR_BTN).tap();
  51. await expect(elementByLabel('didDisappear')).toBeVisible();
  52. });
  53. it('Screen popped event', async () => {
  54. await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
  55. await elementById(TestIDs.SCREEN_POPPED_BTN).tap();
  56. await expect(elementByLabel('Screen popped event')).toBeVisible();
  57. });
  58. it('unmount is called on pop', async () => {
  59. await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
  60. await elementById(TestIDs.POP_BTN).tap();
  61. await expect(elementByLabel('componentWillUnmount')).toBeVisible();
  62. await elementByLabel('OK').atIndex(0).tap();
  63. await expect(elementByLabel('didDisappear')).toBeVisible();
  64. });
  65. it(':android: override hardware back button', async () => {
  66. await elementById(TestIDs.PUSH_BTN).tap();
  67. await elementById(TestIDs.ADD_BACK_HANDLER).tap();
  68. Android.pressBack();
  69. await sleep(100);
  70. await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  71. await elementById(TestIDs.REMOVE_BACK_HANDLER).tap();
  72. Android.pressBack();
  73. await sleep(100);
  74. await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
  75. });
  76. it('does not crash when setting the stack root to an existing component id', async () => {
  77. await elementById(TestIDs.SET_STACK_ROOT_WITH_ID_BTN).tap();
  78. await elementById(TestIDs.SET_STACK_ROOT_WITH_ID_BTN).tap();
  79. });
  80. it(':ios: set stack root component should be first in stack', async () => {
  81. await elementById(TestIDs.PUSH_BTN).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_BTN).tap();
  86. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  87. });
  88. xit(':ios: set searchBar and handle onSearchUpdated event', async () => { // Broken on iOS 13
  89. await elementById(TestIDs.SEARCH_BTN).tap();
  90. await expect(elementByLabel('Start Typing')).toBeVisible();
  91. await elementByLabel('Start Typing').tap();
  92. const query = '124';
  93. await elementByLabel('Start Typing').typeText(query);
  94. await expect(elementById(TestIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
  95. });
  96. });