const assert = require('assert') const fs = require('fs') const path = require('path') const planningApi = require('../../api/planning') const dateUtil = require('../../utils/date') global.wx = { getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }), getDeviceInfo: () => ({ platform: 'devtools' }), getStorageSync: () => '', setStorageSync: () => {}, removeStorageSync: () => {}, showToast: () => {}, showModal: ({ success }) => success({ confirm: false }), switchTab: () => {}, navigateTo: () => {} } const appMock = { globalData: { userInfo: {} } } global.getApp = () => appMock let definition global.Page = value => { definition = value } require('./index') function createPage(data = {}) { const page = { ...definition, data: { ...definition.data, ...data }, setData(values) { Object.entries(values).forEach(([key, value]) => { if (!key.includes('.')) { this.data[key] = value return } const parts = key.split('.') let target = this.data for (let index = 0; index < parts.length - 1; index += 1) { target = target[parts[index]] } target[parts[parts.length - 1]] = value }) } } return page } async function run() { const planningWxml = fs.readFileSync(path.join(__dirname, 'index.wxml'), 'utf8') const planningWxss = fs.readFileSync(path.join(__dirname, 'index.wxss'), 'utf8') const toolbarMarkup = planningWxml.match(/([\s\S]*?)<\/view>\s* block.left), [12, 260, 508, 12]) assert.deepStrictEqual(overlappingBlocks.map(block => block.width), [224, 224, 224, 720]) const overlaps = (left, right) => left.itemStart < right.itemEnd && right.itemStart < left.itemEnd overlappingBlocks.slice(0, 3).forEach((left, index, blocks) => { blocks.slice(index + 1).forEach(right => { if (overlaps(left, right)) { assert.ok(left.left + left.width <= right.left || right.left + right.width <= left.left) } }) }) assert.match(planningWxml, /class="lane-unassigned-tag">不占档期/) assert.match(planningWxml, /门店营业时间未设置/) assert.match(planningWxml, /bindtap="openShopSettings"/) assert.match(planningWxml, /class="week-card card"/) assert.match(planningWxml, /class="week-row-pending">待分配 \{\{item\.unassignedCount\}\}/) assert.match(planningWxml, /class="week-segment" style="width: \{\{count\.width\}\}rpx;/) assert.match(planningWxss, /\.week-track\s*\{[^}]*width:\s*396rpx;[^}]*height:\s*28rpx;/) assert.match(planningWxss, /\.week-row\s*\{[^}]*height:\s*108rpx;/) assert.match(planningWxml, /wx:if="\{\{canCreateAppointment && businessHoursConfigured && !calendarError && \(viewMode !== 'day' \|\| currentShopOpen\)\}\}" class="fab" bindtap="createAppointment"/) assert.match(planningWxml, /class="month-unassigned-count">待 \{\{item\.unassignedCount\}\}/) assert.doesNotMatch(planningWxss, /background-size:\s*100% 240rpx/) assert.match(planningWxss, /\.control-card\s*\{[^}]*padding:\s*8rpx 14rpx;/) const requestPage = createPage({ viewMode: 'day', currentDateText: '2026-10-11' }) let calendarRequests = 0 let resolveCalendar planningApi.calendar = () => { calendarRequests += 1 return new Promise(resolve => { resolveCalendar = resolve }) } const requestOne = requestPage.loadCalendar() const requestTwo = requestPage.loadCalendar() assert.strictEqual(calendarRequests, 1) resolveCalendar({ artists: [], appointments: [], daySummaries: [] }) await Promise.all([requestOne, requestTwo]) const employeesApi = require('../../api/employees') const noticePage = createPage() appMock.globalData.userInfo = { type: 2 } appMock.globalData.reviewNoticeShown = false employeesApi.reviewSummary = async () => ({ pendingCount: 2, noticeEnabled: true }) let switched = false global.wx.showModal = ({ success }) => success({ confirm: true }) global.wx.switchTab = ({ url }) => { switched = url === '/pages/employees/index' } assert.strictEqual(await noticePage.showEmployeeReviewNotice(), true) assert.strictEqual(switched, true) assert.strictEqual(appMock.globalData.reviewNoticeShown, true) assert.strictEqual(appMock.globalData.openEmployeeReview, true) const navigations = [] const toasts = [] global.wx.navigateTo = options => navigations.push(options.url) global.wx.showToast = options => toasts.push(options.title) const monthPage = createPage({ viewMode: 'month', canCreateAppointment: true, currentDateText: '2026-10-12' }) let loadedDate = '' monthPage.loadCalendar = () => { loadedDate = monthPage.data.currentDateText } monthPage.selectMonthDate({ currentTarget: { dataset: { date: '2000-01-01' } } }) assert.strictEqual(monthPage.data.viewMode, 'day') assert.strictEqual(monthPage.data.currentDateText, '2000-01-01') assert.strictEqual(loadedDate, '2000-01-01') assert.strictEqual(navigations.length, 0) const weekPage = createPage({ viewMode: 'week', currentDateText: '2026-10-12' }) let preparedView = false weekPage.prepareView = () => { preparedView = true } weekPage.selectWeekDate({ currentTarget: { dataset: { date: '2026-10-15' } } }) assert.strictEqual(weekPage.data.viewMode, 'week') assert.strictEqual(weekPage.data.currentDateText, '2026-10-15') assert.strictEqual(preparedView, true) assert.strictEqual(navigations.length, 0) const dayFabPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '99' }) dayFabPage.createAppointment() assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-11-02&artistId=99') const monthFabPage = createPage({ viewMode: 'month', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02', selectedArtistId: '88' }) monthFabPage.createAppointment() assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual&artistId=88') const weekFabPage = createPage({ viewMode: 'week', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-11-02' }) weekFabPage.createAppointment() assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?dateMode=manual') const readonlyPage = createPage({ canCreateAppointment: false, businessHoursConfigured: true, selectedArtistId: '88' }) readonlyPage.createAppointment() assert.strictEqual(navigations.length, 0) assert.strictEqual(toasts.pop(), '当前账号仅支持查看预约') const fabPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentDateText: '2026-10-12', selectedArtistId: '99' }) fabPage.createAppointment() assert.strictEqual(navigations.pop(), '/pages/appointment-form/index?date=2026-10-12&artistId=99') const unconfiguredPage = createPage({ canCreateAppointment: true, businessHoursConfigured: false }) unconfiguredPage.createAppointment() assert.strictEqual(navigations.length, 0) assert.strictEqual(toasts.pop(), '请先在店铺设置中配置营业时间') unconfiguredPage.openShopSettings() assert.strictEqual(navigations.pop(), '/pages/shop-settings/index') assert.strictEqual(unconfiguredPage._refreshCalendarOnShow, true) const closedDayAppointmentPage = createPage({ viewMode: 'day', canCreateAppointment: true, businessHoursConfigured: true, currentShopOpen: false }) closedDayAppointmentPage.createAppointment() assert.strictEqual(navigations.length, 0) assert.strictEqual(toasts.pop(), '该日期门店休息,不能新建普通预约') assert.match(planningWxml, /bindtap="selectMonthDate" aria-label="查看\{\{item\.date\}\}日程"/) assert.match(planningWxml, /bindtap="selectWeekDate" aria-label="查看\{\{item\.date\}\}日程"/) assert.match(planningWxss, /\.week-list\s*\{/) } run().catch(error => { console.error(error) process.exitCode = 1 })