Centralize legacy new document bridge
This commit is contained in:
@@ -107,6 +107,31 @@ public:
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
class FakeNewDocumentServices final : public pp::app::NewDocumentServices {
|
||||
public:
|
||||
void create_new_document(const pp::app::NewDocumentPlan& plan) override
|
||||
{
|
||||
creates += 1;
|
||||
last_name = plan.target.name;
|
||||
last_resolution = plan.resolution;
|
||||
call_order += "create;";
|
||||
}
|
||||
|
||||
void prompt_overwrite_new_document(const pp::app::NewDocumentPlan& plan) override
|
||||
{
|
||||
overwrite_prompts += 1;
|
||||
last_name = plan.target.name;
|
||||
last_resolution = plan.resolution;
|
||||
call_order += "overwrite;";
|
||||
}
|
||||
|
||||
int creates = 0;
|
||||
int overwrite_prompts = 0;
|
||||
int last_resolution = 0;
|
||||
std::string last_name;
|
||||
std::string call_order;
|
||||
};
|
||||
|
||||
[[nodiscard]] pp::app::DocumentOpenRoute project_route()
|
||||
{
|
||||
return {
|
||||
@@ -547,6 +572,32 @@ void new_document_plan_rejects_invalid_inputs(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, invalid_resolution.status().code == pp::foundation::StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void new_document_executor_dispatches_save_and_overwrite_paths(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeNewDocumentServices services;
|
||||
auto create = pp::app::plan_new_document(
|
||||
"D:/Paint",
|
||||
"demo",
|
||||
1,
|
||||
[](const std::string&) { return false; });
|
||||
auto overwrite = pp::app::plan_new_document(
|
||||
"D:/Paint",
|
||||
"demo",
|
||||
2,
|
||||
[](const std::string& path) { return path == "D:/Paint/demo.ppi"; });
|
||||
|
||||
PP_EXPECT(harness, create);
|
||||
PP_EXPECT(harness, overwrite);
|
||||
PP_EXPECT(harness, pp::app::execute_new_document_plan(create.value(), services).ok());
|
||||
PP_EXPECT(harness, pp::app::execute_new_document_plan(overwrite.value(), services).ok());
|
||||
|
||||
PP_EXPECT(harness, services.creates == 1);
|
||||
PP_EXPECT(harness, services.overwrite_prompts == 1);
|
||||
PP_EXPECT(harness, services.last_name == "demo");
|
||||
PP_EXPECT(harness, services.last_resolution == 1536);
|
||||
PP_EXPECT(harness, services.call_order == "create;overwrite;");
|
||||
}
|
||||
|
||||
void document_version_target_starts_at_first_version(pp::tests::Harness& harness)
|
||||
{
|
||||
const auto target = pp::app::find_next_document_version_target(
|
||||
@@ -642,6 +693,7 @@ int main()
|
||||
new_document_plan_builds_target_resolution_and_write_decision);
|
||||
harness.run("new document plan prompts for existing target", new_document_plan_prompts_for_existing_target);
|
||||
harness.run("new document plan rejects invalid inputs", new_document_plan_rejects_invalid_inputs);
|
||||
harness.run("new document executor dispatches save and overwrite paths", new_document_executor_dispatches_save_and_overwrite_paths);
|
||||
harness.run("document version target starts at first version", document_version_target_starts_at_first_version);
|
||||
harness.run("document version target increments existing suffix", document_version_target_increments_existing_suffix);
|
||||
harness.run("document version target skips existing paths", document_version_target_skips_existing_paths);
|
||||
|
||||
Reference in New Issue
Block a user