react-native-navigation的迁移库

ApplicationLifecycleTest.test.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const Utils = require('./Utils');
  2. const Android = require('./AndroidUtils');
  3. const TestIDs = require('../playground/src/testIDs');
  4. const includes = require('lodash/includes');
  5. const { elementByLabel, elementById, sleep } = Utils;
  6. const IS_RELEASE = includes(process.argv, '--release');
  7. const KEY_CODE_R = 46;
  8. describe('application lifecycle test', () => {
  9. beforeEach(async () => {
  10. await device.relaunchApp();
  11. });
  12. it('push a screen to ensure its not there after reload', async () => {
  13. await elementById(TestIDs.STACK_BTN).tap();
  14. await elementById(TestIDs.PUSH_BTN).tap();
  15. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  16. await device.reloadReactNative();
  17. await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
  18. });
  19. it('relaunch from background', async () => {
  20. await elementById(TestIDs.STACK_BTN).tap();
  21. await elementById(TestIDs.PUSH_BTN).tap();
  22. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  23. await device.sendToHome();
  24. await device.launchApp();
  25. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  26. });
  27. it(':android: relaunch after close with back button', async () => {
  28. await elementById(TestIDs.STACK_BTN).tap();
  29. await elementById(TestIDs.PUSH_BTN).tap();
  30. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  31. Android.pressBack();
  32. await device.launchApp();
  33. await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
  34. });
  35. it('device orientation does not destroy activity', async () => {
  36. await elementById(TestIDs.STACK_BTN).tap();
  37. await elementById(TestIDs.PUSH_BTN).tap();
  38. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  39. await device.setOrientation('landscape');
  40. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  41. });
  42. it(':android: relaunch after activity killed by system', async () => {
  43. await elementById(TestIDs.STACK_BTN).tap();
  44. await elementById(TestIDs.PUSH_BTN).tap();
  45. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  46. await device.sendToHome();
  47. await togglePhonePermission();
  48. await sleep(1000);
  49. await device.launchApp();
  50. await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
  51. await expect(elementById(TestIDs.WELCOME_SCREEN_HEADER)).toBeVisible();
  52. });
  53. it(':android: pressing r twice with delay does nothing', async () => {
  54. if (!IS_RELEASE) {
  55. await elementById(TestIDs.STACK_BTN).tap();
  56. await elementById(TestIDs.PUSH_BTN).tap();
  57. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  58. Android.pressKeyCode(KEY_CODE_R);
  59. await sleep(1000);
  60. Android.pressKeyCode(KEY_CODE_R);
  61. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  62. }
  63. });
  64. xit(':android: pressing menu opens dev menu', async () => {
  65. if (!IS_RELEASE) {
  66. Android.pressMenu();
  67. await sleep(1000);
  68. await expect(elementByLabel('Reload')).toBeVisible();
  69. }
  70. });
  71. xit(':android: pressing r twice in succession reloads React Native', async () => {
  72. if (!IS_RELEASE) {
  73. await elementById(TestIDs.PUSH_BTN).tap();
  74. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  75. Android.pressKeyCode(KEY_CODE_R);
  76. Android.pressKeyCode(KEY_CODE_R);
  77. await sleep(300);
  78. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  79. }
  80. });
  81. xit(':android: sending reload broadcast reloads react native', async () => {
  82. if (!IS_RELEASE) {
  83. await elementById(TestIDs.PUSH_BTN).tap();
  84. await expect(elementByLabel('Pushed Screen')).toBeVisible();
  85. Android.executeShellCommand('am broadcast -a com.reactnativenavigation.broadcast.RELOAD');
  86. await sleep(1000);
  87. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  88. }
  89. });
  90. async function togglePhonePermission() {
  91. await sleep(700);
  92. Android.revokePermission();
  93. await sleep(700);
  94. Android.grantPermission();
  95. await sleep(1000);
  96. }
  97. });