Verify order selection through real window controls and modal replacement
This commit is contained in:
1 parent
a1c65119a2
commit
13b4665ed2
4 files changed
+89
-14
No files matched your search
@@ -44,7 +44,8 @@ LRESULT CALLBACK test_window_proc(HWND window, UINT message, WPARAM wparam, LPAR
|
||||
}
|
||||
if (message == WM_TIMER && wparam == drive_timer) {
|
||||
if (++timer_attempts > 100) {
|
||||
driver_error = "real popup did not accept the scripted input";
|
||||
driver_error = "real popup did not accept input: menus=" + std::to_string(observed_menus.size()) +
|
||||
" remaining=" + std::to_string(steps.size()) + " active=" + std::to_string(active_menu != nullptr);
|
||||
KillTimer(window, drive_timer);
|
||||
EndMenu();
|
||||
return 0;
|
||||
@@ -62,7 +63,13 @@ LRESULT CALLBACK test_window_proc(HWND window, UINT message, WPARAM wparam, LPAR
|
||||
EndMenu();
|
||||
return 0;
|
||||
}
|
||||
if (step.before_select) step.before_select();
|
||||
try {
|
||||
if (step.before_select) step.before_select();
|
||||
} catch (const std::exception& error) {
|
||||
driver_error = error.what();
|
||||
EndMenu();
|
||||
return 0;
|
||||
}
|
||||
std::vector<INPUT> input;
|
||||
key(input, VK_HOME);
|
||||
for (int index = 0; index < target; ++index) {
|
||||
@@ -94,13 +101,14 @@ struct Window {
|
||||
auto rules = default_rules_manifest();
|
||||
require(rules.has_value());
|
||||
session = std::make_unique<settlement::viewer::ViewerSession>(
|
||||
WorldCheckpoint{std::move(initial), *uuid, 1, *rules}, 1);
|
||||
WorldCheckpoint{std::move(initial), *uuid, 1, *rules}, 2);
|
||||
world = session->world();
|
||||
showing_title = true;
|
||||
has_session = true;
|
||||
lan = std::make_unique<settlement::viewer::LanSession>();
|
||||
displayed_lan_state = LanState::Offline;
|
||||
placement_mode = PlacementMode::None;
|
||||
camera = {};
|
||||
placement_message.clear();
|
||||
steps.clear();
|
||||
observed_menus.clear();
|
||||
@@ -163,17 +171,33 @@ struct Window {
|
||||
}
|
||||
require(placement_mode == PlacementMode::ManageOrders, "Работы menu did not activate order management");
|
||||
}
|
||||
void click_cell(GridPosition cell) {
|
||||
RECT client{};
|
||||
GetClientRect(handle, &client);
|
||||
const auto scale = camera.scale();
|
||||
const auto offset = camera.offset();
|
||||
POINT point{static_cast<LONG>((client.right / 2.0 + (cell.x - cell.y) * tile_width / 2.0) * scale + offset.x),
|
||||
static_cast<LONG>((map_origin_y + (cell.x + cell.y) * tile_height / 2.0) * scale + offset.y)};
|
||||
require(map_cell(client, point) == cell, "normal map hit test did not select the target cell");
|
||||
auto screen = point;
|
||||
ClientToScreen(handle, &screen);
|
||||
SetCursorPos(screen.x, screen.y);
|
||||
const auto coordinates = MAKELPARAM(point.x, point.y);
|
||||
SendMessageW(handle, WM_LBUTTONDOWN, MK_LBUTTON, coordinates);
|
||||
SendMessageW(handle, WM_LBUTTONUP, 0, coordinates);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<World> orders(unsigned count = 2) {
|
||||
auto result = std::make_unique<World>(43, 32, 32, 1, ExecutionMode::SerialReference);
|
||||
for (unsigned index = 0; index < count; ++index) result->queue_production({8, 8}, RecipeId::BuildCabin);
|
||||
for (unsigned index = 0; index < count; ++index) result->queue_production({8, 8}, RecipeId::SawPlank);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct [[= Void::Testing::name("ProductionControlsTests")]] ProductionControlsTests
|
||||
: Void::Testing::Suite<ProductionControlsTests> {
|
||||
[[= Void::Testing::tag("production-controls")]] Test real_work_menu_selects_exact_id_and_waits_for_receipt();
|
||||
[[= Void::Testing::tag("production-controls")]] Test real_resume_choice_keeps_installed_loom_and_waits_for_receipt();
|
||||
[[= Void::Testing::tag("production-controls")]] Test every_order_remains_accessible_across_popup_pages();
|
||||
[[= Void::Testing::tag("production-controls")]] Test replacement_during_popup_cannot_cancel_in_new_world();
|
||||
[[= Void::Testing::tag("production-controls")]] Test legacy_guest_has_no_action_or_modern_submission();
|
||||
@@ -185,11 +209,11 @@ Test ProductionControlsTests::real_work_menu_selects_exact_id_and_waits_for_rece
|
||||
const auto first = world->production_orders().front().id;
|
||||
const auto second = world->production_orders().back().id;
|
||||
fixture.activate_tool();
|
||||
fixture.menu({{2, {}}}, [&] { edit_at_cell(fixture.handle, {8, 8}); });
|
||||
fixture.menu({{2, {}}}, [&] { fixture.click_cell({8, 8}); });
|
||||
require(world->find_production(second) && world->find_production(first) &&
|
||||
placement_message.find(L"ожидает подтверждения") != std::wstring::npos,
|
||||
"UI forged success before a committed receipt");
|
||||
require(observed_menus.back().at(1).find(L"Отменить: Построить домик №" + std::to_wstring(second)) != std::wstring::npos &&
|
||||
require(observed_menus.back().at(1).find(L"Отменить: Распилить доску №" + std::to_wstring(second)) != std::wstring::npos &&
|
||||
observed_menus.back().at(1).find(L"[9, 9]") != std::wstring::npos,
|
||||
"actual popup lost the order name, durable id or user-facing position");
|
||||
fixture.pump_until([&] { return !world->find_production(second); });
|
||||
@@ -201,12 +225,28 @@ Test ProductionControlsTests::every_order_remains_accessible_across_popup_pages(
|
||||
Window fixture(orders(35));
|
||||
const auto last = world->production_orders().back().id;
|
||||
fixture.activate_tool();
|
||||
fixture.menu({{101, {}}, {101, {}}, {3, {}}}, [&] { edit_at_cell(fixture.handle, {8, 8}); });
|
||||
fixture.menu({{101, {}}, {101, {}}, {3, {}}}, [&] { fixture.click_cell({8, 8}); });
|
||||
fixture.pump_until([&] { return !world->find_production(last); });
|
||||
require(world->production_orders().size() == 34 && world->production_orders().front().id == 1);
|
||||
for (const auto& page : observed_menus) require(page.size() <= 19, "popup page exceeded its bounded display size");
|
||||
}
|
||||
|
||||
Test ProductionControlsTests::real_resume_choice_keeps_installed_loom_and_waits_for_receipt() {
|
||||
auto initial = orders(0);
|
||||
initial->queue_production({8, 8}, RecipeId::WeaveCloth);
|
||||
const auto id = initial->production_orders().front().id;
|
||||
require(initial->cancel_production(id) == CommandStatus::Accepted && initial->find_production(id)->suspended);
|
||||
Window fixture(std::move(initial));
|
||||
fixture.activate_tool();
|
||||
fixture.menu({{1, {}}}, [&] { fixture.click_cell({8, 8}); });
|
||||
require(world->find_production(id)->suspended &&
|
||||
placement_message.find(L"ожидает подтверждения") != std::wstring::npos);
|
||||
require(observed_menus.back().at(0).find(L"Возобновить: Ткать ткань №" + std::to_wstring(id)) != std::wstring::npos);
|
||||
fixture.pump_until([&] { return !world->find_production(id)->suspended; });
|
||||
require(world->find_production(id)->recipe == RecipeId::WeaveCloth &&
|
||||
placement_message.find(L"возобновлена") != std::wstring::npos && world->next_command_sequence(1) == 1);
|
||||
}
|
||||
|
||||
Test ProductionControlsTests::replacement_during_popup_cannot_cancel_in_new_world() {
|
||||
for (const bool complete_replacement : {false, true}) {
|
||||
Window fixture(orders());
|
||||
@@ -223,7 +263,7 @@ Test ProductionControlsTests::replacement_during_popup_cannot_cancel_in_new_worl
|
||||
}
|
||||
world = session->world();
|
||||
}
|
||||
}}}, [&] { edit_at_cell(fixture.handle, {8, 8}); });
|
||||
}}}, [&] { fixture.click_cell({8, 8}); });
|
||||
fixture.pump_until([&] { return !session->changing_world(); });
|
||||
const auto current = session->runtime().latest();
|
||||
require(current->identity != opening->identity && current->next_requests[0] == 1 &&
|
||||
@@ -235,8 +275,22 @@ Test ProductionControlsTests::replacement_during_popup_cannot_cancel_in_new_worl
|
||||
|
||||
Test ProductionControlsTests::legacy_guest_has_no_action_or_modern_submission() {
|
||||
Window fixture(orders());
|
||||
const auto host_id = Void::Uuid::try_v4();
|
||||
const auto rules = default_rules_manifest();
|
||||
require(host_id.has_value() && rules.has_value());
|
||||
SimulationRuntime host_runtime(WorldCheckpoint{make_first_colony(2), *host_id, 1, *rules}, {.ticking = false});
|
||||
settlement::viewer::LanSession host_peer;
|
||||
host_peer.host(0, true);
|
||||
session->enter_guest();
|
||||
lan->join("127.0.0.1", "000000", 1);
|
||||
lan->join("127.0.0.1", host_peer.join_code(), host_peer.port());
|
||||
const auto deadline = std::chrono::steady_clock::now() + 5s;
|
||||
while (lan->state() != LanState::GuestConnected) {
|
||||
host_peer.poll_host(host_runtime);
|
||||
if (auto incoming = lan->poll_guest()) session->receive_guest(std::move(incoming));
|
||||
require(std::chrono::steady_clock::now() < deadline, "real legacy guest did not connect");
|
||||
std::this_thread::yield();
|
||||
}
|
||||
world = session->world();
|
||||
require(lan->is_guest() && session->guest());
|
||||
const auto before = session->runtime().latest();
|
||||
const auto menu = create_work_menu();
|
||||
@@ -253,7 +307,8 @@ Test ProductionControlsTests::legacy_guest_has_no_action_or_modern_submission()
|
||||
}
|
||||
|
||||
Test ProductionControlsTests::returning_resident_explains_wait_for_storage() {
|
||||
auto initial = orders(1);
|
||||
auto initial = orders(0);
|
||||
initial->queue_production({8, 8}, RecipeId::BuildCabin);
|
||||
const auto storage = initial->add_storage({3, 3}, 5);
|
||||
initial->stock_storage(storage, ItemType::Plank, 3);
|
||||
initial->stock_storage(storage, ItemType::StoneBlock, 2);
|
||||
|
||||
Reference in new issue
Block a user