react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const Utils = require('./Utils');
  2. const testIDs = require('../playground/src/testIDs');
  3. const Android = require('./AndroidUtils');
  4. const { elementByLabel, elementById, tapDeviceBackAndroid } = Utils;
  5. describe('modal', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. });
  9. it('show modal', async () => {
  10. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  11. await expect(elementById(testIDs.MODAL_SCREEN)).toBeVisible();
  12. });
  13. it('dismiss modal', async () => {
  14. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  15. await expect(elementById(testIDs.MODAL_SCREEN)).toBeVisible();
  16. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  17. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  18. });
  19. it('unmount modal when dismissed', async () => {
  20. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  21. await expect(elementById(testIDs.MODAL_SCREEN)).toBeVisible();
  22. await elementById(testIDs.MODAL_LIFECYCLE_BUTTON).tap();
  23. await expect(elementByLabel('didAppear')).toBeVisible();
  24. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  25. await expect(elementByLabel('componentWillUnmount')).toBeVisible();
  26. await elementByLabel('OK').atIndex(0).tap();
  27. await expect(elementByLabel('didDisappear')).toBeVisible();
  28. await elementByLabel('OK').atIndex(0).tap();
  29. });
  30. it('show multiple modals', async () => {
  31. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  32. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  33. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  34. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  35. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  36. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  37. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  38. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  39. });
  40. it('dismiss unknown screen id', async () => {
  41. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  42. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  43. await elementById(testIDs.DISMISS_UNKNOWN_MODAL_BUTTON).tap();
  44. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  45. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  46. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  47. });
  48. it('dismiss modal by id which is not the top most', async () => {
  49. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  50. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  51. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  52. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  53. await elementById(testIDs.DISMISS_PREVIOUS_MODAL_BUTTON).tap();
  54. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  55. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  56. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  57. });
  58. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  59. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  60. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  61. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  62. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  63. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  64. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  65. await elementById(testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON).tap();
  66. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  67. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  68. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  69. });
  70. it('dismiss some modal by id deep in the stack', async () => {
  71. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  72. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  73. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  74. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  75. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  76. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  77. await elementById(testIDs.DISMISS_FIRST_MODAL_BUTTON).tap();
  78. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  79. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  80. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  81. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  82. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  83. });
  84. it('dismissAllModals', async () => {
  85. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  86. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  87. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  88. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  89. await elementById(testIDs.DISMISS_ALL_MODALS_BUTTON).tap();
  90. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  91. });
  92. it('push into modal', async () => {
  93. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  94. await elementById(testIDs.PUSH_BUTTON).tap();
  95. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  96. });
  97. it(':android: push into modal', async () => {
  98. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  99. await elementById(testIDs.PUSH_BUTTON).tap();
  100. await elementById(testIDs.PUSH_BUTTON).tap();
  101. Android.pressBack();
  102. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  103. });
  104. it('present modal multiple times', async () => {
  105. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  106. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  107. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  108. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  109. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  110. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  111. });
  112. });