ux refine
This commit is contained in:
+93
-6
@@ -21,19 +21,28 @@ def create_item(
|
||||
quantity="2",
|
||||
is_container=False,
|
||||
image=None,
|
||||
submit_action="save",
|
||||
):
|
||||
data = {"name": name, "note": note, "quantity": quantity}
|
||||
data = {"name": name, "note": note, "quantity": quantity, "submit_action": submit_action}
|
||||
if is_container:
|
||||
data["is_container"] = "on"
|
||||
files = {"image_file": image} if image is not None else None
|
||||
return client.post(f"/boxes/{box_id}/items", data=data, files=files, follow_redirects=False)
|
||||
|
||||
|
||||
def create_subitem(client, item_id, name="SubItem A", note="Small", quantity="3", image=None):
|
||||
def create_subitem(
|
||||
client,
|
||||
item_id,
|
||||
name="SubItem A",
|
||||
note="Small",
|
||||
quantity="3",
|
||||
image=None,
|
||||
submit_action="save",
|
||||
):
|
||||
files = {"image_file": image} if image is not None else None
|
||||
return client.post(
|
||||
f"/items/{item_id}/subitems",
|
||||
data={"name": name, "note": note, "quantity": quantity},
|
||||
data={"name": name, "note": note, "quantity": quantity, "submit_action": submit_action},
|
||||
files=files,
|
||||
follow_redirects=False,
|
||||
)
|
||||
@@ -320,14 +329,13 @@ def test_post_redirects_are_reasonable(client, db_session):
|
||||
db_session.commit()
|
||||
|
||||
item_response = create_item(client, box.id, name="Lamp")
|
||||
item_id = int(item_response.headers["location"].split("/")[-1])
|
||||
item = db_session.get(Item, item_id)
|
||||
item = db_session.query(Item).one()
|
||||
item.is_container = True
|
||||
db_session.commit()
|
||||
|
||||
subitem_response = create_subitem(client, item.id, name="Bulb")
|
||||
|
||||
assert item_response.headers["location"] == f"/items/{item.id}"
|
||||
assert item_response.headers["location"] == f"/boxes/{box.id}"
|
||||
assert subitem_response.headers["location"] == f"/items/{item.id}"
|
||||
|
||||
|
||||
@@ -730,6 +738,7 @@ def test_new_item_page_shows_clear_context_and_default_quantity(client, db_sessi
|
||||
assert 'name="quantity"' in response.text
|
||||
assert 'value="1"' in response.text
|
||||
assert "这个物品本身是一个小容器" in response.text
|
||||
assert "保存并添加下一个" in response.text
|
||||
|
||||
|
||||
def test_new_subitem_page_shows_clear_context_and_default_quantity(client, db_session):
|
||||
@@ -746,6 +755,7 @@ def test_new_subitem_page_shows_clear_context_and_default_quantity(client, db_se
|
||||
assert "文件袋" in response.text
|
||||
assert 'name="quantity"' in response.text
|
||||
assert 'value="1"' in response.text
|
||||
assert "保存并添加下一个" in response.text
|
||||
|
||||
|
||||
def test_box_detail_page_renders_clear_hierarchy_and_dense_list_structure(client, db_session):
|
||||
@@ -775,3 +785,80 @@ def test_item_detail_page_renders_clear_hierarchy(client, db_session):
|
||||
assert "容器型 Item" in response.text
|
||||
assert "书房箱" in response.text
|
||||
assert "SubItem" in response.text
|
||||
|
||||
|
||||
def test_creating_regular_item_redirects_back_to_parent_box(client, db_session):
|
||||
box = Box(name="连续录入箱")
|
||||
db_session.add(box)
|
||||
db_session.commit()
|
||||
|
||||
response = create_item(client, box.id, name="剪刀", is_container=False)
|
||||
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"] == f"/boxes/{box.id}"
|
||||
|
||||
|
||||
def test_creating_regular_subitem_redirects_back_to_parent_item(client, db_session):
|
||||
box = Box(name="配件箱")
|
||||
item = Item(name="线材袋", box=box, is_container=True)
|
||||
db_session.add_all([box, item])
|
||||
db_session.commit()
|
||||
|
||||
response = create_subitem(client, item.id, name="USB头")
|
||||
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"] == f"/items/{item.id}"
|
||||
|
||||
|
||||
def test_creating_box_redirects_to_new_box_detail(client):
|
||||
response = create_box(client, name="新箱子")
|
||||
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"].startswith("/boxes/")
|
||||
assert not response.headers["location"].endswith("/items/new")
|
||||
|
||||
|
||||
def test_creating_container_item_redirects_to_item_detail(client, db_session):
|
||||
box = Box(name="子容器箱")
|
||||
db_session.add(box)
|
||||
db_session.commit()
|
||||
|
||||
response = create_item(client, box.id, name="小收纳盒", is_container=True)
|
||||
|
||||
created_item = db_session.query(Item).one()
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"] == f"/items/{created_item.id}"
|
||||
|
||||
|
||||
def test_creating_item_with_save_and_add_next_returns_to_same_new_item_context(client, db_session):
|
||||
box = Box(name="快速录入箱")
|
||||
db_session.add(box)
|
||||
db_session.commit()
|
||||
|
||||
response = create_item(
|
||||
client,
|
||||
box.id,
|
||||
name="袜子",
|
||||
is_container=False,
|
||||
submit_action="save_and_add_next",
|
||||
)
|
||||
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"] == f"/boxes/{box.id}/items/new"
|
||||
|
||||
|
||||
def test_creating_subitem_with_save_and_add_next_returns_to_same_new_subitem_context(client, db_session):
|
||||
box = Box(name="电子箱")
|
||||
item = Item(name="配件袋", box=box, is_container=True)
|
||||
db_session.add_all([box, item])
|
||||
db_session.commit()
|
||||
|
||||
response = create_subitem(
|
||||
client,
|
||||
item.id,
|
||||
name="转接头",
|
||||
submit_action="save_and_add_next",
|
||||
)
|
||||
|
||||
assert response.status_code == 303
|
||||
assert response.headers["location"] == f"/items/{item.id}/subitems/new"
|
||||
|
||||
Reference in New Issue
Block a user