welcomePageNavigation.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const {
  2. bindWelcomeButton,
  3. navigateToMiniProgramHome
  4. } = require('../../public/assets/html/welcome-page-navigation')
  5. describe('welcome page navigation', () => {
  6. test('relaunches the mini program home page', () => {
  7. const reLaunch = jest.fn()
  8. const started = navigateToMiniProgramHome({ reLaunch })
  9. expect(started).toBe(true)
  10. expect(reLaunch).toHaveBeenCalledWith(expect.objectContaining({
  11. url: '/pages/home'
  12. }))
  13. })
  14. test('reports a failure when the page is opened outside the mini program', () => {
  15. const onFailure = jest.fn()
  16. const started = navigateToMiniProgramHome(null, onFailure)
  17. expect(started).toBe(false)
  18. expect(onFailure).toHaveBeenCalledTimes(1)
  19. })
  20. test('prevents repeated taps while navigation is in progress', () => {
  21. const listeners = {}
  22. const button = {
  23. addEventListener: (event, listener) => { listeners[event] = listener },
  24. setAttribute: jest.fn(),
  25. removeAttribute: jest.fn()
  26. }
  27. const reLaunch = jest.fn()
  28. bindWelcomeButton(button, () => ({ reLaunch }))
  29. listeners.click({ preventDefault: jest.fn() })
  30. listeners.click({ preventDefault: jest.fn() })
  31. expect(reLaunch).toHaveBeenCalledTimes(1)
  32. expect(button.setAttribute).toHaveBeenCalledWith('aria-busy', 'true')
  33. })
  34. })