4 use Test::More 'tests'=>24;
6 use SGN::Test::WWW::WebDriver;
8 my $t = SGN::Test::WWW::WebDriver->new();
10 $t->while_logged_in_as("submitter", sub {
13 $t->get_ok('/breeders/locations');
16 my $add_location_link = $t->find_element_ok(
19 "find location map on page add location link as submitter"
22 $add_location_link->click();
25 'a[onclick*="add_from_map"]',
27 "find longitude input test")->click();
29 # fill a form for location and store values in variables to compare after upload to database
30 my $location_name = "yet_another_test_location";
31 my $location_desc_input = $t->find_element_ok(
34 "find location name input");
35 $location_desc_input->send_keys($location_name);
37 my $location_abbr = "YATL";
38 my $location_abbr_input = $t->find_element_ok(
39 "location_abbreviation",
41 "find location abbreviation input");
42 $location_abbr_input->send_keys($location_abbr);
45 my $location_country = "PER";
50 "find location country input")
54 "option[value=\"$location_country\"]",
56 "find location PERU country value")
60 "breeding_program_select",
62 "find breeding program select and clear")
65 my $location_program = "test";
67 "breeding_program_select",
69 "find breeding program select and choose test")
70 ->send_keys($location_program);
72 my $location_type = "Other";
73 my $location_type_select = $t->find_element_ok(
76 "find location type input");
77 $location_type_select->send_keys($location_type);
79 # Here are two options -> first to test if the leaflet correctly picks long and lat form a map - and later compare
80 # it to stored values, but it can be sometimes problematic if some settings are off or the internet doesn't work?
81 # We put fixed values for inputs on the safe side, but there is an alternative to the test leaflet.
83 my $location_latitude = "-15.8468";
84 my $location_latitude_input = $t->find_element_ok(
87 "find location latitude input");
89 $location_latitude_input->clear();
90 $location_latitude_input->send_keys($location_latitude);
92 my $location_longitude = "-70.0338";
93 my $location_longitude_input = $t->find_element_ok(
96 "find location longitude input");
98 $location_longitude_input->clear();
99 $location_longitude_input->send_keys($location_longitude);
101 my $location_altitude = "826";
102 my $location_altitude_input = $t->find_element_ok(
105 "find location altitude input");
107 $location_altitude_input->clear();
108 $location_altitude_input->send_keys($location_altitude);
111 "store_location_submit",
113 "find location submit and click")
117 ok($t->driver->get_alert_text() =~ m/location $location_name added successfully/i, 'new location was saved');
118 $t->driver->accept_alert();
120 $t->get_ok('/breeders/locations');
123 my $page_source = $t->driver->get_page_source();
124 ok($page_source =~ m/$location_name/, "location name loaded on page");
125 ok($page_source =~ m/$location_abbr/, "location abbreviation loaded on page");
126 ok($page_source =~ m/$location_country/, "location country loaded on page");
127 ok($page_source =~ m/$location_program/, "location program loaded on page");
128 ok($page_source =~ m/$location_type/, "location type loaded on page");
129 ok($page_source =~ m/$location_latitude/, "location latitude loaded on page");
130 ok($page_source =~ m/$location_longitude/, "location longitude loaded on page");
131 ok($page_source =~ m/$location_altitude/, "location altitude loaded on page");