subpackage-split.live.test.mjs 5.74 KB
import assert from 'node:assert/strict'
import test from 'node:test'
import automator from 'miniprogram-automator'
import { releaseMiniProgram } from '../../order-lifecycle/ui/uiLauncher.mjs'
import { createSplitEvidenceRecorder } from './evidence.mjs'
import { loadSplitUiConfig, requireSplitUiConfig } from './live-config.mjs'
import {
	getSplitUiRoutes,
	goByProjectRouter,
	loginAndSelectSplitContext,
	openSplitMiniProgram
} from './page-driver.mjs'

const liveEnabled = loadSplitUiConfig().enabled

const readDataAfterSettle = async (page, milliseconds = 800) => {
	await page.waitFor(milliseconds)
	return page.data()
}

test(
	'IT-SPLIT-UI-001/010/011/012/020/021/022/030: pre/post split read-only smoke',
	{ skip: !liveEnabled, timeout: 300000 },
	async () => {
		const config = requireSplitUiConfig()
		const routes = getSplitUiRoutes(config.phase)
		let miniProgram
		let recorder
		let status = '阻塞'
		let failure = ''
		try {
			miniProgram = await openSplitMiniProgram(automator, config)
			recorder = await createSplitEvidenceRecorder({
				outputDir: config.evidenceDir,
				miniProgram
			})

			const context = await loginAndSelectSplitContext(miniProgram, config)
			assert.equal(String(context.storeName), config.storeName)
			assert.equal(Number(context.sceneType), 1)
			recorder.add('IT-SPLIT-UI-001', { context })

			const startPage = await goByProjectRouter(
				miniProgram,
				routes.aiStartAlias,
				{},
				routes.aiStartPath
			)
			assert.equal(startPage.path, routes.aiStartPath)
			recorder.add('IT-SPLIT-UI-010', {
				alias: routes.aiStartAlias,
				path: startPage.path
			})
			await recorder.screenshot('ai-start')

			await miniProgram.navigateBack()
			const listRoute =
				`${routes.aiExerciseListAlias}?staffid=${encodeURIComponent(config.aiTaskId)}` +
				'&tryCount=1&roleType=7&promptOnOff=true'
			const listPage = await goByProjectRouter(
				miniProgram,
				listRoute,
				{},
				routes.aiExerciseListPath
			)
			const listData = await readDataAfterSettle(listPage)
			assert.equal(String(listData.taskStaffId), config.aiTaskId)
			assert.equal(String(listData.tryCount), '1')
			assert.equal(String(listData.roleType), '7')
			assert.equal(listData.promptOnOff, true)
			recorder.add('IT-SPLIT-UI-011', {
				path: listPage.path,
				taskStaffId: listData.taskStaffId,
				tryCount: listData.tryCount,
				roleType: listData.roleType,
				promptOnOff: listData.promptOnOff
			})

			await miniProgram.navigateBack()
			const inspectionPage = await goByProjectRouter(
				miniProgram,
				routes.aiInspectionDetailAlias,
				{
					id: config.aiTaskId,
					estimatedResult: '未知',
					customerName: '自动化脱敏客户'
				},
				routes.aiInspectionDetailPath
			)
			assert.equal(
				String((await inspectionPage.data('detailInfo'))?.id),
				config.aiTaskId
			)
			await miniProgram.navigateBack()
			const receptionPage = await goByProjectRouter(
				miniProgram,
				routes.aiInspectionReceptionAlias,
				{ title: '自动化质检项', marker: 'reception-back' },
				routes.aiInspectionReceptionPath
			)
			assert.equal(
				(await receptionPage.data('detailInfo'))?.marker,
				'reception-back'
			)
			await miniProgram.navigateBack()
			recorder.add('IT-SPLIT-UI-012', {
				detailPath: inspectionPage.path,
				receptionPath: receptionPage.path,
				backPath: (await miniProgram.currentPage())?.path
			})

			for (const [alias, expectedPath] of [
				[routes.staffDailyAlias, routes.staffDailyPath],
				[routes.upgradeStaffDailyAlias, routes.upgradeStaffDailyPath]
			]) {
				const page = await goByProjectRouter(
					miniProgram,
					`${alias}?reportDate=${encodeURIComponent(config.reportDate)}`,
					{},
					expectedPath
				)
				assert.equal(page.path, expectedPath)
				await miniProgram.navigateBack()
			}
			recorder.add('IT-SPLIT-UI-020', {
				reportDate: config.reportDate,
				paths: [routes.staffDailyPath, routes.upgradeStaffDailyPath]
			})

			for (const [reportTypeAttr, reportType] of [
				['daily', 1],
				['weekly', 2],
				['monthly', 3]
			]) {
				const page = await goByProjectRouter(
					miniProgram,
					routes.supervisorDailyAlias,
					{
						params: {
							reportTypeAttr,
							reportType,
							code: `split-smoke-${reportTypeAttr}`
						}
					},
					routes.supervisorDailyPath
				)
				const routeParams = await page.data('routeParams')
				assert.equal(routeParams.reportTypeAttr, reportTypeAttr)
				assert.equal(Number(routeParams.reportType), reportType)
				if (reportTypeAttr === 'daily') {
					await page.setData({
						tmlpObj: { smoke: [] },
						tabActive: 'smoke',
						tabChange: true
					})
					assert.ok(await page.$('gl-cust-form'))
					recorder.add('IT-SPLIT-UI-022', { component: 'gl-cust-form' })
				}
				await miniProgram.navigateBack()
			}
			recorder.add('IT-SPLIT-UI-021', {
				path: routes.supervisorDailyPath,
				reportTypes: ['daily', 'weekly', 'monthly']
			})

			const h5Page = await miniProgram.reLaunch(
				`/${routes.upgradeStaffDailyPath}?reportDate=${encodeURIComponent(config.reportDate)}`
			)
			assert.equal(h5Page.path, routes.upgradeStaffDailyPath)
			recorder.add('IT-SPLIT-UI-030', {
				path: h5Page.path,
				reportDate: config.reportDate
			})
			await recorder.screenshot('report-deep-link')

			recorder.add('write-guard', {
				allowAiWrite: config.allowAiWrite,
				allowReportWrite: config.allowReportWrite,
				performedWrites: false
			})
			status = '通过'
		} catch (error) {
			failure = error instanceof Error ? error.message : 'Unknown split UI error'
			if (recorder) recorder.add('failure', { message: failure })
			throw error
		} finally {
			if (recorder) {
				await recorder.write({
					caseId: 'IT-SPLIT-UI-001-030',
					phase: config.phase,
					status,
					error: failure
				})
			}
			if (miniProgram) await releaseMiniProgram(miniProgram, config)
		}
	}
)