start fixing test for multi cat phenotype upload.
[sgn.git] / t / selenium2 / 02_trial / trial_detail.t
blob57dd59833b928317ff463233ac13b927ad9984e1
1 use lib 't/lib';
2 use strict;
4 use Test::More 'tests' => 178;
6 use SGN::Test::WWW::WebDriver;
7 use SGN::Test::Fixture;
8 my $t = SGN::Test::WWW::WebDriver->new();
9 my $f = SGN::Test::Fixture->new();
11 $t->while_logged_in_as("curator", sub {
12     sleep(2);
14     for my $file ("T100_trial_layout.xls", "T100_trial_layout_selenium_second_file.xlsx") {
16         #Upload New Trial
17         $t->get_ok('/breeders/trials');
18         sleep(3);
20         $t->find_element_ok("upload_trial_link", "name", "click on upload_trial_link ")->click();
21         sleep(4);
23         # SCREEN 1 /Intro/
24         $t->find_element_ok("next_step_upload_intro_button", "id", "click on next_step_upload_intro_button ")->click();
25         sleep(1);
27         # SCREEN 2 /File formating/
28         $t->find_element_ok("upload_single_trial_design_tab", "id", "choose a single trial design tab (default)");
29         $t->find_element_ok('next_step_file_formatting_button', 'id', 'go to next screen - Intro')->click();
30         sleep(1);
32         # SCREEN 3 /Enter trial information/
33         my $trial_name = "selenium_test_trial_detail_$file";
34         $t->find_element_ok("trial_upload_name", "id", "find trial name input")->send_keys($trial_name);
36         $t->find_element_ok("trial_upload_breeding_program", "id", "find breeding program select")->click();
37         sleep(1);
38         $t->find_element_ok('//select[@id="trial_upload_breeding_program"]/option[@value="test"]', 'xpath', "Select 'test' as value for breeding program")->click();
40         $t->find_element_ok("trial_upload_location", "id", "find location select")->click();
41         sleep(1);
42         $t->find_element_ok('//select[@id="trial_upload_location"]/option[@value="test_location"]', 'xpath', "Select 'test_location' as value for trial location")->click();
44         $t->find_element_ok("trial_upload_trial_type", "id", "find trial type select")->click();
45         sleep(1);
47         $t->find_element_ok('//select[@id="trial_upload_trial_type"]/option[@title="phenotyping_trial"]', 'xpath', "Select 'phenotyping_trial' as value for type of trial")->click();
49         $t->find_element_ok("trial_upload_year", "id", "find trial year input")->click();
50         sleep(1);
51         $t->find_element_ok('//select[@id="trial_upload_year"]/option[@value="2016"]', 'xpath', "Select '2016' as value for year")->click();
53         $t->find_element_ok('trial_upload_plot_width', 'id', "find trial plot width input")->send_keys("10");
54         $t->find_element_ok('trial_upload_plot_length', 'id', "find trial plot length input")->send_keys("10");
55         $t->find_element_ok('trial_upload_field_size', 'id', "find trial field size input")->send_keys("5");
56         $t->find_element_ok('trial_upload_plant_entries', 'id', "find trial plants per plot input")->send_keys("10");
58         $t->find_element_ok("trial_upload_description", "id", "find trial description input")->send_keys('Test trial detail selenium - description');;
60         $t->find_element_ok("trial_upload_trial_stock_type", "id", "find trial design select")->click();
61         sleep(1);
62         $t->find_element_ok('//select[@id="trial_upload_trial_stock_type"]/option[@value="accession"]', 'xpath', "Select 'accession' as value for stock type")->click();
64         $t->find_element_ok("trial_upload_design_method", "id", "find trial design select")->click();
65         sleep(1);
66         $t->find_element_ok('//select[@id="trial_upload_design_method"]/option[@value="CRD"]', 'xpath', "Select 'CRD' as value for design method")->click();
68         my $upload_input = $t->find_element_ok("trial_uploaded_file", "id", "find file input");
69         my $filename = $f->config->{basepath} . "/t/data/trial/$file";
71         $t->driver()->upload_file($filename);
72         $upload_input->send_keys($filename);
73         sleep(2);
75         $t->find_element_ok('next_step_trial_information_button', 'id', 'go to next screen - Intro')->click();
76         # SCREEN 4 /Trial Linkage/
78         $t->find_element_ok("upload_trial_trial_sourced", "id", "find trial sourced select")->click();
79         sleep(1);
80         $t->find_element_ok('//select[@id="upload_trial_trial_sourced"]/option[@value="no"]', 'xpath', "Select 'no' as value for trial sourced")->click();
82         $t->find_element_ok("upload_trial_trial_will_be_genotyped", "id", "find 'trial will be genotyped' select")->click();
83         sleep(1);
84         $t->find_element_ok('//select[@id="upload_trial_trial_will_be_genotyped"]/option[@value="no"]', 'xpath', "Select 'no' as value for trial will be genotyped")->click();
86         $t->find_element_ok("upload_trial_trial_will_be_crossed", "id", "find 'trial will be crossed' select")->click();
87         sleep(1);
88         $t->find_element_ok('//select[@id="upload_trial_trial_will_be_crossed"]/option[@value="no"]', 'xpath', "Select 'no' as value for trial will be crossed")->click();
90         $t->find_element_ok("upload_trial_validate_form_button", "id", "find and click trial validate form button")->click();
91         sleep(2);
93         $t->find_element_ok("upload_trial_submit_first", "name", "find and click upload trial submit button")->click();
95         # important sleep 60 seconds for a functionality - it can take ages to save a trail depend of the machine
96         sleep(60);
98         $t->find_element_ok("close_trial_upload_dialog", "id", "find and click close trial upload button")->click();
100         # OPEN A TRIAL AFTER CREATE TO CHECK DETAILS
102         $t->get_ok('/breeders/trials');
103         sleep(3);
105         $t->find_element_ok("refresh_jstree_html_trialtree_button", "id", "refresh tree")->click();
106         sleep(5);
108         $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
109         sleep(3);
111         $t->find_element_ok("$trial_name", "partial_link_text", "open up tree")->click();
113         #New Trial ID from database
114         my $trial_id = $f->bcs_schema->resultset('Project::Project')->search({ name => $trial_name }, { order_by => { -desc => 'project_id' } })->first->project_id();
116         #Delete Trial Coordinates - Remove first one to upload new coordinates
117         $t->get_ok('/breeders/trial/' . $trial_id);
118         sleep(5);
120         my $heatmap_onswitch = $t->find_element_ok("pheno_heatmap_onswitch", "id", "click to open pheno heatmap panel");
121         $heatmap_onswitch->click();
122         sleep(3);
124         $t->find_element_ok("delete_field_map_hm_link", "id", "click on delete previous coordinate")->click();
125         sleep(1);
127         $t->find_element_ok("delete_field_coords_ok_button", "id", "click on delete previous coordinate - confirm")->click();
128         sleep(15);
130         $t->find_element_ok("dismiss_delete_field_map_dialog", "id", "click on confirmation of delete")->click();
131         sleep(10);
133         #Upload Trial Coordinates
134         my $heatmap_onswitch = $t->find_element_ok("pheno_heatmap_onswitch", "id", "click to open pheno heatmap panel");
135         $heatmap_onswitch->click();
136         sleep(3);
138         $t->find_element_ok("heatmap_upload_trial_coords_link", "id", "click on upload_trial_coords_link ")->click();
140         my $upload_input = $t->find_element_ok("trial_coordinates_uploaded_file", "id", "find file input");
142         my $filename = $f->config->{basepath} . "/t/data/trial/T100_trial_coords.csv";
143         $t->driver()->upload_file($filename);
144         $upload_input->send_keys($filename);
145         sleep(1);
147         $t->find_element_ok("upload_trial_coords_ok_button", "id", "submit upload trial coords file ")->click();
148         sleep(15);
150         $t->find_element_ok("trial_coord_upload_success_dialog_message_cancel", "id", "close success msg")->click();
151         sleep(1);
153         $t->find_element_ok("upload_trial_coords_cancel_button", "id", "close upload modal")->click();
154         sleep(5);
156         my $trial_details = $t->find_element_ok(
157             'trial_details_content',
158             'id',
159             "find content of trial details")->get_attribute('innerHTML');
161         ok($trial_details =~ /$trial_name/, "Verify trial name: $trial_name");
162         ok($trial_details =~ /test/, "Verify breeding program");
163         ok($trial_details =~ /test_location/, "Verify trial location");
164         ok($trial_details =~ /2016/, "Verify trial year");
165         ok($trial_details =~ /phenotyping_trial/, "Verify trial type");
166         ok($trial_details =~ /[No Planting Date]/, "Verify planting date");
167         ok($trial_details =~ /[No Harvest Date]/, "Verify harvest date");
168         ok($trial_details =~ /Test trial detail selenium - description/, "Verify description");
170         my $trial_design_onswitch = $t->find_element_ok("trial_design_section_onswitch", "id", "click to open design section");
171         $trial_design_onswitch->click();
172         sleep(3);
174         $trial_details = $t->find_element_ok(
175             'trial_controls_table',
176             'id',
177             "find content of trial design")->get_attribute('innerHTML');
179         ok($trial_details =~ /CRD/, "Verify ");
180         ok($trial_details =~ /2/, "Verify ");
182         $t->find_element_ok("trial_stocks_onswitch", "id", "view trial accessions")->click();
183         sleep(5);
185         $trial_details = $t->find_element_ok(
186             'trial_stocks_table',
187             'id',
188             "find content of trial accessions")->get_attribute('innerHTML');
190         ok($trial_details =~ /test_accession1/, "Verify accessions");
191         ok($trial_details =~ /test_accession2/, "Verify accessions");
192         ok($trial_details =~ /test_accession3/, "Verify accessions");
193         ok($trial_details =~ /test_accession4/, "Verify accessions");
195         $t->find_element_ok("trial_controls_onswitch", "id", "view trial controls")->click();
196         sleep(5);
198         $trial_details = $t->find_element_ok(
199             'trial_controls_content',
200             'id',
201             "find content of trial accessions")->get_attribute('innerHTML');
203         ok($trial_details =~ /test_accession2/, "Verify controls");
204         ok($trial_details =~ /test_accession3/, "Verify controls");
206         $t->find_element_ok("trial_plots_onswitch", "id", "view trial plots")->click();
207         sleep(5);
209         $t->find_element_ok("plot_select_all", "id", "select plots")->click();
210         sleep(1);
212         $t->find_element_ok("plot_data_new_list_name", "id", "find add list input");
214         my $add_list_input = $t->find_element_ok("plot_data_new_list_name", "id", "find add list input test");
216         $add_list_input->send_keys("plots_list");
218         $t->find_element_ok("plot_data_add_to_new_list", "id", "find add list button")->click();
219         sleep(1);
220         $t->accept_alert_ok();
221         sleep(1);
223         # Open a a newly created list and check details of list
224         my $out = $t->find_element_ok("lists_link", "name", "find lists_link")->click();
225         sleep(3);
227         $t->find_element_ok("view_list_plots_list", "id", "view 'plots_list' for test")->click();
228         sleep(2);
230         $trial_details = $t->find_element_ok(
231             'list_item_dialog_datatable_wrapper',
232             'id',
233             "find content of list to check details")->get_attribute('innerHTML');
235         ok($trial_details =~ /T100_plot_01/, "Verify plots");
236         ok($trial_details =~ /T100_plot_02/, "Verify plots");
237         ok($trial_details =~ /T100_plot_03/, "Verify plots");
238         ok($trial_details =~ /T100_plot_04/, "Verify plots");
239         ok($trial_details =~ /T100_plot_05/, "Verify plots");
240         ok($trial_details =~ /T100_plot_06/, "Verify plots");
241         ok($trial_details =~ /T100_plot_07/, "Verify plots");
242         ok($trial_details =~ /T100_plot_08/, "Verify plots");
243     }
246 $t->driver->close();
247 done_testing();