mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-17 19:22:02 +00:00
定时任务前端:触发历史加「对比上一次」,运行详情页头的「由定时任务「X」发起」改成键盘可达的链接
- 触发历史:服务端给了 compare 的那次触发,在运行链接前加「对比上一次」,链到对比页(本次是这次触发的运行、 基准是服务端自动对比时取的同一任务上一次),带上来历让对比页写「默认基准:同一定时任务的上一次运行」。悬停写 各类指标的个数,和 Webhook 通知那一行同一个写法(三类总写、其余有才写、两边都没有指标时不写一串 0 个),读屏 当说明念;只有个数。compare 为 null、老服务端不给时不显示 - 运行详情页头:定时任务发起的运行,「谁发起的」那一段换成到 /schedules/:id 的真链接(Tab 到得了、回车能开, 有焦点环)。到点发起的(署名是「定时任务:X」)整句换成「由定时任务「X」发起」,不再写两遍;有人署名点了 立即运行的,署名照写、后面接「来自定时任务「X」」。名字取定时任务现在的名字,取不到用署名里记的;长名字截断, 全名在悬停里。记录页「定时」标记的说明同步改成指向这里 - types.ts 定时任务那一段加 ScheduleFireCompare 和 ScheduleFire.compare;文案进 SCHEDULE_TEXT - check-schedules:触发历史的对比链接(地址、悬停的计数、只在有 compare 的行出现、Tab 到得了、回车打开对比页)、 运行详情页头的链接(现在的名字、真链接、不重复署名、Tab 到得了且有焦点环、回车去定时任务、署名的立即运行、 手动运行没有、长名字截断不撑宽、浅色可读),390px 深浅色下对比链接在屏幕里、看得清
This commit is contained in:
@@ -3050,6 +3050,37 @@ export const SCHEDULE_TEXT = {
|
||||
allLoaded: '已全部加载',
|
||||
shown: (n: number) => `已显示 ${n} 条`,
|
||||
|
||||
// ---- 触发历史里的对比:运行结束后服务端自动和同一定时任务的上一次比一次
|
||||
compareLink: '对比上一次',
|
||||
/**
|
||||
* 悬停写各类指标的个数,和 Webhook 通知里那一行同一个写法(服务端 scheduler/auto_compare.py 的 summary_text):
|
||||
* 变化三分法的三类总写上,0 个也写;其余各类有才写,次序同对比页;两边都没有指标时不写一串 0 个。只有个数,
|
||||
* 不写数值。各类的叫法用对比页那一套(RUN_COMPARE_TEXT.classLabel)
|
||||
*/
|
||||
compareTitle: (summary: Partial<Record<string, number>>) => {
|
||||
const n = (key: string) => (typeof summary[key] === 'number' ? summary[key] as number : 0)
|
||||
const core = ['data_only', 'caliber_and_data', 'sql_changed']
|
||||
const rest = ['params_only', 'added', 'removed', 'incomparable', 'unchanged']
|
||||
if (![...core, ...rest].some((key) => n(key) > 0)) return '与上一次相比:两次运行都没有指标'
|
||||
const parts = [...core, ...rest.filter((key) => n(key) > 0)]
|
||||
.map((key) => `${RUN_COMPARE_TEXT.classLabel[key] ?? key} ${n(key)} 个`)
|
||||
return `与上一次相比:${parts.join('、')}`
|
||||
},
|
||||
|
||||
// ---- 运行详情页头的来源
|
||||
/**
|
||||
* 到点发起(以及没有署名的立即运行)的运行记在「定时任务:名字」名下,前缀和服务端 scheduler/service.py 的
|
||||
* actor_label 一致。页头据此不再写「定时任务:X 发起」,换成下面那条链接
|
||||
*/
|
||||
actorPrefix: '定时任务:',
|
||||
runSource: (name?: string | null) => (name ? `由定时任务「${name}」发起` : '由定时任务发起'),
|
||||
/** 有人署名点「立即运行」发起的:署名照写(runStarter),后面接这一句 */
|
||||
runSourceManual: (name?: string | null) => (name ? `来自定时任务「${name}」` : '来自定时任务'),
|
||||
runStarter: (who: string) => `${who} 发起`,
|
||||
/** 悬停写全名(页头窄时链接会截断)和点开去哪 */
|
||||
runSourceTitle: (name?: string | null) =>
|
||||
(name ? `定时任务「${name}」:查看设置和触发历史` : '查看这个定时任务的设置和触发历史'),
|
||||
|
||||
// ---- 记录页的定时标记
|
||||
runTag: '定时',
|
||||
runTagTitle: (name?: string | null) => (name ? `由定时任务「${name}」发起,点击查看` : '由定时任务发起,点击查看'),
|
||||
|
||||
@@ -31,6 +31,7 @@ import { ProvenanceBar, Telemetry, runClocks } from './Telemetry'
|
||||
import { TracePane } from './TracePane'
|
||||
import { useRunDetail } from './useRunDetail'
|
||||
import { useCompareEntry } from './compare/entry'
|
||||
import { RunScheduleSource } from '../schedules/parts'
|
||||
|
||||
/**
|
||||
* 一次运行的详情:头部读数、凭证、排错路径,下面分三个视图——
|
||||
@@ -561,9 +562,12 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
|
||||
{formatTime(run.created_at ?? null, new Date(now))}
|
||||
</time>
|
||||
<span>·</span>
|
||||
<span title={run.started_by ? undefined : '发起时未设置署名'}>
|
||||
{run.started_by || '未署名'} 发起
|
||||
</span>
|
||||
{/* 定时任务发起的:写成到那个定时任务的链接(键盘可达;记录页的「定时」标记只能鼠标点) */}
|
||||
{run.schedule_id ? <RunScheduleSource scheduleId={run.schedule_id} startedBy={run.started_by} /> : (
|
||||
<span title={run.started_by ? undefined : '发起时未设置署名'}>
|
||||
{run.started_by || '未署名'} 发起
|
||||
</span>
|
||||
)}
|
||||
<span>·</span>
|
||||
<span className="tnum">{formatNumber(d.events.length)} 条事件</span>
|
||||
{workflowGone && <span>· 工作流已删除</span>}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ChevronRight, History, RotateCw } from 'lucide-react'
|
||||
import { ChevronRight, GitCompareArrows, History, RotateCw } from 'lucide-react'
|
||||
import { api } from '../../api/client'
|
||||
import { EmptyState, ErrorState, Skeleton, Spinner, StatusPill, toast, useTicker } from '../../components/ui'
|
||||
import { formatDateTime, parseServerTime } from '../../lib/format'
|
||||
import { SCHEDULE_TEXT as T } from '../../lib/terms'
|
||||
import type { Schedule, ScheduleFire } from '../../types'
|
||||
import type { Schedule, ScheduleFire, ScheduleFireCompare } from '../../types'
|
||||
import { comparePath, type CompareVia } from '../runs/compare/entry'
|
||||
import { FireKindChip, FireStatusChip, ZonedTime } from './parts'
|
||||
|
||||
const PAGE = 20
|
||||
|
||||
/**
|
||||
* 触发历史:每次触发一行,新的在前,20 条一页、「加载更多」往后接。计划时间按定时任务的时区写;跳过、发起失败
|
||||
* 写原因;发起了的链到那次运行、写运行现在的状态;发出去的通知逐条写结果。refreshKey 变了(立即运行之后)从头重取
|
||||
* 写原因;发起了的链到那次运行、写运行现在的状态;运行结束后服务端和同一任务的上一次比过的,另给「对比上一次」;
|
||||
* 发出去的通知逐条写结果。refreshKey 变了(立即运行之后)从头重取
|
||||
*/
|
||||
export function FireHistory({ schedule, refreshKey }: { schedule: Schedule; refreshKey: number }) {
|
||||
const [items, setItems] = useState<ScheduleFire[] | null>(null)
|
||||
@@ -110,6 +112,7 @@ function FireRow({ fire: f, tz, now }: { fire: ScheduleFire; tz: string; now: nu
|
||||
<FireKindChip fire={f} />
|
||||
<FireStatusChip fire={f} />
|
||||
<span className="flex-1" />
|
||||
{f.run_id && f.compare && <CompareLink runId={f.run_id} compare={f.compare} />}
|
||||
{f.run_id ? (
|
||||
<Link to={`/runs/${encodeURIComponent(f.run_id)}`} className="inline-flex shrink-0 items-center gap-1.5 text-2xs text-dim hover:text-fg hover:underline">
|
||||
{f.run_status && <StatusPill status={f.run_status} plain />}
|
||||
@@ -137,3 +140,23 @@ function FireRow({ fire: f, tz, now }: { fire: ScheduleFire; tz: string; now: nu
|
||||
</li>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 「对比上一次」:去对比页,本次是这次触发的运行、基准是服务端自动对比时取的同一任务的上一次。悬停写各类指标的个数
|
||||
* (和通知里那一行同一个写法),读屏把它当说明念。带上来历,对比页据此写「默认基准:同一定时任务的上一次运行」
|
||||
*/
|
||||
function CompareLink({ runId, compare }: { runId: string; compare: ScheduleFireCompare }) {
|
||||
const via: CompareVia = { base: compare.base_run_id, reason: 'same_schedule' }
|
||||
return (
|
||||
<Link
|
||||
to={comparePath(runId, compare.base_run_id)}
|
||||
state={via}
|
||||
title={T.compareTitle(compare.summary)}
|
||||
data-fire-compare={compare.base_run_id}
|
||||
className="inline-flex shrink-0 items-center gap-1 rounded-sm text-2xs text-dim outline-none hover:text-fg hover:underline focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
|
||||
>
|
||||
<GitCompareArrows size={11} aria-hidden />
|
||||
{T.compareLink}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -269,8 +269,8 @@ export function useScheduleNames(ids: (string | null | undefined)[]): ReadonlyMa
|
||||
* 这里拦住冒泡,只去定时任务、不打开运行。
|
||||
*
|
||||
* 按钮里放不了可聚焦的链接(读屏会把按钮里的内容压平,Tab 也到不了),所以键盘到不了这个标记:读屏改念
|
||||
* 「由定时任务「X」发起」,至少在整行的名字里听到来源。键盘可达的入口要放到运行详情的页头,或者把整行改成
|
||||
* 「打开运行」按钮和这个链接并排,都不在本页的文件里,见交付说明
|
||||
* 「由定时任务「X」发起」,至少在整行的名字里听到来源。键盘可达的入口在运行详情的页头(RunScheduleSource):
|
||||
* 打开这次运行之后,Tab 就能到那条链接
|
||||
*/
|
||||
export function ScheduleTag({ scheduleId, name }: { scheduleId: string; name?: string | null }) {
|
||||
const navigate = useNavigate()
|
||||
@@ -291,3 +291,40 @@ export function ScheduleTag({ scheduleId, name }: { scheduleId: string; name?: s
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 运行详情页头的来源
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 运行详情页头里「谁发起的」那一段,定时任务发起的运行用它:「由定时任务「X」发起」是真的链接,Tab 到得了、回车能
|
||||
* 打开,去那个定时任务的设置和触发历史。记录页的「定时」标记在整行按钮里,只能用鼠标点,键盘的入口在这里。
|
||||
*
|
||||
* 到点发起的运行(以及没有署名的立即运行)记在「定时任务:X」名下:原来那句「定时任务:X 发起」整句换成这条链接,
|
||||
* 不写两遍。有人署名点「立即运行」的,署名照写,后面接「来自定时任务「X」」。名字取定时任务现在的名字(改过名的写
|
||||
* 新名字),取不到时用署名里记的那个,再没有就不写名字。页头窄时链接截断,全名在悬停里
|
||||
*/
|
||||
export function RunScheduleSource({ scheduleId, startedBy }: { scheduleId: string; startedBy?: string | null }) {
|
||||
const names = useScheduleNames([scheduleId])
|
||||
const recorded = startedBy?.startsWith(T.actorPrefix) ? startedBy.slice(T.actorPrefix.length).trim() : null
|
||||
const auto = !startedBy || recorded != null
|
||||
const name = names.get(scheduleId) || recorded || null
|
||||
const link = (
|
||||
<Link
|
||||
to={`/schedules/${encodeURIComponent(scheduleId)}`}
|
||||
title={T.runSourceTitle(name)}
|
||||
data-run-schedule-link={scheduleId}
|
||||
className="min-w-0 truncate rounded-sm text-dim outline-none hover:text-fg hover:underline focus-visible:ring-2 focus-visible:ring-[var(--accent)]"
|
||||
>
|
||||
{auto ? T.runSource(name) : T.runSourceManual(name)}
|
||||
</Link>
|
||||
)
|
||||
if (auto || !startedBy) return link
|
||||
return (
|
||||
<>
|
||||
<span className="shrink-0">{T.runStarter(startedBy)}</span>
|
||||
<span>·</span>
|
||||
{link}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3207,6 +3207,15 @@ export interface ScheduleFireNotice {
|
||||
at: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行结束后和同一定时任务上一次运行的自动对比:基准是哪一次、各类指标的个数(同对比接口的 summary)。只有个数,
|
||||
* 具体的数在对比页上
|
||||
*/
|
||||
export interface ScheduleFireCompare {
|
||||
base_run_id: string
|
||||
summary: RunCompareSummary
|
||||
}
|
||||
|
||||
/** 一次触发(触发历史的一行) */
|
||||
export interface ScheduleFire {
|
||||
id: string
|
||||
@@ -3220,6 +3229,10 @@ export interface ScheduleFire {
|
||||
/** 跳过、发起失败的原因(中文) */
|
||||
reason: string | null
|
||||
notified: ScheduleFireNotice[]
|
||||
/**
|
||||
* 和同一定时任务上一次的对比。没有上一次、还没算、比不了、运行又在执行(不在终态)时为 null;老服务端不给
|
||||
*/
|
||||
compare?: ScheduleFireCompare | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
|
||||
+164
-3
@@ -3,7 +3,9 @@
|
||||
// 守的是这些「看着没坏、其实不能用」的地方:预设生成的 cron 不对(选了每周一 09:00,交上去的是每天)、时区按本机写
|
||||
// 而不是按定时任务的时区、预览不防抖、非法 cron 只弹一句不知道指哪一项、启用开关不带版本号(别人改过也照样覆盖)、
|
||||
// 立即运行之后没有下文、触发历史只有一页、保存过的 Webhook 地址又被原样显示出来、改了别的字段却把地址清掉、
|
||||
// 记录页看不出哪些运行来自定时任务、390px 窄屏被表单撑出横向滚动。
|
||||
// 记录页看不出哪些运行来自定时任务、390px 窄屏被表单撑出横向滚动。运行结束后的自动对比:触发历史里「对比上一次」
|
||||
// 链到对比页、悬停只写各类指标的个数;运行详情页头的「由定时任务「X」发起」是键盘到得了的真链接(记录页的「定时」
|
||||
// 标记在整行按钮里,只能鼠标点)。
|
||||
// 还有几处时序和口径:晚到的刷新把刚切换的开关盖回去、先开触发历史再开设置时带着旧版本撞假的 409、保存途中又改了
|
||||
// 别的字段时替换过的地址明文留在框里、服务端会拒的组合(未发布 + 正式运行、必填没填、已发布版本里没有的字段)
|
||||
// 照样放行、测试消息的结果把服务端的整句又套一层、错过已跳过的那条悬停另说一个原因(和本条记的原因对不上)。
|
||||
@@ -375,6 +377,13 @@ const S2 = {
|
||||
* 原因却有两种,各放一条、原因照服务端的原话写:f03 是停机一周多、在宽限内恢复时积压的那一次(最近一次就是补发的
|
||||
* f02),f05 是超出补发宽限的。f06、f07 没有记原因(约定里 reason 可以是 null),看兜底的说明
|
||||
*/
|
||||
/** 服务端自动对比给的计数(只有个数):f00 和同一任务的上一次(run-f02)比过 */
|
||||
const COMPARE_F00 = { base_run_id: 'run-f02', summary: { unchanged: 4, data_only: 3, caliber_and_data: 1, sql_changed: 0,
|
||||
params_only: 2, added: 0, removed: 0, incomparable: 0 } }
|
||||
const COMPARE_F00_TITLE = '与上一次相比:只数据变 3 个、口径与数据都变 1 个、SQL 结构变 0 个、只参数变 2 个、未变 4 个'
|
||||
const NO_METRICS = { base_run_id: 'run-f09', summary: { unchanged: 0, data_only: 0, caliber_and_data: 0, sql_changed: 0,
|
||||
params_only: 0, added: 0, removed: 0, incomparable: 0 } }
|
||||
|
||||
function makeFires() {
|
||||
const out = []
|
||||
const local = (at) => {
|
||||
@@ -385,14 +394,15 @@ function makeFires() {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const at = iso(nextMonday9(-(i + 1)))
|
||||
let f = fire(`f${String(i).padStart(2, '0')}`, { fire_at: at, created_at: at })
|
||||
if (i === 0) f = { ...f, kind: 'manual', notified: [{ event: 'finished', status: 'ok', at }, { event: 'failed', status: 'failed', at }] }
|
||||
if (i === 0) f = { ...f, kind: 'manual', compare: COMPARE_F00, notified: [{ event: 'finished', status: 'ok', at }, { event: 'failed', status: 'failed', at }] }
|
||||
if (i === 1) f = { ...f, status: 'skipped_overlap', run_id: null, run_status: null, reason: '上一次运行(#9f8e7d)尚未结束' }
|
||||
if (i === 2) f = { ...f, kind: 'misfire', run_status: 'failed' }
|
||||
if (i === 2) f = { ...f, kind: 'misfire', run_status: 'failed', compare: null }
|
||||
if (i === 3) f = { ...f, ...missed, reason: `服务未运行,错过了 ${local(at)} 的触发;积压的触发不补,只发起最近一次` }
|
||||
if (i === 4) f = { ...f, status: 'failed_to_start', run_id: null, run_status: null, reason: '工作流「门店周报」还没有发布:正式运行需要已发布的版本' }
|
||||
if (i === 5) f = { ...f, ...missed, reason: `服务未运行,错过了 ${local(at)} 的触发,超出补发宽限(1 小时),没有发起` }
|
||||
if (i === 6) f = { ...f, ...missed, reason: null }
|
||||
if (i === 7) f = { ...f, status: 'failed_to_start', run_id: null, run_status: null, reason: null }
|
||||
if (i === 8) f = { ...f, compare: NO_METRICS }
|
||||
out.push(f)
|
||||
}
|
||||
return out
|
||||
@@ -401,12 +411,27 @@ function makeFires() {
|
||||
const RUNS = [
|
||||
{ id: 'run-sched-1', workflow_id: 'wf-weekly', workflow_name: '门店周报', status: 'succeeded', input: { date: '2026-10-04' },
|
||||
output: { 周报: '上周销售额 1,234 万元' }, error: null, usage: { duration_ms: 4200 }, run_class: 'formal', version: 3,
|
||||
started_by: '定时任务:门店周报(旧名)',
|
||||
schedule_id: 's-weekly', created_at: iso(NOW - 2 * H), started_at: iso(NOW - 2 * H), finished_at: iso(NOW - 2 * H + 4200) },
|
||||
{ id: 'run-manual-1', workflow_id: 'wf-weekly', workflow_name: '门店周报', status: 'succeeded', input: { date: '2026-10-03' },
|
||||
output: { 周报: '手动补一份' }, error: null, usage: { duration_ms: 3900 }, run_class: 'exploratory', version: null,
|
||||
schedule_id: null, created_at: iso(NOW - 3 * H), started_at: iso(NOW - 3 * H), finished_at: iso(NOW - 3 * H + 3900) },
|
||||
]
|
||||
|
||||
/** 有人署名点了「立即运行」:署名照写,页头另接到定时任务的链接 */
|
||||
const RUN_MANUAL_FIRE = { ...RUNS[0], id: 'run-sched-2', started_by: '检查员甲', created_at: iso(NOW - H), started_at: iso(NOW - H),
|
||||
finished_at: iso(NOW - H + 4200) }
|
||||
/** 运行详情要的图和事件:一个节点、开始到结束两条,够页头和时间线画出来 */
|
||||
const RUN_GRAPH = { nodes: [{ id: 'out', type: 'output', position: { x: 0, y: 0 }, data: { label: '成果', config: {} } }], edges: [] }
|
||||
function runEvents(run) {
|
||||
const t0 = Date.parse(run.started_at) / 1000
|
||||
return [
|
||||
{ seq: 1, type: 'run.started', node_id: null, ts: t0, data: { nodes: 1 } },
|
||||
{ seq: 2, type: 'run.finished', node_id: null, ts: t0 + 4.2,
|
||||
data: { output: run.output, usage: {}, timing: { wall_ms: 4200, active_ms: 4200, wait_ms: 0 } } },
|
||||
]
|
||||
}
|
||||
|
||||
function freshState(patch = {}) {
|
||||
return {
|
||||
schedules: [structuredClone(S1), structuredClone(S2)],
|
||||
@@ -538,7 +563,13 @@ async function reply(state, method, path, url, body) {
|
||||
if (state.runs && method === 'GET' && path.startsWith('/runs/')) {
|
||||
const run = state.runs.find((r) => path === `/runs/${r.id}`)
|
||||
if (run) return { json: run }
|
||||
const m = path.match(/^\/runs\/([^/]+)\/(events|graph|artifacts)$/)
|
||||
const of = m && state.runs.find((r) => r.id === m[1])
|
||||
if (of && m[2] === 'events') return { json: runEvents(of) }
|
||||
if (of && m[2] === 'graph') return { json: { graph: RUN_GRAPH, workflow_id: of.workflow_id, version: of.version } }
|
||||
if (of) return { json: [] }
|
||||
}
|
||||
if (state.runs && method === 'GET' && path === '/approvals' && url.searchParams.get('run_id')) return { json: [] }
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -621,6 +652,18 @@ const saveDone = (page) => until(async () => {
|
||||
/** 等预览算完、说的是这个频率 */
|
||||
const previewSays = (page, words) => until(async () => (await page.locator('[data-schedule-preview][data-status="ok"]').count()) === 1
|
||||
&& (await page.locator('[data-schedule-preview]').innerText()).includes(words))
|
||||
/**
|
||||
* 只按 Tab 键把焦点移到 sel 上:从页面开头往后按,最多按 max 次。按到了返回按了几次,按不到返回 0。键盘可达就是
|
||||
* 这个意思——鼠标能点、程序能 focus() 的不算
|
||||
*/
|
||||
const tabTo = async (page, sel, max = 160) => {
|
||||
await page.evaluate(() => document.activeElement?.blur?.())
|
||||
for (let i = 1; i <= max; i++) {
|
||||
await page.keyboard.press('Tab')
|
||||
if (await page.evaluate((s) => !!document.activeElement?.matches?.(s), sel)) return i
|
||||
}
|
||||
return 0
|
||||
}
|
||||
/** 元素整个在视口的横向范围里 */
|
||||
const inViewX = (page, sel) => page.evaluate((s) => {
|
||||
const el = document.querySelector(s)
|
||||
@@ -1335,6 +1378,117 @@ await section('详情:触发历史分页', async () => {
|
||||
&& await gone.page.locator('[data-schedule-missing] a[href="/schedules"]').count() === 1)
|
||||
})
|
||||
|
||||
await section('详情:触发历史里的「对比上一次」', async () => {
|
||||
const { page, sent, errors } = await open('/schedules/s-weekly?tab=history')
|
||||
await page.locator('[data-fire-id]').first().waitFor()
|
||||
const row = (id) => page.locator(`[data-fire-id="${id}"]`)
|
||||
const link = row('f00').locator('[data-fire-compare]')
|
||||
check('有对比的那次:给「对比上一次」', (await link.count()) === 1 && (await link.innerText()).trim() === '对比上一次',
|
||||
await link.count() ? await link.innerText() : '没有链接')
|
||||
check('……链到对比页,本次是这次的运行、基准是服务端比过的那一次',
|
||||
await link.getAttribute('href') === '/runs/compare?target=run-f00&base=run-f02', (await link.getAttribute('href')) ?? '')
|
||||
const title = (await link.getAttribute('title')) ?? ''
|
||||
check('……悬停写各类指标的个数:三类总写,其余有才写,没有数值', title === COMPARE_F00_TITLE, title)
|
||||
check('两边都没有指标:悬停不写一串 0 个', ((await row('f08').locator('[data-fire-compare]').getAttribute('title')) ?? '')
|
||||
=== '与上一次相比:两次运行都没有指标')
|
||||
const linked = await page.locator('[data-fire-compare]').evaluateAll((els) => els.map((e) => e.closest('[data-fire-id]')?.getAttribute('data-fire-id')))
|
||||
check('没有对比的(compare 为 null、老服务端不给、没有运行)不给链接', JSON.stringify(linked) === '["f00","f08"]', JSON.stringify(linked))
|
||||
check('运行链接照旧在', await row('f00').locator('a[href="/runs/run-f00"]').count() === 1)
|
||||
const presses = await tabTo(page, '[data-fire-id="f00"] [data-fire-compare]')
|
||||
check('键盘:Tab 到得了「对比上一次」', presses > 0, `按了 ${presses} 次`)
|
||||
await shot(page, 'history-compare-focus-dark')
|
||||
await page.keyboard.press('Enter')
|
||||
const url = await until(() => {
|
||||
const u = new URL(page.url())
|
||||
return u.pathname === '/runs/compare' ? u : null
|
||||
})
|
||||
check('……回车打开对比页,带着本次和基准', !!url && url.searchParams.get('target') === 'run-f00'
|
||||
&& url.searchParams.get('base') === 'run-f02', page.url())
|
||||
const real = writes(sent, /./).filter((x) => x.key !== 'POST /schedules/preview')
|
||||
check('只读:没有写请求', real.length === 0, real.map((x) => x.key).join('、'))
|
||||
check('没有页面报错', !errors.length, errors.join(' | '))
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------- 运行详情
|
||||
|
||||
await section('运行详情:页头的定时任务链接', async () => {
|
||||
const state = freshState({ runs: [...RUNS, RUN_MANUAL_FIRE] })
|
||||
const { page, sent, errors } = await open('/runs/run-sched-1', { state })
|
||||
await page.locator('[data-run-detail="run-sched-1"]').waitFor({ timeout: 10000 })
|
||||
const head = page.locator('[data-run-detail] header').first()
|
||||
const link = head.locator('[data-run-schedule-link]')
|
||||
// 署名里记的是旧名字:取到定时任务列表之后写现在的名字
|
||||
const said = await until(async () => {
|
||||
const t = (await link.innerText().catch(() => '')).trim()
|
||||
return t === '由定时任务「门店周报 · 每周」发起' ? t : null
|
||||
})
|
||||
check('页头写「由定时任务「X」发起」,X 是定时任务现在的名字', !!said, (await link.innerText().catch(() => '没有链接')).trim())
|
||||
check('……是到那个定时任务的真链接', (await link.evaluate((el) => el.tagName)) === 'A'
|
||||
&& await link.getAttribute('href') === '/schedules/s-weekly', (await link.getAttribute('href')) ?? '')
|
||||
const headText = await head.innerText()
|
||||
check('……不再另写「定时任务:X 发起」', !headText.includes('定时任务:') && !headText.includes('旧名'), oneLine([headText]).slice(0, 160))
|
||||
check('……悬停写全名和点开去哪', ((await link.getAttribute('title')) ?? '').includes('门店周报 · 每周'))
|
||||
const presses = await tabTo(page, '[data-run-detail] header [data-run-schedule-link]')
|
||||
check('键盘:Tab 到得了页头的定时任务链接', presses > 0, `按了 ${presses} 次`)
|
||||
const ring = await page.evaluate(() => getComputedStyle(document.activeElement).boxShadow)
|
||||
check('……聚焦时有焦点环', !!ring && ring !== 'none', ring)
|
||||
await shot(page, 'run-detail-schedule-link-dark')
|
||||
await page.keyboard.press('Enter')
|
||||
check('……回车去那个定时任务', await until(() => new URL(page.url()).pathname === '/schedules/s-weekly'), page.url())
|
||||
await page.locator('[data-schedule-form], [data-schedules-page] header').first().waitFor()
|
||||
|
||||
const manual = await open('/runs/run-sched-2', { state: freshState({ runs: [...RUNS, RUN_MANUAL_FIRE] }) })
|
||||
await manual.page.locator('[data-run-detail="run-sched-2"]').waitFor({ timeout: 10000 })
|
||||
const mHead = manual.page.locator('[data-run-detail] header').first()
|
||||
const mLink = mHead.locator('[data-run-schedule-link]')
|
||||
await until(async () => (await mLink.innerText().catch(() => '')).includes('门店周报 · 每周'))
|
||||
const mText = oneLine([await mHead.innerText()])
|
||||
check('有人署名点了立即运行:署名照写,后面接「来自定时任务「X」」的链接', mText.includes('检查员甲 发起')
|
||||
&& (await mLink.innerText()).trim() === '来自定时任务「门店周报 · 每周」' && await mLink.getAttribute('href') === '/schedules/s-weekly',
|
||||
mText.slice(0, 160))
|
||||
|
||||
await shot(manual.page, 'run-detail-manual-fire-dark')
|
||||
const light = await open('/runs/run-sched-1', { state: freshState({ runs: [...RUNS, RUN_MANUAL_FIRE] }), theme: 'light' })
|
||||
await light.page.locator('[data-run-detail="run-sched-1"] header [data-run-schedule-link]').waitFor()
|
||||
const lightTone = await light.page.evaluate(() => {
|
||||
const link = document.querySelector('[data-run-detail] header [data-run-schedule-link]')
|
||||
const head = document.querySelector('[data-run-detail] header')
|
||||
return { theme: document.documentElement.dataset.theme, fg: getComputedStyle(link).color,
|
||||
bg: getComputedStyle(head).backgroundColor }
|
||||
})
|
||||
check('浅色:页头的定时任务链接字和底色分得开', lightTone.theme === 'light' && lightTone.fg !== lightTone.bg, JSON.stringify(lightTone))
|
||||
await shot(light.page, 'run-detail-schedule-link-light')
|
||||
const plain = await open('/runs/run-manual-1', { state: freshState({ runs: [...RUNS, RUN_MANUAL_FIRE] }) })
|
||||
await plain.page.locator('[data-run-detail="run-manual-1"]').waitFor({ timeout: 10000 })
|
||||
check('手动发起的运行:页头没有定时任务链接', await plain.page.locator('[data-run-detail] header [data-run-schedule-link]').count() === 0)
|
||||
|
||||
// 名字很长、详情区不宽时链接截断,不把页头撑宽(全名在悬停里)
|
||||
const longName = freshState({ runs: [...RUNS, RUN_MANUAL_FIRE] })
|
||||
longName.schedules = longName.schedules.map((x) => (x.id === 's-weekly' ? { ...x, name: '华东区全部门店按品类与渠道拆分的周度销售与退款复盘' } : x))
|
||||
const narrow = await open('/runs/run-sched-1', { state: longName, width: 900 })
|
||||
await narrow.page.locator('[data-run-detail="run-sched-1"]').waitFor({ timeout: 10000 })
|
||||
const nLink = narrow.page.locator('[data-run-detail] header [data-run-schedule-link]')
|
||||
await until(async () => (await nLink.innerText().catch(() => '')).includes('复盘'))
|
||||
const fit = await narrow.page.evaluate(() => {
|
||||
const head = document.querySelector('[data-run-detail] header')
|
||||
const link = head?.querySelector('[data-run-schedule-link]')
|
||||
if (!head || !link) return null
|
||||
const h = head.getBoundingClientRect()
|
||||
const l = link.getBoundingClientRect()
|
||||
return { headRight: Math.round(h.right), linkRight: Math.round(l.right), scroll: head.scrollWidth - head.clientWidth,
|
||||
clipped: link.scrollWidth > link.clientWidth }
|
||||
})
|
||||
check('长名字:链接截断,不超出页头、页头不横向溢出', !!fit && fit.linkRight <= fit.headRight && fit.scroll <= 1 && fit.clipped,
|
||||
JSON.stringify(fit))
|
||||
// 回车打开的定时任务页会请求预览(POST,但只读),不算写
|
||||
const writesSeen = [...writes(sent, /./), ...writes(manual.sent, /./), ...writes(light.sent, /./), ...writes(plain.sent, /./),
|
||||
...writes(narrow.sent, /./)]
|
||||
.filter((x) => x.key !== 'POST /schedules/preview')
|
||||
check('只读:没有写请求', writesSeen.length === 0, writesSeen.map((x) => x.key).join('、'))
|
||||
const all = [...errors, ...manual.errors, ...light.errors, ...plain.errors, ...narrow.errors]
|
||||
check('没有页面报错', !all.length, all.join(' | '))
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------- 记录页
|
||||
|
||||
await section('记录页:定时标记', async () => {
|
||||
@@ -1416,6 +1570,13 @@ await section('窄屏 390px 与浅色', async () => {
|
||||
const hist = await open('/schedules/s-weekly?tab=history', { ...narrow, theme })
|
||||
await hist.page.locator('[data-fire-id]').first().waitFor()
|
||||
check(`${theme}:触发历史不横向溢出`, await overflow(hist.page) <= 1, `${await overflow(hist.page)}px`)
|
||||
check(`${theme}:「对比上一次」在屏幕里`, await inViewX(hist.page, '[data-fire-id="f00"] [data-fire-compare]'))
|
||||
const cmp = await hist.page.evaluate(() => {
|
||||
const link = document.querySelector('[data-fire-id="f00"] [data-fire-compare]')
|
||||
const list = document.querySelector('[data-fire-list] ul')
|
||||
return link && list && { fg: getComputedStyle(link).color, bg: getComputedStyle(list).backgroundColor }
|
||||
})
|
||||
check(`${theme}:「对比上一次」的字和底色分得开`, !!cmp && cmp.fg !== cmp.bg, JSON.stringify(cmp))
|
||||
check(`${theme}:页头的开关、立即运行、删除在屏幕里`, await inViewX(hist.page, 'header [data-schedule-run]')
|
||||
&& await inViewX(hist.page, 'header [data-schedule-toggle]') && await inViewX(hist.page, 'header [data-schedule-delete]'))
|
||||
await shot(hist.page, `history-390-${theme}`)
|
||||
|
||||
Reference in New Issue
Block a user