import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join } from 'node:path' import { PRICE_TRACK_DEFAULT_LISTING_STATUSES, PRICE_TRACK_LISTING_STATUSES, orderListingStatuses, withDefaultListingStatuses, } from '../src/pages/brand/components/listingFilters.ts' /** * 跟价「按商品状态(全量)」多状态(2026-10-16 立项;2026-10-17 改默认与兜底口径)。 * * 钉四件事: * 1. 状态目录本身——取值必须与客户端 amazon_base_v2.LISTING_STATUS_CATALOG 的键逐字一致, * 顺序就是客户端逐状态跑的顺序,默认只勾在售(=本功能上线前的行为); * 2. 空勾选的语义=只跑在售(不拦启动),且回写顺序不随点击次序漂; * 3. 载荷接线——listing_statuses 只在状态模式下发、以派发值为准、空清单不入队; * 4. mode 不再单吃本地勾选态(页面刷新后本地态回默认=全量,会把指定ASIN循环跑成全量改价)。 */ const PAGE = join( dirname(fileURLToPath(import.meta.url)), '../src/pages/brand/components/BrandPriceTrackTab.vue', ) const source = readFileSync(PAGE, 'utf8') test('状态目录:三项、顺序稳定、取值与客户端目录同名', () => { assert.deepEqual( PRICE_TRACK_LISTING_STATUSES.map((row) => row.value), ['Active', 'MissingOffer', 'PricingIssue'], '顺序即客户端逐状态筛选执行的顺序,改动要同步 app_client 的 LISTING_STATUS_CATALOG', ) assert.deepEqual( PRICE_TRACK_LISTING_STATUSES.map((row) => row.label), ['在售', '缺少的报价', '定价问题'], ) assert.equal(new Set(PRICE_TRACK_LISTING_STATUSES.map((row) => row.label)).size, 3, '文案不许重复') }) test('默认只勾在售=上线前行为,且必须是目录里的项', () => { assert.deepEqual([...PRICE_TRACK_DEFAULT_LISTING_STATUSES], ['Active']) const known = new Set(PRICE_TRACK_LISTING_STATUSES.map((row) => row.value)) for (const value of PRICE_TRACK_DEFAULT_LISTING_STATUSES) { assert.ok(known.has(value), `默认勾了目录外的状态 ${value}`) } }) test('一个状态都没勾=兜底回在售,不拦启动', () => { assert.deepEqual(withDefaultListingStatuses([]), ['Active'], '空勾选必须落到在售——客户端 resolve_listing_statuses 也是这个兜底,两边不能分叉') assert.deepEqual(withDefaultListingStatuses(['PricingIssue', 'Active']), ['Active', 'PricingIssue'], '有勾选时按目录顺序原样保留,只补空') assert.doesNotMatch(source, /请至少勾选一个商品状态/, '又恢复了"空勾选拦启动":不勾的语义就是只跑在售,拦它只会让用户以为跑不了') }) test('兜底只喂载荷,不许回头锁界面:在售必须能被取消', () => { // 2026-10-17 上线后被用户当场指出::checked 绑到兜底值上,「先取消在售、再勾自己要的状态」 // 这条最自然的路径就死了(取消最后一格立刻弹回在售)。兜底是提交期的事,不是界面的事。 assert.match(source, /function isListingStatusSelected\(value: string\) \{\n\s+return selectedListingStatuses\.value\.includes\(value\)/, '勾选框又绑回兜底值:在售取消不掉') assert.doesNotMatch(source, /input\.checked = effectiveListingStatuses/, '又往事件目标上写回兜底勾选') }) test('回写按目录顺序、目录外的值被摘掉', () => { assert.deepEqual(orderListingStatuses(['PricingIssue', 'Active', 'SearchSuppressed', '']), ['Active', 'PricingIssue'], '逐状态执行顺序变成了点击顺序或带进脏值:同一份勾选两次跑出的任务形状不同') assert.match(source, /selectedListingStatuses\.value = orderListingStatuses\(\[\.\.\.next\]\)/, '勾选回写不再走目录排序') }) test('载荷只在状态模式下带 listing_statuses', () => { assert.match( source, /\.\.\.\(mode === 'status' \? \{ listing_statuses: listingStatusesForPayload\(child\) \}\s*:\s*\{\}\)/, '指定ASIN模式不该发这个键(发了客户端会拿清单首项做预筛,改掉今天"按在售预筛"的形状)', ) }) test('listing_statuses 为空不许入队(兜底后本就不该出现空清单)', () => { assert.match(source, /\['country_codes', 'listing_statuses'\]/, '队列闸没把 listing_statuses 圈进非空数组——空清单会被客户端静默退回在售') }) test('mode 与状态清单都以派发回来的子任务为准,本地勾选只作兜底', () => { assert.match(source, /if \(child\) return child\.statusMode \? 'status' : 'asin'/, 'mode 又变成只读本地勾选态:刷新页面后指定ASIN循环会被拼成全量跟价(对整店真实改价)') assert.match(source, /fromDispatch\.length \? fromDispatch : effectiveListingStatuses\.value/, '状态清单不再优先取派发值:INFINITE 循环的后续轮会随界面改勾选而漂') assert.match(source, /buildQueuePayload\(taskVo, row, childTaskRequest\)/, '派发链路没把 childTaskRequest 传进载荷') }) test('循环建单把兜底后的清单一起提交(后端逐轮回读的就是它)', () => { assert.match(source, /listingStatuses: statusModeEnabled\.value \? effectiveListingStatuses\.value : \[\]/, '建单提交了未兜底的原始勾选:空勾选会落库成空清单,下一轮才被发现') }) test('续跑时勾选态跟着在跑的那份循环走', () => { assert.match(source, /if \(next && !hadLoop && next\.statusMode !== false\) \{/, '续跑预填没判"在跑的循环":asin-only 循环会把状态勾选也带出来') assert.match(source, /const running = orderListingStatuses\(\(next\.listingStatuses \|\| \[\]\)\.filter\(Boolean\)\)/, '预填不再按目录顺序回写') assert.match(source, /if \(running\.length\) selectedListingStatuses\.value = running/, '预填开始覆盖空清单:老循环没存过这个字段,会把默认在售冲成不勾') })