react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. });
  28. it('show multiple modals', async () => {
  29. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  30. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  31. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  32. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  33. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  34. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  35. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  36. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  37. });
  38. it('dismiss unknown screen id', async () => {
  39. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  40. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  41. await elementById(testIDs.DISMISS_UNKNOWN_MODAL_BUTTON).tap();
  42. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  43. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  44. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  45. });
  46. it('dismiss modal by id which is not the top most', async () => {
  47. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  48. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  49. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  50. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  51. await elementById(testIDs.DISMISS_PREVIOUS_MODAL_BUTTON).tap();
  52. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  53. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  54. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  55. });
  56. it('dismiss all previous modals by id when they are below top presented modal', async () => {
  57. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  58. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  59. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  60. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  61. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  62. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  63. await elementById(testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON).tap();
  64. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  65. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  66. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  67. });
  68. it('dismiss some modal by id deep in the stack', async () => {
  69. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  70. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  71. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  72. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  73. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  74. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  75. await elementById(testIDs.DISMISS_FIRST_MODAL_BUTTON).tap();
  76. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  77. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  78. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  79. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  80. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  81. });
  82. it('dismissAllModals', async () => {
  83. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  84. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  85. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  86. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  87. await elementById(testIDs.DISMISS_ALL_MODALS_BUTTON).tap();
  88. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  89. });
  90. it('push into modal', async () => {
  91. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  92. await elementById(testIDs.PUSH_BUTTON).tap();
  93. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  94. });
  95. it(':android: push into modal', async () => {
  96. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  97. await elementById(testIDs.PUSH_BUTTON).tap();
  98. await elementById(testIDs.PUSH_BUTTON).tap();
  99. Android.pressBack();
  100. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  101. });
  102. it('present modal multiple times', async () => {
  103. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  104. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  105. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  106. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  107. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  108. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  109. });
  110. });