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
29 changes: 22 additions & 7 deletions ruoyi-fastapi-test/test_code_gen_harness.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
from typing import TYPE_CHECKING

import pytest
Expand All @@ -17,10 +18,11 @@


@pytest.mark.parametrize('framework', ['vue2', 'vue3', 'react'])
async def test_edit_table_ignores_departing_search_form(
browser_harness: BrowserHarness, monkeypatch: pytest.MonkeyPatch, framework: str
@pytest.mark.parametrize('delayed', ['none', 'response', 'render'])
async def test_edit_table_waits_for_details_and_ignores_departing_search_form(
browser_harness: BrowserHarness, monkeypatch: pytest.MonkeyPatch, framework: str, delayed: str
) -> None:
"""页面切换时查询表单仍可见,编辑必须只填写基本信息中的表描述。"""
"""详情响应或表单回填延迟时,编辑仍须等待初始值且不能误填离场查询表单。"""
monkeypatch.setattr(Config, 'frontend_framework', framework)
page = await browser_harness.new_page()
saved = {'tableName': 'example', 'tableComment': 'original'}
Expand All @@ -33,15 +35,14 @@ async def test_edit_table_ignores_departing_search_form(
</form>
<div class="el-table__body-wrapper"><table><tbody class="ant-table-tbody">
<tr class="el-table__row ant-table-row"><td>example</td><td id="saved-comment">original</td><td>
<button>预览</button><button onclick="history.pushState({}, '', '/tool/gen-edit/index/1');
document.querySelector('#editor').hidden = false">编辑</button>
<button>预览</button><button onclick="edit()">编辑</button>
</td></tr>
</tbody></table></div>
<section id="editor" hidden>
<button role="tab" id="basic-tab" onclick="showPanel('basic')">基本信息</button>
<button role="tab" id="generate-tab" onclick="showPanel('generate')">生成信息</button>
<div role="tabpanel" id="basic" aria-labelledby="basic-tab">
<div class="el-form-item ant-form-item">表描述<input id="edit-comment" value="original"></div>
<div class="el-form-item ant-form-item">表描述<input id="edit-comment"></div>
</div>
<div role="tabpanel" id="generate" aria-labelledby="generate-tab" hidden>
<div class="ant-form-item"><label class="ant-form-item-label">前端类型</label>
Expand All @@ -55,25 +56,39 @@ async def test_edit_table_ignores_departing_search_form(
</section>
</div>
<script>
let details;
function edit() {
history.pushState({}, '', '/tool/gen-edit/index/1');
document.querySelector('#editor').hidden = false;
details = fetch('/tool/gen/1').then(response => response.json()).then(async payload => {
await new Promise(resolve => setTimeout(resolve, RENDER_DELAY));
document.querySelector('#edit-comment').value = payload.data.info.tableComment;
});
}
function showPanel(id) {
document.querySelectorAll('[role=tabpanel]').forEach(panel => panel.hidden = panel.id !== id);
}
async function save() {
await details;
const comment = document.querySelector('#edit-comment').value;
await fetch('/tool/gen', {method: 'PUT', body: JSON.stringify({tableComment: comment})});
document.querySelector('#saved-comment').textContent = comment;
document.querySelector('#editor').hidden = true;
history.pushState({}, '', '/tool/gen');
}
</script>
"""
""".replace('RENDER_DELAY', '500' if delayed == 'render' else '0')

async def respond(route: Route) -> None:
if route.request.method == 'PUT':
saved.update(route.request.post_data_json)
await route.fulfill(json={'code': 200})
elif route.request.url.endswith('/tool/gen/list'):
await route.fulfill(json={'code': 200, 'rows': [saved]})
elif route.request.url.endswith('/tool/gen/1'):
if delayed == 'response':
await asyncio.sleep(0.5)
await route.fulfill(json={'code': 200, 'data': {'info': saved}})
else:
await route.fulfill(content_type='text/html; charset=utf-8', body=html)

Expand Down
17 changes: 12 additions & 5 deletions ruoyi-fastapi-test/tool/test_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ async def import_table(self) -> None:

async def edit_table(self) -> None:
"""修改实际生成配置,并重新读取确认服务端持久化结果。"""
await self.table_row().locator('td').last.get_by_role('button').nth(1).click()
details = await self.action(
self.table_row().locator('td').last.get_by_role('button').nth(1).click,
f'/tool/gen/{self.table_id}',
)
await self.page.wait_for_url(f'**/tool/gen-edit/index/{self.table_id}**')
self.table_comment = f'生成验收{uuid4().hex[:8]}'
await self.page.get_by_role('tab', name='基本信息', exact=True).click()
await (
comment = (
self.page.get_by_role('tabpanel', name='基本信息', exact=True)
.locator('.el-form-item:visible, .ant-form-item:visible')
.filter(has_text='表描述')
.locator('input')
.fill(self.table_comment)
)
# URL 和输入框可见时详情仍可能在加载,必须等初始值回填后再修改。
await expect(comment).to_have_value(details['data']['info']['tableComment'])
await comment.fill(self.table_comment)
if self.is_react:
await self.page.get_by_role('tab', name='生成信息', exact=True).click()
await self.choose(
Expand All @@ -96,8 +101,10 @@ async def edit_table(self) -> None:
lambda response: response.request.method == 'PUT' and urlparse(response.url).path.endswith('/tool/gen')
) as pending:
await self.page.get_by_role('button', name=button_name('提交')).click()
result = await (await pending.value).json()
assert result['code'] == HTTPStatus.OK, result
response = await pending.value
submitted = response.request.post_data_json
assert submitted['tableComment'] == self.table_comment, submitted
await self.payload(response)
await self.page.wait_for_url(re.compile(r'/tool/gen(?:\?.*)?$'))
listed = await self.search_table()
assert listed['rows'][0]['tableComment'] == self.table_comment
Expand Down
Loading