64 lines
2.8 KiB
GDScript
64 lines
2.8 KiB
GDScript
# tests/unit/presentation/settings_store_test.gd — 设置存储单元契约(回读/缺省/应用链)
|
||
# 断言面 = SettingsStore 公开方法:save_settings/load_settings 持久化回读、缺文件出厂默认、
|
||
# apply() 引擎档应用(UiKit.motion_scale 双态)。隔离卫生:一律经 _init path 注入指向临时 cfg,
|
||
# 禁碰真实 user://settings.cfg(ui_click_probe 设置面段同款纪律)。
|
||
# 运行:godot --headless --path game --script res://tests/unit/presentation/settings_store_test.gd
|
||
extends SceneTree
|
||
|
||
const Kit := preload("res://tests/unit/test_kit.gd")
|
||
const StoreScript := preload("res://presentation/settings_store.gd")
|
||
|
||
const ISO_PATH := "user://settings_store_unit_test.cfg" # 隔离注路径(临时件——测毕清理)
|
||
|
||
|
||
func _init() -> void:
|
||
_test_settings_roundtrip()
|
||
_test_settings_default()
|
||
_test_settings_apply_chain()
|
||
_cleanup()
|
||
quit(Kit.finish("settings_store_test"))
|
||
|
||
|
||
func _cleanup() -> void:
|
||
DirAccess.remove_absolute(ProjectSettings.globalize_path(ISO_PATH))
|
||
|
||
|
||
# ---- 持久化回读(写 true→存→新实例回读 true;节/键 motion/reduced)----
|
||
|
||
func _test_settings_roundtrip() -> void:
|
||
var w = StoreScript.new(ISO_PATH)
|
||
w.reduced_motion = true
|
||
Kit.check("前置:save_settings 落盘成功", w.save_settings())
|
||
var r = StoreScript.new(ISO_PATH)
|
||
r.load_settings()
|
||
Kit.check("持久化回读:新实例回读 reduced_motion=true(motion/reduced 节键)〔断言补齐批 V6〕", r.reduced_motion == true)
|
||
w.reduced_motion = false
|
||
Kit.check("回写往返:改 false 再存再读得 false〔断言补齐批 V6〕", w.save_settings() and (func():
|
||
var r2 = StoreScript.new(ISO_PATH)
|
||
r2.load_settings()
|
||
return r2.reduced_motion == false).call())
|
||
|
||
|
||
# ---- 缺省值(无文件缺省 false)----
|
||
|
||
func _test_settings_default() -> void:
|
||
var absent_path := "user://settings_store_unit_absent_%d.cfg" % (Time.get_ticks_msec())
|
||
DirAccess.remove_absolute(ProjectSettings.globalize_path(absent_path)) # 确保无文件
|
||
var d = StoreScript.new(absent_path)
|
||
d.load_settings()
|
||
Kit.check("无文件缺省:reduced_motion=false(缺文件=出厂默认合法态)〔断言补齐批 V7〕", d.reduced_motion == false)
|
||
|
||
|
||
# ---- 引擎档应用链(reduced→apply()→UiKit.motion_scale==0.5,false→1.0;测毕还原静态初值)----
|
||
|
||
func _test_settings_apply_chain() -> void:
|
||
var saved_scale: float = UiKit.motion_scale # 静态初值留底——测毕还原
|
||
var a = StoreScript.new(ISO_PATH)
|
||
a.reduced_motion = true
|
||
a.apply()
|
||
Kit.check("应用链:reduced=true → UiKit.motion_scale==0.5〔断言补齐批 V8〕", UiKit.motion_scale == 0.5)
|
||
a.reduced_motion = false
|
||
a.apply()
|
||
Kit.check("应用链:reduced=false → UiKit.motion_scale==1.0〔断言补齐批 V8〕", UiKit.motion_scale == 1.0)
|
||
UiKit.motion_scale = saved_scale # 还原(静态共享面——不渗入其他套件)
|