3 use Test::More 'tests' => 48;
5 use SGN::Test::WWW::WebDriver;
6 use Selenium::Remote::WDKeys 'KEYS';
7 use SGN::Test::Fixture;
9 my $t = SGN::Test::WWW::WebDriver->new();
10 my $f = SGN::Test::Fixture->new();
12 $t->while_logged_in_as("curator", sub {
15 # Note: Use the fuzzy search to match similar names to prevent uploading of duplicate accessions. Fuzzy searching is much slower than regular search. Only a curator can disable the fuzzy search.
16 $t->get_ok('/breeders/accessions');
19 $t->find_element_ok("lists_link", "name", "find lists_link")->click();
20 $t->find_element_ok("add_list_input", "id", "find add list input");
22 my $random_val = int(rand(1000));
23 my $list_name = sprintf("new_test_list_accessions_%d", $random_val);
25 $t->find_element_ok("add_list_input", "id", "find add list input test")->send_keys($list_name);
27 $t->find_element_ok("add_list_button", "id", "find add list button test")->click();
29 $t->find_element_ok("view_list_$list_name", "id", "view list test")->click();
32 $t->find_element_ok("type_select", "id", "add type of list")->click();
33 $t->find_element_ok('option[name="accessions"]', "css", "select type 'accessions' from a list")->click();
36 $t->find_element_ok("dialog_add_list_item", "id", "add test list items")->send_keys("element1\nelement2\nelement3\n");
39 $t->find_element_ok("dialog_add_list_item_button", "id", "find add_list_item_button and click")->click();
41 $t->find_element_ok("close_list_item_dialog", "id", "find close_list_item_dialog button and click")->click();
43 $t->find_element_ok("close_list_dialog_button", "id", "find close dialog button and click")->click();
45 # first try with fuzzy search on test_stocks // before tests were run on test_list' but is not available for
46 # jane doe user as curator - only for submitter john doe
48 $t->get_ok('/breeders/accessions');
51 $t->find_element_ok("add_accessions_link", "name", "find element add accessions link as curator")->click();
52 $t->find_element_ok("list_div_list_select", "id", "find and open list select input")->click();
53 $t->find_element_ok('//option[text()="test_stocks"]', "xpath", "select new_list name 'test_stock'")->click();
56 my $fuzzy_checkbox = $t->find_element_ok("fuzzy_check", "id", "check fuzzy and uncheck it");
57 unless($fuzzy_checkbox->get_attribute('checked')) {
58 $fuzzy_checkbox->click();
61 my $submit_accessions = $t->find_element_ok("new_accessions_submit", "id", "submit new accessions");
62 $submit_accessions->click();
65 my $review_found_matches = $t->find_element_ok("review_found_matches_hide", "id", "review found matches test");
66 $review_found_matches->click();
69 $t->driver->accept_alert();
71 # then we add new_test_list_accessions not using fuzzy search should be added as first without problems
72 # with a name of organism Manihot esculenta
73 $t->get_ok('/breeders/accessions');
76 $t->find_element_ok("add_accessions_link", "name", "find element add accessions link as curator")->click();
78 $t->find_element_ok("list_div_list_select", "id", "select new list test")->click();
79 $t->find_element_ok("//option[text()=\"$list_name\"]", "xpath", "select new_list")->click();
82 # fuzzy checkbox if checked then click (uncheck)
83 $fuzzy_checkbox = $t->find_element_ok("fuzzy_check", "id", "check fuzzy and uncheck it");
84 if ($fuzzy_checkbox->get_attribute('checked')) {
85 $fuzzy_checkbox->click();
88 my $submit_accessions = $t->find_element_ok("new_accessions_submit", "id", "submit new accessions");
89 $submit_accessions->click();
92 my $review_found_matches = $t->find_element_ok("review_found_matches_hide", "id", "review found matches test");
93 $review_found_matches->click();
95 my $species_name_input = $t->find_element_ok("species_name_input", "id", "input species name");
96 $species_name_input->send_keys(KEYS->{'control'}, 'a');
97 $species_name_input->send_keys(KEYS->{'backspace'});
98 $species_name_input->send_keys("Manihot esculenta");
100 my $review_matches = $t->find_element_ok("review_absent_accessions_submit", "id", "review matches and submit");
101 $review_matches->click();
104 $t->find_element_ok("close_add_accessions_saved_message_modal", "id", "close add accessions saved message modal");
106 # then we add new_test_list_accession again, not using fuzzy search to see if it sees them in the db.
107 # there should be in DB ain we shouldn't have a option to add them
108 $t->get_ok('/breeders/accessions');
111 $t->find_element_ok("add_accessions_link", "name", "find element add accessions link as curator")->click();
112 $t->find_element_ok("list_div_list_select", "id", "select new list test")->click();
113 $t->find_element_ok("//option[text()=\"$list_name\"]", "xpath", "select new_list")->click();
116 # fuzzy checkbox if checked then click
117 $fuzzy_checkbox = $t->find_element_ok("fuzzy_check", "id", "check fuzzy and uncheck it");
118 if ($fuzzy_checkbox->get_attribute('checked')) {
119 $fuzzy_checkbox->click();
123 my $submit_accessions = $t->find_element_ok("new_accessions_submit", "id", "submit new accessions");
124 $submit_accessions->click();
127 my $review_matches = $t->find_element_ok(
128 "review_found_matches_hide",
130 "review found matches in db, close modal");
131 $review_matches->click();
134 $t->driver->accept_alert();
136 # then we add new_test_list_accessions again, using fuzzy search to see if it sees them in the db.
137 # with fuzzy logic results should be a same - cannot be added to DB
138 $t->get_ok('/breeders/accessions');
141 $t->find_element_ok("add_accessions_link", "name", "find element add accessions link as curator")->click();
142 $t->find_element_ok("list_div_list_select", "id", "select new list test")->click();
143 $t->find_element_ok("//option[text()=\"$list_name\"]", "xpath", "select new_list")->click();
146 $fuzzy_checkbox = $t->find_element_ok("fuzzy_check", "id", "check fuzzy checkbox");
147 unless ($fuzzy_checkbox->get_attribute('checked')) {
148 $fuzzy_checkbox->click();
151 my $submit_accessions = $t->find_element_ok("new_accessions_submit", "id", "submit new accessions");
152 $submit_accessions->click();
155 my $review_found_matches = $t->find_element_ok("review_found_matches_hide", "id", "review found matches, close modal");
156 $review_found_matches->click();
158 $t->driver->accept_alert();
162 $t->while_logged_in_as("submitter", sub {
165 # log as submitter and check if fuzzy logic is always checked and disable to change
166 $t->get_ok('/breeders/accessions');
169 $t->find_element_ok("add_accessions_link", "name", "find element add accessions link as submitter")->click();
171 my $fuzzy_checkbox = $t->find_element_ok("fuzzy_check", "id", "find fuzzy checkbox");
172 is $fuzzy_checkbox->get_attribute('checked'), 1, 'fuzzy logic checkbox is checked for submitter';
173 is $fuzzy_checkbox->get_attribute('disabled'), 1, 'fuzzy logic checkbox is disabled for submitter';