react-native-navigation的迁移库

ApplicationLifecycleTest.test.js 3.7KB

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