start fixing test for multi cat phenotype upload.
[sgn.git] / t / selenium2 / breeders / location.t
blob81278448ec9b0a1f2c17eabbebb4d7abdf9dc00a
2 use lib 't/lib';
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 {
11     sleep(1);
12     
13     $t->get_ok('/breeders/locations');
14     sleep(5);
16     my $add_location_link = $t->find_element_ok(
17         "location_map",
18         "id",
19         "find location map on page add location link as submitter"
20         );
22     $add_location_link->click();
24     $t->find_element_ok(
25         'a[onclick*="add_from_map"]',
26         "css",
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(
32         "location_name",
33         "id",
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",
40         "id",
41         "find location abbreviation input");
42     $location_abbr_input->send_keys($location_abbr);
45     my $location_country = "PER";
47     $t->find_element_ok(
48         "location_country",
49         "id",
50         "find location country input")
51         ->click();
53     $t->find_element_ok(
54         "option[value=\"$location_country\"]",
55         "css",
56         "find location PERU country value")
57         ->click();
59     $t->find_element_ok(
60         "breeding_program_select",
61         "id",
62         "find breeding program select and clear")
63         ->click();
65     my $location_program = "test";
66     $t->find_element_ok(
67         "breeding_program_select",
68         "id",
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(
74         "location_type",
75         "id",
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(
85         "location_latitude",
86         "id",
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(
94         "location_longitude",
95         "id",
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(
103         "location_altitude",
104         "id",
105         "find location altitude input");
107     $location_altitude_input->clear();
108     $location_altitude_input->send_keys($location_altitude);
110     $t->find_element_ok(
111         "store_location_submit",
112         "id",
113         "find location submit and click")
114         ->click();
115     sleep(2);
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');
121     sleep(2);
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");
135 $t->driver->quit();
136 done_testing();