feat: migrate static pages to native tabbar
This commit is contained in:
170
tests/ai-page.test.js
Normal file
170
tests/ai-page.test.js
Normal file
@@ -0,0 +1,170 @@
|
||||
describe('ai page', () => {
|
||||
afterEach(() => {
|
||||
delete global.Page
|
||||
delete global.wx
|
||||
jest.resetModules()
|
||||
})
|
||||
|
||||
test('exposes AI assistant tabs and default QA panel data', () => {
|
||||
let capturedPageConfig
|
||||
|
||||
global.Page = config => {
|
||||
capturedPageConfig = config
|
||||
}
|
||||
|
||||
const aiPageModule = require('../pages/ai/index')
|
||||
const pageData =
|
||||
typeof aiPageModule.createAiPageData === 'function'
|
||||
? aiPageModule.createAiPageData()
|
||||
: capturedPageConfig?.data
|
||||
|
||||
expect(aiPageModule.createAiPageData).toEqual(expect.any(Function))
|
||||
expect(pageData.title).toBe('AI助手')
|
||||
expect(pageData.historyText).toBe('历史')
|
||||
expect(pageData.activeTabKey).toBe('qa')
|
||||
expect(pageData.tabs).toEqual([
|
||||
expect.objectContaining({ key: 'qa', label: 'AI答疑' }),
|
||||
expect.objectContaining({ key: 'analysis', label: '辨证分析' }),
|
||||
expect.objectContaining({ key: 'constitution', label: '体质检测' })
|
||||
])
|
||||
expect(pageData.currentPanel).toEqual(
|
||||
expect.objectContaining({
|
||||
key: 'qa',
|
||||
badge: 'AI答疑',
|
||||
heading: '您好,我是中医学习助手',
|
||||
actionButtonText: '发送'
|
||||
})
|
||||
)
|
||||
expect(pageData.currentPanel.examples).toHaveLength(3)
|
||||
})
|
||||
|
||||
test('switches panel content when another tab is tapped', () => {
|
||||
let capturedPageConfig
|
||||
|
||||
global.Page = config => {
|
||||
capturedPageConfig = config
|
||||
}
|
||||
|
||||
require('../pages/ai/index')
|
||||
|
||||
const pageInstance = {
|
||||
data: {
|
||||
...(capturedPageConfig.data || {})
|
||||
},
|
||||
setData(update) {
|
||||
this.data = {
|
||||
...this.data,
|
||||
...update
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
capturedPageConfig.handleTabTap.call(pageInstance, {
|
||||
currentTarget: {
|
||||
dataset: {
|
||||
tabKey: 'analysis'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(pageInstance.data.activeTabKey).toBe('analysis')
|
||||
expect(pageInstance.data.currentPanel).toEqual(
|
||||
expect.objectContaining({
|
||||
key: 'analysis',
|
||||
badge: '辨证分析',
|
||||
heading: '先整理症状,再查看学习型辨证分析',
|
||||
actionButtonText: '开始分析'
|
||||
})
|
||||
)
|
||||
|
||||
capturedPageConfig.handleTabTap.call(pageInstance, {
|
||||
currentTarget: {
|
||||
dataset: {
|
||||
tabKey: 'constitution'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(pageInstance.data.activeTabKey).toBe('constitution')
|
||||
expect(pageInstance.data.currentPanel).toEqual(
|
||||
expect.objectContaining({
|
||||
key: 'constitution',
|
||||
badge: '体质检测',
|
||||
heading: '体质检测即将开放',
|
||||
actionButtonText: '查看其它待开放能力'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('shows a toast for history and action placeholders', () => {
|
||||
let capturedPageConfig
|
||||
|
||||
global.Page = config => {
|
||||
capturedPageConfig = config
|
||||
}
|
||||
|
||||
global.wx = {
|
||||
showToast: jest.fn()
|
||||
}
|
||||
|
||||
require('../pages/ai/index')
|
||||
|
||||
capturedPageConfig.handleHistoryTap()
|
||||
capturedPageConfig.handleActionTap()
|
||||
|
||||
expect(global.wx.showToast).toHaveBeenCalledTimes(2)
|
||||
expect(global.wx.showToast).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
expect.objectContaining({
|
||||
title: '功能建设中',
|
||||
icon: 'none'
|
||||
})
|
||||
)
|
||||
expect(global.wx.showToast).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({
|
||||
title: '功能建设中',
|
||||
icon: 'none'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('adds a visible interpret entry and routes history to the tcm history page', () => {
|
||||
let capturedPageConfig
|
||||
|
||||
global.Page = config => {
|
||||
capturedPageConfig = config
|
||||
}
|
||||
|
||||
global.wx = {
|
||||
navigateTo: jest.fn(),
|
||||
showToast: jest.fn()
|
||||
}
|
||||
|
||||
const aiPageModule = require('../pages/ai/index')
|
||||
const pageData = aiPageModule.createAiPageData()
|
||||
|
||||
expect(pageData.secondaryEntries).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ key: 'ai-history', title: 'AI历史' }),
|
||||
expect.objectContaining({ key: 'mingli-interpret', title: '命理解读' })
|
||||
])
|
||||
)
|
||||
|
||||
capturedPageConfig.handleHistoryTap()
|
||||
capturedPageConfig.handleSecondaryEntryTap({
|
||||
currentTarget: {
|
||||
dataset: {
|
||||
route: '/packages/mingli/pages/interpret/index'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
expect(global.wx.navigateTo).toHaveBeenNthCalledWith(1, {
|
||||
url: '/packages/tcm/pages/ai-history/index'
|
||||
})
|
||||
expect(global.wx.navigateTo).toHaveBeenNthCalledWith(2, {
|
||||
url: '/packages/mingli/pages/interpret/index'
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user