135 lines
5.6 KiB
Python
135 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
||
"""多选月份那一格的「挑选方式」存不存得住、认不认得。
|
||
|
||
PYTHONPATH=. python3 scripts/check_months_style.py
|
||
|
||
来由:那一格最初只有一种长相——12 个月的盘子摊在表单里,一整行没了。现在让它挑姿势
|
||
(下拉多选 / 弹出框多选 / 平铺点选),用的是设计器里已有的那份 ``pickerStyle``,
|
||
于是最容易坏的不是控件,是**保存那一路把它当残骸收掉**:
|
||
|
||
* ``api/design.py`` 的 ``clean_option_source`` 见「这一类没有候选来源」就连 ``pickerStyle``
|
||
一起抹(多选月份不在 ``source_kinds_of`` 的清单里)——配的人挑了弹出框,存一次默默掉回下拉;
|
||
* 反过来,换成文本框之后那一格还留着 ``pickerStyle``,看着是文本框,读出来却带着上一类的
|
||
展现配置,下一个人无从知道它为什么在那儿。
|
||
|
||
钉这十七句:三档都认、默认是下拉(平铺要吃掉一整行,不能当默认)、认不出的写法收掉并在
|
||
保存那一刻说一句、明细列同理、换成别的类型跟着收、值与念法照旧。全程不碰库。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import sys
|
||
|
||
from app.api.design import clean_option_source
|
||
from app.service import formruntime
|
||
|
||
FAILS: list[str] = []
|
||
|
||
|
||
def check(label: str, got: object, want: object) -> None:
|
||
if got != want:
|
||
FAILS.append(f"{label}:想要 {want!r},拿到 {got!r}")
|
||
|
||
|
||
def fields_of(*items: dict) -> dict:
|
||
return {"fields": list(items)}
|
||
|
||
|
||
def cleaned(field: dict) -> dict:
|
||
return clean_option_source(fields_of(field))["fields"][0]
|
||
|
||
|
||
# ------------------------------------------------------------------ 认档与默认
|
||
check("默认那一档", formruntime.months_style_of({}), "dropdown")
|
||
check("弹出框认得", formruntime.months_style_of({"pickerStyle": "dialog"}), "dialog")
|
||
check("平铺认得", formruntime.months_style_of({"pickerStyle": "inline"}), "inline")
|
||
check("下拉认得", formruntime.months_style_of({"pickerStyle": "dropdown"}), "dropdown")
|
||
# 「自动」是那两格下拉组件的说法:多选月份只有一档默认,摆「自动」等于让人猜
|
||
check("auto 回落默认", formruntime.months_style_of({"pickerStyle": "auto"}), "dropdown")
|
||
check("瞎写的回落默认", formruntime.months_style_of({"pickerStyle": "popup"}), "dropdown")
|
||
check("脏空格照样认", formruntime.months_style_of({"pickerStyle": " dialog "}), "dialog")
|
||
|
||
# ------------------------------------------------------------------ 保存那一路
|
||
check(
|
||
"配了弹出框存得住",
|
||
cleaned({"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "dialog"}).get("pickerStyle"),
|
||
"dialog",
|
||
)
|
||
check(
|
||
"配了平铺存得住",
|
||
cleaned({"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "inline"}).get("pickerStyle"),
|
||
"inline",
|
||
)
|
||
check(
|
||
"认不出的写法收掉",
|
||
"pickerStyle" in cleaned({"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "popup"}),
|
||
False,
|
||
)
|
||
check(
|
||
"多选月份不许挂候选来源",
|
||
"optionSource" in cleaned({"key": "m", "label": "停用月份", "type": "months", "optionSource": "dict"}),
|
||
False,
|
||
)
|
||
check(
|
||
"换成文本框之后那一档跟着收",
|
||
"pickerStyle" in cleaned({"key": "m", "label": "停用月份", "type": "text", "pickerStyle": "dialog"}),
|
||
False,
|
||
)
|
||
check(
|
||
"选择类的挑选方式照旧存得住(这次改动没把它们带坏)",
|
||
cleaned({"key": "s", "label": "类别", "type": "select", "pickerStyle": "inline", "options": [{"value": "a"}]}).get(
|
||
"pickerStyle"
|
||
),
|
||
"inline",
|
||
)
|
||
|
||
# ------------------------------------------------------------------ 保存那一刻的说法
|
||
bogus = {"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "popup"}
|
||
problems = formruntime.validate_schema([bogus])
|
||
check("主表那一格配歪了会说", any("挑选方式不认识" in line for line in problems), True)
|
||
check(
|
||
"说的时候带上是哪一格",
|
||
any("「停用月份」" in line for line in problems if "挑选方式不认识" in line),
|
||
True,
|
||
)
|
||
check(
|
||
"配对了不多说一句",
|
||
formruntime.validate_schema([{"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "dialog"}]),
|
||
[],
|
||
)
|
||
column_bogus = {
|
||
"key": "rows",
|
||
"label": "明细",
|
||
"type": "table",
|
||
"columns": [{"key": "m", "label": "停用月份", "type": "months", "pickerStyle": "popup"}],
|
||
}
|
||
column_problems = formruntime.validate_schema([column_bogus])
|
||
check("明细那一列同样会说", any("的列「停用月份」的挑选方式不认识" in line for line in column_problems), True)
|
||
|
||
# ------------------------------------------------------------------ 值与念法照旧
|
||
check("并段那句没被带坏", formruntime.months_text(["2026-11", "2026-10"]), "2026年10-11月")
|
||
check(
|
||
"跨年两头写全",
|
||
formruntime.months_text(["2026-12", "2027-01", "2027-02", "2027-05"]),
|
||
"2026年12月-2027年2月、2027年5月",
|
||
)
|
||
check("脏值丢掉、去重、按时间排", formruntime.month_list(["2026-11", "2026-11", "2026-13", "x"]), ["2026-11"])
|
||
value_problems = formruntime.value_problems(
|
||
[{"key": "m", "label": "停用月份", "type": "months", "required": True}], {"m": "editable"}, {"m": ["2026-10", "十月"]}
|
||
)
|
||
check("提交时那一项写法不对会挡", any("2026-01 这样写法的月份" in line for line in value_problems), True)
|
||
|
||
|
||
def main() -> int:
|
||
for line in FAILS:
|
||
print(f"[FAIL] {line}")
|
||
if FAILS:
|
||
print(f"共 {len(FAILS)} 句不对")
|
||
return 1
|
||
print("通过:多选月份的挑选方式认档、存得住、配歪了当场说(17 句)")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|