react-native-navigation的迁移库

BackHandler.test.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const Utils = require('./Utils');
  2. const testIDs = require('../playground/src/testIDs');
  3. const Android = require('./AndroidUtils');
  4. const { elementByLabel, elementById, sleep } = Utils;
  5. describe(':android: screen stack', () => {
  6. beforeEach(async () => {
  7. await device.relaunchApp();
  8. });
  9. it('override hardware back button', async () => {
  10. await elementByLabel('BACK HANDLER').tap();
  11. await expect(elementByLabel('Back Handler Screen')).toBeVisible();
  12. await elementByLabel('ADD BACK HANDLER').tap();
  13. Android.pressBack();
  14. await sleep(100);
  15. await expect(elementByLabel('Back Handler Screen')).toBeVisible();
  16. await elementByLabel('REMOVE BACK HANDLER').tap();
  17. Android.pressBack();
  18. await sleep(100);
  19. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  20. });
  21. it('override hardware back button in modal with stack', async () => {
  22. await elementByLabel('BACK HANDLER').tap();
  23. await expect(elementByLabel('Back Handler Screen')).toBeVisible();
  24. await elementByLabel('SHOW MODAL WITH STACK').tap();
  25. await elementByLabel('ADD BACK HANDLER').tap();
  26. // Back is handled in Js
  27. Android.pressBack();
  28. await sleep(100);
  29. await expect(elementByLabel('Back button pressed!')).toBeVisible();
  30. // pop
  31. await elementByLabel('REMOVE BACK HANDLER').tap();
  32. Android.pressBack();
  33. await sleep(100);
  34. await expect(elementByLabel('Back Handler Screen')).toBeVisible();
  35. // modal dismissed
  36. Android.pressBack();
  37. await sleep(100);
  38. await expect(elementByLabel('Back Handler Screen')).toBeVisible();
  39. // main
  40. Android.pressBack();
  41. await sleep(100);
  42. await expect(elementByLabel('React Native Navigation!')).toBeVisible();
  43. });
  44. });