react-native-navigation的迁移库

Modals.test.js 5.3KB

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