diff --git a/calcit.cirru b/calcit.cirru index 6858076..7a8b6f4 100644 --- a/calcit.cirru +++ b/calcit.cirru @@ -948,7 +948,9 @@ .unwrap $ get states :cursor List app.schema/StateKey state $ decode-map-as - or (app.schema/field-or states :data nil) initial-state + match (get states :data) + (:some value) (if value value initial-state) + (:none) initial-state Map Tag String div {} $ :style $ merge ui/flex ui/center @@ -993,7 +995,7 @@ .unwrap $ get state :password , false :examples $ [] - :schema $ quote $ Fn (Map Tag Dynamic) (-> respo.schema/Component) + :schema $ quote $ Fn (Map Tag StateValue) (-> respo.schema/Component) (:generics StateValue) 'initial-state $ %{} 'CodeEntry (:doc |) :code $ quote $ def initial-state {} (:username |) (:password |) diff --git a/tests/components.test.mjs b/tests/components.test.mjs index 88d4482..4f439bc 100644 --- a/tests/components.test.mjs +++ b/tests/components.test.mjs @@ -7,6 +7,7 @@ import { comp_command_button, comp_command_editor, comp_command_row } from '../o import { comp_process, find_urls } from '../out-page/app.comp.process.mjs'; import { comp_process_detail, hide_thread_info } from '../out-page/app.comp.process-detail.mjs'; import { comp_profile } from '../out-page/app.comp.profile.mjs'; +import { comp_login } from '../out-page/app.comp.login.mjs'; import { comp_home, lower_case } from '../out-page/app.comp.home.mjs'; import { comp_history, format_date_time } from '../out-page/app.comp.history.mjs'; import dayjs from 'dayjs'; @@ -85,6 +86,18 @@ function elements(component) { const values = nodes => nodes.map(node => c.listToArray(read(node, 'attrs')).map(c.listToArray).find(([key]) => key.value === 'value')[1]); const attr = (node, name) => c.listToArray(read(node, 'attrs')).map(c.listToArray).find(([key]) => key.value === name)?.[1]; +test('login preserves defaults and existing input values', () => { + for (const [source, expected] of [ + ['{} (:cursor ([]))', ['', '']], + ['{} (:cursor ([])) (:data nil)', ['', '']], + ['{} (:cursor ([])) (:data false)', ['', '']], + ['{} (:cursor ([])) (:data ({} (:username |Ada) (:password |synthetic)))', ['Ada', 'synthetic']], + ]) { + const inputs = elements(comp_login(parse(source))).filter(node => ['Username', 'Password'].includes(attr(node, 'placeholder'))); + assert.deepEqual(inputs.map(node => attr(node, 'value')), expected); + } +}); + test('workflow button treats absent commands as empty and rejects invalid commands', () => { for (const [workflow, valid] of [ [parse('{} (:name |Demo) (:base-dir |/synthetic)'), true],