aboutsummaryrefslogtreecommitdiff
path: root/libs/map/map_tests/editor_notes_tests.cpp
blob: c33d97cf1957244c15cd05cd3c4e4c129a85f7dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "testing/testing.hpp"

#include "generator/generator_tests_support/test_feature.hpp"
#include "generator/generator_tests_support/test_mwm_builder.hpp"

#include "map/framework.hpp"
#include "map/place_page_info.hpp"

#include "drape_frontend/drape_frontend_tests/visual_params_fixture.hpp"

#include "editor/editor_notes.hpp"
#include "editor/osm_editor.hpp"

#include "indexer/data_header.hpp"
#include "indexer/editable_map_object.hpp"
#include "indexer/mwm_set.hpp"

#include "platform/country_defines.hpp"
#include "platform/local_country_file.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include "platform/platform_tests_support/scoped_file.hpp"

#include "geometry/latlon.hpp"
#include "geometry/mercator.hpp"
#include "geometry/point2d.hpp"

namespace editor_notes_tests
{
using namespace generator::tests_support;
using df::test_support::VisualParamsFixture;
using platform::LocalCountryFile;
using platform::tests_support::ScopedFile;

// https://github.com/organicmaps/organicmaps/issues/11170
// A note created via "Edit place" on a line/area feature must be attached to the user's map
// selection (tap) point, not to the feature's geometric center, which for a road or forest can be
// far from where the problem was reported.
UNIT_CLASS_TEST(VisualParamsFixture, EditorNotes_UseSelectionPointNotFeatureCenter)
{
  Framework frm({} /* params */, false /* loadMaps */);

  // A straight horizontal road; its geometric center is the midpoint (0.5, 0).
  LocalCountryFile country(GetPlatform().WritableDir(), platform::CountryFile("EditorNotesLand"), 0 /* version */);
  platform::CountryIndexes::DeleteFromDisk(country);
  country.DeleteFromDisk(MapFileType::Map);
  {
    TestMwmBuilder builder(country, feature::DataHeader::MapType::Country);
    builder.Add(TestStreet({{0.0, 0.0}, {1.0, 0.0}}, "Test Road", "en"));
  }
  TEST_EQUAL(frm.RegisterMap(country).second, MwmSet::RegResult::Success, ());

  // Tap on the road far from its center, as if reporting a problem at that exact spot.
  m2::PointD const tapPoint(0.9, 0.0);
  place_page::BuildInfo bi;
  bi.m_source = place_page::BuildInfo::Source::User;
  bi.m_mercator = tapPoint;
  frm.BuildAndSetPlacePageInfo(bi);

  auto const & info = frm.GetCurrentPlacePageInfo();
  TEST(info.GetID().IsValid(), ("The tap must select the road."));
  // The selection keeps the tap point verbatim, not the road center.
  TEST_ALMOST_EQUAL_ABS(info.GetMercator(), tapPoint, 1e-7, ());

  ScopedFile const notesFile("test_editor_notes.xml", ScopedFile::Mode::DoNotCreate);
  osm::Editor::Instance().SetNotesForTesting(notesFile.GetFullPath());

  osm::EditableMapObject emo;
  TEST(frm.GetEditableMapObject(info.GetID(), emo), ());
  frm.CreateNote(emo, osm::Editor::NoteProblemType::General, "Obstacle on the road");

  editor::Notes const notes(notesFile.GetFullPath());
  TEST_EQUAL(notes.GetNotesForTests().size(), 1, ());
  // Looser tolerance: the note round-trips through XML.
  TEST_ALMOST_EQUAL_ABS(notes.GetNotesForTests().front().m_point, mercator::ToLatLon(tapPoint), 1e-4, ());

  platform::CountryIndexes::DeleteFromDisk(country);
  country.DeleteFromDisk(MapFileType::Map);
}

UNIT_CLASS_TEST(VisualParamsFixture, EditorNotes_UseSelectionPointForExplicitFeatureTap)
{
  Framework frm({} /* params */, false /* loadMaps */);

  LocalCountryFile country(GetPlatform().WritableDir(), platform::CountryFile("EditorNotesExplicitLand"),
                           0 /* version */);
  platform::CountryIndexes::DeleteFromDisk(country);
  country.DeleteFromDisk(MapFileType::Map);
  {
    TestMwmBuilder builder(country, feature::DataHeader::MapType::Country);
    builder.Add(TestStreet({{0.0, 0.0}, {1.0, 0.0}}, "Test Road", "en"));
  }
  TEST_EQUAL(frm.RegisterMap(country).second, MwmSet::RegResult::Success, ());

  m2::PointD const tapPoint(0.9, 0.0);
  auto const roadId = frm.GetFeatureAtPoint(tapPoint);
  TEST(roadId.IsValid(), ("The tap must resolve the test road."));

  place_page::BuildInfo bi;
  bi.m_source = place_page::BuildInfo::Source::User;
  bi.m_mercator = tapPoint;
  bi.m_featureId = roadId;
  frm.BuildAndSetPlacePageInfo(bi);

  auto const & info = frm.GetCurrentPlacePageInfo();
  TEST_EQUAL(info.GetID(), roadId, ());
  TEST_EQUAL(info.GetGeomType(), feature::GeomType::Line, ());
  TEST_NOT_EQUAL(info.GetMercator(), tapPoint,
                 ("Explicit feature selection keeps the feature center in the place page."));

  ScopedFile const notesFile("test_editor_notes_explicit.xml", ScopedFile::Mode::DoNotCreate);
  osm::Editor::Instance().SetNotesForTesting(notesFile.GetFullPath());

  osm::EditableMapObject emo;
  TEST(frm.GetEditableMapObject(info.GetID(), emo), ());
  frm.CreateNote(emo, osm::Editor::NoteProblemType::General, "Obstacle on the road");

  editor::Notes const notes(notesFile.GetFullPath());
  TEST_EQUAL(notes.GetNotesForTests().size(), 1, ());
  TEST_ALMOST_EQUAL_ABS(notes.GetNotesForTests().front().m_point, mercator::ToLatLon(tapPoint), 1e-4, ());

  platform::CountryIndexes::DeleteFromDisk(country);
  country.DeleteFromDisk(MapFileType::Map);
}
}  // namespace editor_notes_tests