Add admin CRUD via schema-derived forms sharing validate/submit.
Infer fields from SQLite table_info; serve /admin/{table}/new|edit|delete.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
ee019fb1c2
commit
897db76aa7
8 files changed
+494
-56
No files matched your search
@@ -0,0 +1,84 @@
|
||||
---
|
||||
title: web admin form-from-schema smoke
|
||||
description: Schema-derived admin forms share validate/submit (offline).
|
||||
> ext/web/web.mq.md
|
||||
> web-fixtures/db/articles.mq.md as articles
|
||||
> lib/json.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
*`store` = > web.db url="sqlite:web-fixtures/data/admin-smoke.db" *
|
||||
*`schema` = > articles.schema *
|
||||
> `store`.init name=articles fields=`schema`
|
||||
*`url` = > json.get value=`store` key=url *
|
||||
|
||||
*`info` = > web_db_table_info url=`url` table=articles *
|
||||
*`cols` = > json.get value=`info` key=columns *
|
||||
*`n` = > len value=`cols` *
|
||||
1. `n` >= 2
|
||||
> print text=schema-ok
|
||||
2. *
|
||||
> print text=schema-fail
|
||||
|
||||
*`fnew` = > web_form_from_schema url=`url` table=articles action=insert *
|
||||
*`fields` = > json.get value=`fnew` key=fields *
|
||||
*`nf` = > len value=`fields` *
|
||||
1. `nf` >= 1
|
||||
> print text=new-form-ok
|
||||
2. *
|
||||
> print text=new-form-fail
|
||||
|
||||
`row` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Admin create | via schema form |
|
||||
|
||||
*`sub` = > web_form_submit form=`fnew` data=`row` url=`url` *
|
||||
*`sok` = > json.get value=`sub` key=ok *
|
||||
1. `sok`
|
||||
> print text=insert-ok
|
||||
2. *
|
||||
> print text=insert-fail
|
||||
|
||||
*`got` = > `store`.get table=articles id=1 *
|
||||
*`title` = > json.get value=`got` key=title *
|
||||
1. `title` == "Admin create"
|
||||
> print text=get-ok
|
||||
2. *
|
||||
> print text=get-fail
|
||||
|
||||
*`fedit` = > web_form_from_schema url=`url` table=articles action=update id=1 *
|
||||
`patch` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| Admin edited | body updated |
|
||||
|
||||
*`up` = > web_form_submit form=`fedit` data=`patch` url=`url` *
|
||||
*`uok` = > json.get value=`up` key=ok *
|
||||
1. `uok`
|
||||
> print text=update-ok
|
||||
2. *
|
||||
> print text=update-fail
|
||||
|
||||
*`got2` = > `store`.get table=articles id=1 *
|
||||
*`title2` = > json.get value=`got2` key=title *
|
||||
1. `title2` == "Admin edited"
|
||||
> print text=edit-ok
|
||||
2. *
|
||||
> print text=edit-fail
|
||||
|
||||
`empty` =
|
||||
|
||||
| title | body |
|
||||
|-------|------|
|
||||
| | |
|
||||
|
||||
*`bad` = > web_form_submit form=`fnew` data=`empty` url=`url` *
|
||||
*`bok` = > json.get value=`bad` key=ok *
|
||||
1. `bok`
|
||||
> print text=required-should-fail
|
||||
2. *
|
||||
> print text=required-ok
|
||||
@@ -1258,6 +1258,26 @@ render-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_web_admin_smoke() {
|
||||
let status = Command::new("cargo")
|
||||
.args(["build", "-p", "marqdo_plugin_web"])
|
||||
.current_dir(env!("CARGO_MANIFEST_DIR"))
|
||||
.status()
|
||||
.expect("build web plugin");
|
||||
assert!(status.success(), "failed to build marqdo_plugin_web");
|
||||
assert_out(
|
||||
"tests/ext/web-admin-smoke.mq.md",
|
||||
"schema-ok
|
||||
new-form-ok
|
||||
insert-ok
|
||||
get-ok
|
||||
update-ok
|
||||
edit-ok
|
||||
required-ok",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ext_agent_framework_smoke() {
|
||||
let status = Command::new("cargo")
|
||||
|
||||
Reference in new issue
Block a user