|
| 1 | +"""Backend coverage for the `pages.mindmap_layout` column. |
| 2 | +
|
| 3 | +The frontend treats NULL as `'lr'`, so existing rows must keep returning |
| 4 | +`null` and the field must round-trip through both create and update without |
| 5 | +bumping `pages.version`. |
| 6 | +""" |
| 7 | +import pytest |
| 8 | + |
| 9 | + |
| 10 | +@pytest.mark.asyncio |
| 11 | +async def test_create_mindmap_page_omits_layout_returns_null(auth_client): |
| 12 | + response = await auth_client.post( |
| 13 | + "/api/pages", |
| 14 | + json={ |
| 15 | + "title": "ML Default", |
| 16 | + "slug": "ml-default", |
| 17 | + "page_type": "mindmap", |
| 18 | + "content_md": "# Root", |
| 19 | + }, |
| 20 | + ) |
| 21 | + assert response.status_code == 201 |
| 22 | + data = response.json() |
| 23 | + assert data["page_type"] == "mindmap" |
| 24 | + assert "mindmap_layout" in data |
| 25 | + assert data["mindmap_layout"] is None |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.asyncio |
| 29 | +async def test_create_with_explicit_layout_persists(auth_client): |
| 30 | + response = await auth_client.post( |
| 31 | + "/api/pages", |
| 32 | + json={ |
| 33 | + "title": "ML Radial", |
| 34 | + "slug": "ml-radial", |
| 35 | + "page_type": "mindmap", |
| 36 | + "mindmap_layout": "radial", |
| 37 | + "content_md": "# Root", |
| 38 | + }, |
| 39 | + ) |
| 40 | + assert response.status_code == 201 |
| 41 | + assert response.json()["mindmap_layout"] == "radial" |
| 42 | + |
| 43 | + fetched = await auth_client.get("/api/pages/ml-radial") |
| 44 | + assert fetched.status_code == 200 |
| 45 | + assert fetched.json()["mindmap_layout"] == "radial" |
| 46 | + |
| 47 | + |
| 48 | +@pytest.mark.asyncio |
| 49 | +async def test_update_layout_does_not_bump_version(auth_client): |
| 50 | + create = await auth_client.post( |
| 51 | + "/api/pages", |
| 52 | + json={ |
| 53 | + "title": "ML Vbump", |
| 54 | + "slug": "ml-vbump", |
| 55 | + "page_type": "mindmap", |
| 56 | + "content_md": "# Root", |
| 57 | + }, |
| 58 | + ) |
| 59 | + assert create.status_code == 201 |
| 60 | + starting_version = create.json()["version"] |
| 61 | + |
| 62 | + # Layout-only edit: must persist and must NOT bump the version counter |
| 63 | + # (matches is_public / page_type behavior — see pages.py optimistic-lock |
| 64 | + # logic: only content_md / title bump version). |
| 65 | + res = await auth_client.put( |
| 66 | + "/api/pages/ml-vbump", |
| 67 | + json={"mindmap_layout": "rl"}, |
| 68 | + ) |
| 69 | + assert res.status_code == 200 |
| 70 | + body = res.json() |
| 71 | + assert body["mindmap_layout"] == "rl" |
| 72 | + assert body["version"] == starting_version |
| 73 | + |
| 74 | + |
| 75 | +@pytest.mark.asyncio |
| 76 | +async def test_update_layout_to_invalid_value_returns_422(auth_client): |
| 77 | + await auth_client.post( |
| 78 | + "/api/pages", |
| 79 | + json={ |
| 80 | + "title": "ML Bad", |
| 81 | + "slug": "ml-bad", |
| 82 | + "page_type": "mindmap", |
| 83 | + "content_md": "# Root", |
| 84 | + }, |
| 85 | + ) |
| 86 | + res = await auth_client.put( |
| 87 | + "/api/pages/ml-bad", |
| 88 | + json={"mindmap_layout": "diagonal"}, |
| 89 | + ) |
| 90 | + assert res.status_code == 422 |
| 91 | + |
| 92 | + |
| 93 | +@pytest.mark.asyncio |
| 94 | +async def test_update_layout_back_to_null(auth_client): |
| 95 | + await auth_client.post( |
| 96 | + "/api/pages", |
| 97 | + json={ |
| 98 | + "title": "ML Reset", |
| 99 | + "slug": "ml-reset", |
| 100 | + "page_type": "mindmap", |
| 101 | + "mindmap_layout": "radial", |
| 102 | + "content_md": "# Root", |
| 103 | + }, |
| 104 | + ) |
| 105 | + res = await auth_client.put( |
| 106 | + "/api/pages/ml-reset", |
| 107 | + json={"mindmap_layout": None}, |
| 108 | + ) |
| 109 | + assert res.status_code == 200 |
| 110 | + assert res.json()["mindmap_layout"] is None |
| 111 | + |
| 112 | + fetched = await auth_client.get("/api/pages/ml-reset") |
| 113 | + assert fetched.json()["mindmap_layout"] is None |
| 114 | + |
| 115 | + |
| 116 | +@pytest.mark.asyncio |
| 117 | +async def test_layout_allowed_on_document_page(auth_client): |
| 118 | + """Layout column has no meaning for `page_type='document'`, but we accept |
| 119 | + it anyway so toggling page_type doesn't lose the setting.""" |
| 120 | + res = await auth_client.post( |
| 121 | + "/api/pages", |
| 122 | + json={ |
| 123 | + "title": "Doc With Layout", |
| 124 | + "slug": "doc-with-layout", |
| 125 | + "page_type": "document", |
| 126 | + "mindmap_layout": "radial", |
| 127 | + "content_md": "Body", |
| 128 | + }, |
| 129 | + ) |
| 130 | + assert res.status_code == 201 |
| 131 | + assert res.json()["mindmap_layout"] == "radial" |
| 132 | + |
| 133 | + |
| 134 | +@pytest.mark.asyncio |
| 135 | +async def test_get_response_always_includes_layout_key(auth_client): |
| 136 | + await auth_client.post( |
| 137 | + "/api/pages", |
| 138 | + json={"title": "Plain Doc", "slug": "plain-doc", "content_md": "x"}, |
| 139 | + ) |
| 140 | + res = await auth_client.get("/api/pages/plain-doc") |
| 141 | + assert res.status_code == 200 |
| 142 | + assert "mindmap_layout" in res.json() |
0 commit comments