react-native-navigation的迁移库

Modals.test.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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('modal', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. await elementById(TestIDs.NAVIGATION_TAB).tap();
  9. await elementById(TestIDs.MODAL_BTN).tap();
  10. });
  11. it('show modal', async () => {
  12. await expect(elementById(TestIDs.MODAL_SCREEN_HEADER)).toBeVisible();
  13. });
  14. it('dismiss modal', async () => {
  15. await expect(elementById(TestIDs.MODAL_SCREEN_HEADER)).toBeVisible();
  16. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  17. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  18. });
  19. it('unmount modal when dismissed', async () => {
  20. await expect(elementById(TestIDs.MODAL_SCREEN_HEADER)).toBeVisible();
  21. await elementById(TestIDs.MODAL_LIFECYCLE_BTN).tap();
  22. await expect(elementByLabel('didAppear')).toBeVisible();
  23. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  24. await expect(elementByLabel('componentWillUnmount')).toBeVisible();
  25. await elementByLabel('OK').atIndex(0).tap();
  26. await expect(elementByLabel('didDisappear')).toBeVisible();
  27. await elementByLabel('OK').atIndex(0).tap();
  28. });
  29. it('show multiple modals', async () => {
  30. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  31. await elementById(TestIDs.MODAL_BTN).tap();
  32. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  33. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  34. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  35. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  36. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  37. });
  38. it('dismiss unknown screen id', async () => {
  39. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  40. await elementById(TestIDs.DISMISS_UNKNOWN_MODAL_BTN).tap();
  41. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  42. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  43. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  44. });
  45. it('dismiss modal by id which is not the top most', async () => {
  46. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  47. await elementById(TestIDs.MODAL_BTN).tap();
  48. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  49. await elementById(TestIDs.DISMISS_PREVIOUS_MODAL_BTN).tap();
  50. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  51. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  52. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  53. });
  54. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  55. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  56. await elementById(TestIDs.MODAL_BTN).tap();
  57. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  58. await elementById(TestIDs.MODAL_BTN).tap();
  59. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  60. await elementById(TestIDs.DISMISS_ALL_PREVIOUS_MODAL_BTN).tap();
  61. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  62. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  63. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  64. }
  65. );
  66. it('dismiss some modal by id deep in the stack', async () => {
  67. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  68. await elementById(TestIDs.MODAL_BTN).tap();
  69. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  70. await elementById(TestIDs.MODAL_BTN).tap();
  71. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  72. await elementById(TestIDs.DISMISS_FIRST_MODAL_BTN).tap();
  73. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  74. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  75. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  76. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  77. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  78. });
  79. it('dismissAllModals', async () => {
  80. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  81. await elementById(TestIDs.MODAL_BTN).tap();
  82. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  83. await elementById(TestIDs.DISMISS_ALL_MODALS_BTN).tap();
  84. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  85. });
  86. it('push into modal', async () => {
  87. await elementById(TestIDs.PUSH_BTN).tap();
  88. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  89. });
  90. it(':android: push into modal and dismiss pushed screen with hardware back', async () => {
  91. await elementById(TestIDs.PUSH_BTN).tap();
  92. await elementById(TestIDs.PUSH_BTN).tap();
  93. Android.pressBack();
  94. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  95. });
  96. it('present modal multiple times', async () => {
  97. await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
  98. await elementById(TestIDs.MODAL_BTN).tap();
  99. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  100. });
  101. it('setRoot dismisses modals', async () => {
  102. await elementById(TestIDs.SET_ROOT).tap();
  103. await expect(elementById(TestIDs.MODAL_SCREEN_HEADER)).toBeNotVisible();
  104. await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  105. });
  106. it(':android: override hardware back button in modal with stack', async () => {
  107. await elementById(TestIDs.PUSH_BTN).tap();
  108. await elementById(TestIDs.ADD_BACK_HANDLER).tap();
  109. // Back is handled in Js
  110. Android.pressBack();
  111. await sleep(100);
  112. await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeVisible();
  113. // pop
  114. await elementById(TestIDs.REMOVE_BACK_HANDLER).tap();
  115. Android.pressBack();
  116. await sleep(100);
  117. await expect(elementById(TestIDs.MODAL_SCREEN_HEADER)).toBeVisible();
  118. // modal dismissed
  119. Android.pressBack();
  120. await sleep(100);
  121. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  122. });
  123. });