3 use Test::More 'tests' => 46;
5 use SGN::Test::WWW::WebDriver;
7 my $t = SGN::Test::WWW::WebDriver->new();
8 use Selenium::Remote::WDKeys 'KEYS';
10 $t->while_logged_in_as("submitter", sub {
13 $t->get_ok('stock/38879/view');
16 # Test edit / cancel button for stock / accession
17 $t->find_element_ok('//div[@id="stock_details_buttons"]/a[contains(text(), "Edit")]', "xpath", "find edit link")->click();
20 $t->find_element_ok('//div[@id="stock_details_buttons"]/a[contains(text(), "Cancel")]', "xpath", "find edit link")->click();
23 $t->find_element_ok('//div[@id="stock_details_buttons"]/a[contains(text(), "Edit")]', "xpath", "find edit link")->click();
26 # Test edit form for stock / accession
27 my $species_name_input = $t->find_element_ok("species_name", "id", "edit stock organism");
28 $species_name_input->send_keys(KEYS->{'control'}, 'a');
29 $species_name_input->send_keys(KEYS->{'backspace'});
30 $species_name_input->send_keys('Manihot esculenta');
32 $t->find_element_ok("stockForm_reset_button", "id", "find reset edit button")->click();
35 $species_name_input = $t->find_element_ok("species_name", "id", "edit stock organism");
36 $species_name_input->send_keys(KEYS->{'control'}, 'a');
37 $species_name_input->send_keys(KEYS->{'backspace'});
38 $species_name_input->send_keys('Manihot esculenta');
40 $t->find_element_ok("type_id", "name", "edit stock type")->click();
44 '//select[@name="type_id"]/option[contains(text(), "tissue_sample")]',
46 "select stock type as 'tissue_sample'")->click();
49 my $unique_name = $t->find_element_ok("uniquename", "name", "edit stock uniquename");
50 $unique_name->send_keys(KEYS->{'control'}, 'a');
51 $unique_name->send_keys(KEYS->{'backspace'});
52 $unique_name->send_keys('UG120001_Testedit');
54 $t->find_element_ok("description", "name", "edit stock description")->send_keys('Test description edit.');
56 $t->find_element_ok("stockForm_submit_button", "id", "find submit edit button")->click();
59 # Test adding and removing synonyms from stock additional info section
60 # my $synonym_onswitch = $t->find_element_ok("stock_additional_info_section_onswitch", "id", "click to open image panel");
61 # $synonym_onswitch->click();
64 $t->find_element_ok("stock_add_synonym", "id", "find add synonym link")->click();
67 $t->find_element_ok("synonyms_select", "id", "find add synonym select")->click();
71 '//select[@id="synonyms_select"]/option[@title="stock_synonym"]',
73 "select 'stock_synonym' as value")->click();
76 $t->find_element_ok("synonyms_prop", "id", "find add synonym input")->send_keys('test_synonym');
78 $t->find_element_ok("synonyms_addProp_submit", "id", "add synonym submit")->click();
81 $t->driver->accept_alert();
84 $t->find_element_ok('//div[@id="synonyms_content"]/a[text() = "X"]', "xpath", "find delete synonym link")->click();
86 $t->driver->accept_alert();
88 $t->driver->accept_alert();
91 # Test adding parents from pedigree info section
92 $t->get_ok('stock/38879/view');
95 my $pedigree_section = $t->find_element_ok('stock_pedigree_section_onswitch', 'id', 'find pedigree section');
96 $t->driver->execute_script("arguments[0].scrollIntoView(true);window.scrollBy(0,-100)", $pedigree_section);
98 $pedigree_section->click();
101 my $add_parent_link = $t->find_element_ok('add_parent_link', 'id', 'find add parent link');
102 $add_parent_link->click();
105 my $stock_name = $t->find_element_ok("stock_autocomplete", "id", "add parent input");
106 $stock_name->send_keys('test_wrong_stock_name');
108 $t->find_element_ok("male", "id", "find male input")->click();
109 $t->find_element_ok("female", "id", "find female input")->click();
111 $t->find_element_ok("add_parent_cross_type", "id", "add parent input")->click();
115 '//select[@id="add_parent_cross_type"]/option[@value="biparental"]',
117 "add parent input")->click();
120 $t->find_element_ok("add_parent_submit", "id", "submit add parent")->click();
123 $t->driver->accept_alert();
126 $stock_name->send_keys(KEYS->{'control'}, 'a');
127 $stock_name->send_keys(KEYS->{'backspace'});
128 $stock_name->send_keys('test_accession1');
130 $t->find_element_ok("add_parent_submit", "id", "submit add parent")->click();
133 $t->driver->accept_alert();
136 $t->get_ok('stock/38879/view');
139 my $pedigree_section = $t->find_element_ok('stock_pedigree_section_onswitch', 'id', 'find pedigree section');
140 $t->driver->execute_script("arguments[0].scrollIntoView(true);window.scrollBy(0,-100)", $pedigree_section);
142 $pedigree_section->click();
145 my $add_parent_link = $t->find_element_ok('add_parent_link', 'id', 'find add parent link');
146 $add_parent_link->click();
149 $stock_name = $t->find_element_ok("stock_autocomplete", "id", "add parent input");
151 $t->find_element_ok("male", "id", "find male input")->click();
153 $stock_name->send_keys(KEYS->{'control'}, 'a');
154 $stock_name->send_keys(KEYS->{'backspace'});
155 $stock_name->send_keys('test_accession2');
157 $t->find_element_ok("add_parent_submit", "id", "submit add parent")->click();
160 $t->driver->accept_alert();
163 # Test if parents were added to database and now in a view
164 $t->get_ok('stock/38879/view');
167 my $pedigree_section = $t->find_element_ok('stock_pedigree_section_onswitch', 'id', 'find pedigree section');
168 $t->driver->execute_script("arguments[0].scrollIntoView(true);window.scrollBy(0,-100)", $pedigree_section);
170 $pedigree_section->click();
173 my $pedigree_view = $t->find_element_ok(
174 '//div[@id="pdgv-wrap"]',
176 'find a content of pedigree view')->get_attribute('innerHTML');
178 ok($pedigree_view =~ /test_accession1/, "Verify if test_accession1 on pedigree panel");
179 ok($pedigree_view =~ /test_accession2/, "Verify if test_accession2 on pedigree panel");
181 my $pedigree_string = $t->find_element_ok("pedigree_string", "id", "verify pedigree string")->get_text();
183 ok($pedigree_string =~ /test_accession1\/test_accession2/, "Verify if pedigree string contain 'test_accession1/test_accession2'");
185 $t->find_element_ok("remove_parent_link", "id", "find delete parent link")->click();
188 # Test removing parents from pedigree info section
190 '//div[@id="remove_parent_list"]/a[1]',
192 "find delete parent link")->click();
195 $t->driver->accept_alert();
198 $t->driver->accept_alert();
201 my $pedigree_section = $t->find_element_ok('stock_pedigree_section_onswitch', 'id', 'find pedigree section');
202 $t->driver->execute_script("arguments[0].scrollIntoView(true);window.scrollBy(0,-100)", $pedigree_section);
204 $pedigree_section->click();
207 $t->find_element_ok("remove_parent_link", "id", "find delete parent link")->click();
211 '//div[@id="remove_parent_list"]/a[1]',
213 "find delete parent link")->click();
215 $t->driver->accept_alert();
218 $t->driver->accept_alert();