react-native-navigation的迁移库

Modals.test.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. test('show modal', async () => {
  10. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  11. await expect(elementById(testIDs.MODAL_SCREEN)).toBeVisible();
  12. });
  13. test('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. test('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. test('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. test('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. test('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. test(
  59. 'dismiss all previous modals by id when they are below top presented modal',
  60. async () => {
  61. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  62. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  63. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  64. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  65. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  66. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  67. await elementById(testIDs.DISMISS_ALL_PREVIOUS_MODAL_BUTTON).tap();
  68. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  69. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  70. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  71. }
  72. );
  73. test('dismiss some modal by id deep in the stack', async () => {
  74. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  75. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  76. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  77. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  78. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  79. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  80. await elementById(testIDs.DISMISS_FIRST_MODAL_BUTTON).tap();
  81. await expect(elementByLabel('Modal Stack Position: 3')).toBeVisible();
  82. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  83. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  84. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  85. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  86. });
  87. test('dismissAllModals', async () => {
  88. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  89. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  90. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  91. await expect(elementByLabel('Modal Stack Position: 2')).toBeVisible();
  92. await elementById(testIDs.DISMISS_ALL_MODALS_BUTTON).tap();
  93. await expect(elementById(testIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  94. });
  95. test('push into modal', async () => {
  96. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  97. await elementById(testIDs.PUSH_BUTTON).tap();
  98. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  99. });
  100. test(':android: push into modal', async () => {
  101. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  102. await elementById(testIDs.PUSH_BUTTON).tap();
  103. await elementById(testIDs.PUSH_BUTTON).tap();
  104. Android.pressBack();
  105. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  106. });
  107. test('present modal multiple times', async () => {
  108. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  109. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  110. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  111. await elementById(testIDs.SHOW_MODAL_BUTTON).tap();
  112. await elementById(testIDs.DISMISS_MODAL_BUTTON).tap();
  113. await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();
  114. });
  115. });