Make editor updates asynchronous with unified preview API
This commit is contained in:
@@ -13,7 +13,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--site", type=Path, default=ROOT / "examples/studio-site")
|
||||
parser.add_argument("--site", type=Path, default=ROOT / "examples/site-studio")
|
||||
args = parser.parse_args()
|
||||
with tempfile.TemporaryDirectory(prefix="cms-installed-001-") as tmp:
|
||||
work = Path(tmp)
|
||||
@@ -97,7 +97,7 @@ with TestClient(app) as client:
|
||||
assert response.status_code==200
|
||||
response=client.get('/admin/pages/index')
|
||||
assert response.status_code==200 and 'document-editor' in response.text
|
||||
for name in ('antirion-rework.css','shell.css','pages.css','pages.js','admin.css','admin.js','editor.js','builder.css','builder-adapter.css','builder.js','htmx.min.js','theme-studio.css','theme-studio.js'):
|
||||
for name in ('antirion-rework.css','shell.css','pages.css','pages.js','admin.css','admin.js','editor.js','preview-update.js','builder.css','builder-adapter.css','builder.js','htmx.min.js','theme-studio.css','theme-studio.js'):
|
||||
assert client.get('/admin/static/'+name).status_code==200,name
|
||||
assert 'pages-screen' in client.get('/admin/pages').text
|
||||
cookie=client.cookies.get('se_session')
|
||||
@@ -113,6 +113,21 @@ with TestClient(app) as client:
|
||||
assert result.status_code==200,result.text
|
||||
assert 'preview:ready' in result.text and 'data-preview-id' in result.text
|
||||
assert 'data-section-width' in result.text and '--container-max:' in result.text
|
||||
import json
|
||||
from site_engine.parsing.frontmatter import parse
|
||||
block_id=parse(source)[0]['regions']['main'][0]['id']
|
||||
original=source
|
||||
calls=app.state.api_calls
|
||||
result=client.post('/admin/editor/pages/index/update',data={'csrf':csrf,'payload':json.dumps({'source':source,'etag':etag_of(source.encode()),'revision':23,'operations':[{'type':'inspector','fields':{'operation':['block'],'block_id':[block_id],'p.title':['Installed background update']}}]})},headers={'Origin':'http://testserver','HX-Request':'true','Accept':'application/json'})
|
||||
assert result.status_code==200,result.text
|
||||
updated=result.json()
|
||||
assert updated['snapshot']['revision']==23 and 'Installed background update' in updated['snapshot']['source']
|
||||
assert 'Installed background update' in updated['preview']['html'] and updated['projection']
|
||||
assert app.state.api_calls==calls+1
|
||||
assert (Path(os.environ['SITE_ROOT'])/'pages/index.md').read_text()==original
|
||||
with TestClient(create_preview_app()) as preview:
|
||||
result=preview.get(updated['preview']['url'])
|
||||
assert result.status_code==200 and 'sitePreviewDocument' in result.text,result.text
|
||||
assert 'theme-bootstrap' in client.get('/admin/theme').text
|
||||
import json
|
||||
document={'schema':1,'preset':'dark','preset_version':1,'overrides':{}}
|
||||
@@ -125,7 +140,7 @@ with TestClient(app) as client:
|
||||
assert result.status_code==200 and 'sample-site' in result.text,result.text
|
||||
assert '--color-primary: #a48bfa' in result.text
|
||||
assert app.state.api_calls>0
|
||||
print('installed wheel: all theme presets, build, widths, static, templates, Theme Manager, API, bridge, separate preview OK; design/ absent')
|
||||
print('installed wheel: all theme presets, build, widths, static, templates, Theme Manager, API, background update, bridge, separate preview OK; design/ absent')
|
||||
"""
|
||||
subprocess.run([sys.executable, "-c", program], cwd=work, env=env, check=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user