Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions calcit.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |)
Expand Down
13 changes: 13 additions & 0 deletions tests/components.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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],
Expand Down