|
@@ -0,0 +1,43 @@
|
|
|
|
|
+const {
|
|
|
|
|
+ bindWelcomeButton,
|
|
|
|
|
+ navigateToMiniProgramHome
|
|
|
|
|
+} = require('../../public/assets/html/welcome-page-navigation')
|
|
|
|
|
+
|
|
|
|
|
+describe('welcome page navigation', () => {
|
|
|
|
|
+ test('relaunches the mini program home page', () => {
|
|
|
|
|
+ const reLaunch = jest.fn()
|
|
|
|
|
+
|
|
|
|
|
+ const started = navigateToMiniProgramHome({ reLaunch })
|
|
|
|
|
+
|
|
|
|
|
+ expect(started).toBe(true)
|
|
|
|
|
+ expect(reLaunch).toHaveBeenCalledWith(expect.objectContaining({
|
|
|
|
|
+ url: '/pages/home'
|
|
|
|
|
+ }))
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('reports a failure when the page is opened outside the mini program', () => {
|
|
|
|
|
+ const onFailure = jest.fn()
|
|
|
|
|
+
|
|
|
|
|
+ const started = navigateToMiniProgramHome(null, onFailure)
|
|
|
|
|
+
|
|
|
|
|
+ expect(started).toBe(false)
|
|
|
|
|
+ expect(onFailure).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('prevents repeated taps while navigation is in progress', () => {
|
|
|
|
|
+ const listeners = {}
|
|
|
|
|
+ const button = {
|
|
|
|
|
+ addEventListener: (event, listener) => { listeners[event] = listener },
|
|
|
|
|
+ setAttribute: jest.fn(),
|
|
|
|
|
+ removeAttribute: jest.fn()
|
|
|
|
|
+ }
|
|
|
|
|
+ const reLaunch = jest.fn()
|
|
|
|
|
+
|
|
|
|
|
+ bindWelcomeButton(button, () => ({ reLaunch }))
|
|
|
|
|
+ listeners.click({ preventDefault: jest.fn() })
|
|
|
|
|
+ listeners.click({ preventDefault: jest.fn() })
|
|
|
|
|
+
|
|
|
|
|
+ expect(reLaunch).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ expect(button.setAttribute).toHaveBeenCalledWith('aria-busy', 'true')
|
|
|
|
|
+ })
|
|
|
|
|
+})
|