react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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('unmount is called on pop', async () => {
  54. await elementById(TestIDs.PUSH_LIFECYCLE_BTN).tap();
  55. await elementById(TestIDs.POP_BTN).tap();
  56. await expect(elementByLabel('componentWillUnmount')).toBeVisible();
  57. await elementByLabel('OK').atIndex(0).tap();
  58. await expect(elementByLabel('didDisappear')).toBeVisible();
  59. });
  60. it(':android: override hardware back button', async () => {
  61. await elementById(TestIDs.PUSH_BTN).tap();
  62. await elementById(TestIDs.ADD_BACK_HANDLER).tap();
  63. Android.pressBack();
  64. await sleep(100);
  65. await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  66. await elementById(TestIDs.REMOVE_BACK_HANDLER).tap();
  67. Android.pressBack();
  68. await sleep(100);
  69. await expect(elementById(TestIDs.STACK_SCREEN_HEADER)).toBeVisible();
  70. });
  71. it(':ios: set stack root component should be first in stack', async () => {
  72. await elementById(TestIDs.PUSH_BTN).tap();
  73. await expect(elementByLabel('Stack Position: 1')).toBeVisible();
  74. await elementById(TestIDs.SET_STACK_ROOT_BUTTON).tap();
  75. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  76. await elementById(TestIDs.POP_BTN).tap();
  77. await expect(elementByLabel('Stack Position: 2')).toBeVisible();
  78. });
  79. it(':ios: set searchBar and handle onSearchUpdated event', async () => {
  80. await elementById(TestIDs.SEARCH_BTN).tap();
  81. await expect(elementByLabel('Start Typing')).toBeVisible();
  82. await elementByLabel('Start Typing').tap();
  83. const query = '124';
  84. await elementByLabel('Start Typing').typeText(query);
  85. await expect(elementById(TestIDs.SEARCH_RESULT_ITEM)).toHaveText(`Item ${query}`);
  86. });
  87. });