自动发布开发环境 Nacos 配置 / publish (push) Successful in 46s
- 日视图滚动容器末尾新增留白(64rpx + 安全区),避免末条时间刻度与末个预约卡片贴边、滚到底仍缺一截 - 视口高度计算同步预留该留白,短时间轴不再因高度刚好等于内容高度而裁掉末条标签 - 时间刻度列加宽到 104rpx,刻度与泳道内容间距增至 20rpx,改善左侧呼吸感并避免刻度文字被截断
301 lines
15 KiB
JavaScript
301 lines
15 KiB
JavaScript
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(/<view class="month-toolbar">([\s\S]*?)<\/view>\s*<view class="month-card/)
|
|
assert.ok(toolbarMarkup)
|
|
assert.ok(toolbarMarkup[1].indexOf('month-toolbar-title') < toolbarMarkup[1].indexOf('month-toolbar-controls'))
|
|
assert.ok(toolbarMarkup[1].indexOf('month-mode-switch') < toolbarMarkup[1].indexOf('row-name-switch'))
|
|
const toolbarControlsStyle = planningWxss.match(/\.month-toolbar-controls\s*\{([^}]*)\}/)
|
|
assert.ok(toolbarControlsStyle)
|
|
assert.match(toolbarControlsStyle[1], /margin-left:\s*auto/)
|
|
|
|
assert.deepStrictEqual(definition.data.viewModes.map(item => item.value), ['month', 'week', 'day'])
|
|
assert.strictEqual(definition.data.viewMode, 'month')
|
|
|
|
const page = createPage({ viewMode: 'week' })
|
|
let monthBuilds = 0
|
|
let weekBuilds = 0
|
|
let dayBuilds = 0
|
|
page.buildMonthDays = () => { monthBuilds += 1; return [] }
|
|
page.buildWeekDays = () => { weekBuilds += 1; return [] }
|
|
page.buildDayView = () => { dayBuilds += 1; return {} }
|
|
page.buildViewState({ artists: [], appointments: [], daySummaries: [] })
|
|
assert.deepStrictEqual([monthBuilds, weekBuilds, dayBuilds], [0, 1, 0])
|
|
|
|
const closedWeekPage = createPage({ viewMode: 'week', currentDateText: '2026-10-12' })
|
|
const closedWeek = Array.from({ length: 7 }, (_, index) => ({
|
|
date: dateUtil.formatDate(dateUtil.addDays(dateUtil.startOfWeek(closedWeekPage.data.currentDateText), index)),
|
|
shopOpen: false,
|
|
shopStartTime: null,
|
|
shopEndTime: null
|
|
}))
|
|
const closedWeekState = closedWeekPage.buildViewState({
|
|
businessStartTime: '10:00',
|
|
businessEndTime: '22:00',
|
|
artists: [],
|
|
appointments: [],
|
|
daySummaries: closedWeek
|
|
})
|
|
assert.strictEqual(closedWeekState.businessHoursConfigured, false)
|
|
assert.strictEqual(closedWeekState.weekDays.every(day => day.statusText === '休'), true)
|
|
|
|
const openWeekState = closedWeekPage.buildViewState({
|
|
businessStartTime: '10:00',
|
|
businessEndTime: '22:00',
|
|
artists: [],
|
|
appointments: [],
|
|
daySummaries: closedWeek.map((day, index) => index === 2
|
|
? { ...day, shopOpen: true, shopStartTime: '10:00', shopEndTime: '22:00' }
|
|
: day)
|
|
})
|
|
assert.strictEqual(openWeekState.businessHoursConfigured, true)
|
|
|
|
page.data.viewMode = 'month'
|
|
page.data.monthDisplayMode = 'count'
|
|
const monthDays = definition.buildMonthDays.call(page, {
|
|
artists: [{ id: 1, name: '美甲师', shortName: '员', color: '#000' }],
|
|
daySummaries: [{ date: dateUtil.formatDate(dateUtil.startOfMonth(page.data.currentDateText)), totalCount: 2, unassignedCount: 1, artistCounts: [] }]
|
|
})
|
|
assert.strictEqual(monthDays.length, 42)
|
|
assert.strictEqual(monthDays.some(item => item.artistCounts.some(count => count.artistId === '__unassigned__' && count.count === 1)), true)
|
|
assert.strictEqual(monthDays.find(item => item.unassignedCount === 1).unassignedCount, 1)
|
|
const weekStart = dateUtil.formatDate(dateUtil.startOfWeek(page.data.currentDateText))
|
|
const weekDays = definition.buildWeekDays.call(page, {
|
|
artists: [{ id: 1, name: '美甲师', shortName: '员', color: '#000' }],
|
|
daySummaries: [{ date: weekStart, totalCount: 2, unassignedCount: 2, artistCounts: [] }]
|
|
})
|
|
assert.strictEqual(weekDays[0].unassignedCount, 2)
|
|
assert.strictEqual(weekDays[0].artistCounts.some(count => count.artistId === '__unassigned__'), false)
|
|
|
|
const dayPage = createPage({ currentDateText: '2026-10-12', selectedArtistId: '' })
|
|
const dayState = dayPage.buildDayView({
|
|
businessStartTime: '10:00',
|
|
businessEndTime: '22:00',
|
|
artists: [{ id: 1, name: '美甲师', color: '#000' }],
|
|
appointments: [{ orderItemId: 8, date: '2026-10-12', startTime: '2026-10-12 14:00:00', durationMinutes: 60, artistId: null }]
|
|
})
|
|
assert.strictEqual(dayState.dayLanes[0].artistId, '__unassigned__')
|
|
assert.strictEqual(dayState.dayLanes[0].blocks.length, 1)
|
|
assert.strictEqual(dayState.unassignedCount, 1)
|
|
assert.strictEqual(dayState.timelineHeight, 1854)
|
|
assert.strictEqual(dayState.timelineViewportHeight, 820)
|
|
assert.strictEqual(dayState.hours.find(item => item.label === '14:00').top, 654)
|
|
assert.strictEqual(dayState.dayLanes[0].blocks[0].height, 150)
|
|
const shortAppointmentState = dayPage.buildDayView({
|
|
businessStartTime: '10:30',
|
|
businessEndTime: '11:30',
|
|
artists: [{ id: 1, name: '美甲师', color: '#000' }],
|
|
appointments: [{ orderItemId: 9, date: '2026-10-12', startTime: '2026-10-12 10:45:00', durationMinutes: 15, artistId: 1 }]
|
|
})
|
|
assert.strictEqual(shortAppointmentState.hours[0].top, 54)
|
|
assert.strictEqual(shortAppointmentState.hours[1].top, 204)
|
|
assert.strictEqual(shortAppointmentState.timelineViewportHeight, 268)
|
|
const shortAppointmentLane = shortAppointmentState.dayLanes.find(lane => lane.artistId === 1)
|
|
assert.strictEqual(shortAppointmentLane.blocks[0].height, 40)
|
|
assert.strictEqual(shortAppointmentLane.blocks[0].compact, true)
|
|
const missingHoursPage = createPage({ viewMode: 'day', currentDateText: '2026-10-12' })
|
|
const missingHoursEmptyState = missingHoursPage.buildDayView({
|
|
artists: [{ id: 1, name: '美甲师', color: '#000' }],
|
|
appointments: []
|
|
})
|
|
assert.strictEqual(missingHoursEmptyState.hours.length, 0)
|
|
assert.strictEqual(missingHoursEmptyState.dayLanes.length, 0)
|
|
assert.strictEqual(missingHoursEmptyState.hasTimedAppointments, false)
|
|
const closedDaySummaryPage = createPage({ currentDateText: '2026-10-12' })
|
|
const closedDayState = closedDaySummaryPage.buildViewState({
|
|
businessStartTime: '10:00',
|
|
businessEndTime: '22:00',
|
|
artists: [],
|
|
appointments: [],
|
|
daySummaries: [{ date: '2026-10-12', shopOpen: false, shopStartTime: null, shopEndTime: null }]
|
|
})
|
|
assert.strictEqual(closedDayState.businessHoursConfigured, false)
|
|
assert.strictEqual(closedDayState.currentShopOpen, false)
|
|
missingHoursPage.clearCalendarView()
|
|
assert.strictEqual(missingHoursPage.data.businessHoursText, '营业时间暂不可用')
|
|
const missingHoursWithBookingState = missingHoursPage.buildDayView({
|
|
artists: [{ id: 1, name: '美甲师', color: '#000' }],
|
|
appointments: [{ orderItemId: 10, date: '2026-10-12', startTime: '2026-10-12 15:30:00', durationMinutes: 60, artistId: 1 }]
|
|
})
|
|
assert.strictEqual(missingHoursWithBookingState.hasTimedAppointments, true)
|
|
assert.strictEqual(missingHoursWithBookingState.hours[0].label, '15:00')
|
|
assert.strictEqual(missingHoursWithBookingState.hours[1].label, '16:00')
|
|
assert.strictEqual(missingHoursWithBookingState.dayLanes.find(lane => lane.artistId === 1).blocks.length, 1)
|
|
assert.match(planningWxml, /class="hour-line" style="top: \{\{hour\.top\}\}rpx;"/)
|
|
assert.match(planningWxml, /class="time-label" style="top: \{\{item\.top\}\}rpx;"/)
|
|
assert.match(planningWxss, /\.hour-line\s*\{[^}]*transform:\s*translateY\(-50%\);/)
|
|
const overlappingState = dayPage.buildDayView({
|
|
businessStartTime: '10:00',
|
|
businessEndTime: '12:00',
|
|
artists: [{ id: 1, name: '美甲师', color: '#000' }],
|
|
appointments: [
|
|
{ orderItemId: 11, date: '2026-10-12', startTime: '2026-10-12 10:00:00', durationMinutes: 60, artistId: null },
|
|
{ orderItemId: 12, date: '2026-10-12', startTime: '2026-10-12 10:30:00', durationMinutes: 60, artistId: null },
|
|
{ orderItemId: 13, date: '2026-10-12', startTime: '2026-10-12 10:45:00', durationMinutes: 30, artistId: null },
|
|
{ orderItemId: 14, date: '2026-10-12', startTime: '2026-10-12 11:30:00', durationMinutes: 60, artistId: null }
|
|
]
|
|
})
|
|
assert.strictEqual(overlappingState.dayLanes[0].width, 744)
|
|
const overlappingBlocks = overlappingState.dayLanes[0].blocks
|
|
assert.deepStrictEqual(overlappingBlocks.map(block => 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
|
|
})
|