76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
describe('login page', () => {
|
|
afterEach(() => {
|
|
delete global.Page
|
|
delete global.wx
|
|
jest.resetModules()
|
|
})
|
|
|
|
test('renders a static login surface without session-store wiring', () => {
|
|
let capturedPageConfig
|
|
|
|
global.Page = config => {
|
|
capturedPageConfig = config
|
|
}
|
|
|
|
const loginPageModule = require('../pages/login/index')
|
|
const pageData = loginPageModule.createLoginPageData()
|
|
const source = fs.readFileSync(path.join(process.cwd(), 'pages/login/index.js'), 'utf8')
|
|
|
|
expect(capturedPageConfig.data).toEqual(expect.objectContaining({ title: '欢迎来到玄志' }))
|
|
expect(pageData.title).toBe('欢迎来到玄志')
|
|
expect(pageData.actions).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({ key: 'wechat', title: '微信授权登录' }),
|
|
expect.objectContaining({ key: 'browse', title: '先看看静态页面' })
|
|
])
|
|
)
|
|
expect(source).not.toContain('sessionStore')
|
|
expect(source).not.toContain('handleMockLogin')
|
|
})
|
|
|
|
test('switches to home for browse action and keeps wechat action as static toast', () => {
|
|
let capturedPageConfig
|
|
|
|
global.Page = config => {
|
|
capturedPageConfig = config
|
|
}
|
|
|
|
global.wx = {
|
|
switchTab: jest.fn(),
|
|
showToast: jest.fn()
|
|
}
|
|
|
|
require('../pages/login/index')
|
|
|
|
capturedPageConfig.handleActionTap({
|
|
currentTarget: {
|
|
dataset: {
|
|
actionType: 'route',
|
|
route: '/pages/home/index'
|
|
}
|
|
}
|
|
})
|
|
|
|
capturedPageConfig.handleActionTap({
|
|
currentTarget: {
|
|
dataset: {
|
|
actionType: 'toast'
|
|
}
|
|
}
|
|
})
|
|
|
|
expect(global.wx.switchTab).toHaveBeenCalledWith({
|
|
url: '/pages/home/index'
|
|
})
|
|
expect(global.wx.showToast).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
title: '登录功能建设中',
|
|
icon: 'none'
|
|
})
|
|
)
|
|
})
|
|
})
|