6 use Test::More 'tests' => 48;
8 use SGN::Test::WWW::WebDriver;
9 use Selenium::Remote::WDKeys 'KEYS';
10 use SGN::Test::Fixture;
12 my $t = SGN::Test::WWW::WebDriver->new();
13 my $f = SGN::Test::Fixture->new();
14 my $schema = $f->bcs_schema;
16 $t->while_logged_in_as("submitter", sub {
19 $t->get_ok("/breeders/trials");
22 $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
25 $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
28 $t->find_element_ok("new_folder_dialog_link", "id", "create new folder")->click();
30 # CREATE NEW F1 PARENT FOLDER
31 my $random_val = int(rand(1000));
32 my $folder_parent_name = sprintf("Selenium_F1_%d", $random_val);
34 $t->find_element_ok("new_folder_name", "id","pass F1 as new folder name")->send_keys($folder_parent_name);
37 $t->find_element_ok('button[id="new_folder_submit"]', "css", "create new folder submit")->click();
40 $t->find_element_ok('button[id="close_new_folder_success_dialog"]', "css", "close new folder success dialog")->click();
43 $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
46 $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
49 my $page_source = $t->driver->get_page_source();
51 $t->find_element_ok("//a[contains(text(),\"$folder_parent_name\")]", 'xpath', "Confirm if new $folder_parent_name folder exists after tree refresh");
53 $t->find_element_ok("new_folder_dialog_link", "id", "create new F2 folder")->click();
56 # CREATE NEW F2 CHILD FOLDER
57 my $folder_child_name = sprintf("Selenium_F2_%d", $random_val);
58 my $new_folder_field = $t->find_element_ok("new_folder_name", "id","find 'new folder name' textbox and clear a field");
59 $new_folder_field->send_keys(KEYS->{'control'}, 'a');
60 $new_folder_field->send_keys(KEYS->{'backspace'});
61 $t->find_element_ok("new_folder_name", "id","pass F2 as new folder name")->send_keys($folder_child_name);
63 $t->find_element_ok('select[id="new_folder_parent_folder_id"]', "css","find and click to open new_folder/parent_folder")->click();
66 my $parent_elem = $t->find_element_ok("option[title='$folder_parent_name']", "css","find parent name by title and select parent : $folder_parent_name");
67 my $parent_folder_number = $parent_elem->get_attribute('value');
68 $parent_elem->click();
70 $t->find_element_ok('button[id="new_folder_submit"]', "css", "create new folder submit")->click();
73 $t->find_element_ok('button[id="close_new_folder_success_dialog"]', "css", "close new folder success dialog")->click();
76 $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
79 $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
82 # MOVE TRIAL TO F2 FOLDER FROM MODAL WINDOW
83 $t->find_element_ok("open_folder_dialog_link", "id", "place trial in F2")->click();
86 $t->find_element_ok("html_select_folder_for_trial", "id","pass child folder $folder_child_name as folder name")->click();
89 my $child_elem = $t->find_element_ok("option[title='$folder_child_name']", "css","find child folder name by title and select : $folder_child_name");
90 my $child_folder_number = $child_elem->get_attribute('value');
93 $t->find_element_ok("html_select_trial_for_folder", "id","find select trial for folder pass and click (open)")->click();
94 $t->find_element_ok('option[title="test_trial"]', "css","pass test_trial as trial names")->click();
96 $t->find_element_ok("set_trial_folder", "id", "add trial to folder submit")->click();
98 $t->find_element_ok('button[id="close_set_folder_success_dialog"]', "css", "close set folder success dialog")->click();
101 # TEST DELETE OF PARENT FOLDER - SHOULD FAIL
102 $t->get_ok("/folder/$parent_folder_number");
105 $t->find_element_ok("delete_folder_button", "id", "delete folder fails because child folder.")->click();
106 $t->driver->accept_alert();
108 $t->driver->accept_alert();
111 $t->find_element_ok("Folders", "partial_link_text", "go to folder tab")->click();
114 # MOVE CHILD FOLDER (F2) FROM PARENT (F1) FOLDER AND DELETE PARENT (F1)
115 $t->find_element_ok("move_folder_dialog_link", "id", "find 'move folder' link and click")->click();
117 $t->find_element_ok("move_folder_id", "id","find move folder select and open it");
118 $t->find_element_ok("option[title='$folder_child_name']", "css","pass child folder : $folder_child_name as folder name")->click();
120 $t->find_element_ok("move_folder_submit", "id", "find move folder submit button and click")->click();
122 $t->find_element_ok('button[id="close_move_folder_success_dialog"]', "css", "close move folder success dialog")->click();
124 # TEST DELETE OF PARENT FOLDER - SHOULD PASS BECAUSE FOLDER IS EMPTY
125 $t->get_ok("/folder/$parent_folder_number");
128 $t->find_element_ok("delete_folder_button", "id", "delete folder")->click();
129 $t->driver->accept_alert();
131 $t->driver->accept_alert();
133 my $check_folder_deleted = $schema->resultset("Project::Project")->find({ project_id => $parent_folder_number});
134 ok(!$check_folder_deleted, "folder F1 deleted");
136 # MOVE TEST_TRIAL TO ROOT FOLDER
137 $t->get_ok("/breeders/trials");
140 $t->find_element_ok("open_folder_dialog_link", "id", "open a 'move trail' modal window to move trial from F2 folder")->click();
143 $t->find_element_ok("html_select_folder_for_trial", "id","pass 'None' (root) folder as folder name")->click();
146 $t->find_element_ok("option[value='0']", "css","find 'None' folder name by value '0' and select")->click();
148 $t->find_element_ok("html_select_trial_for_folder", "id","find select trial for folder pass and click (open)")->click();
149 $t->find_element_ok('option[title="test_trial"]', "css","pass test_trial as trial names")->click();
151 $t->find_element_ok("set_trial_folder", "id", "add trial to folder 'None' and submit button")->click();
153 $t->find_element_ok('button[id="close_set_folder_success_dialog"]', "css", "close set folder success dialog")->click();
158 $t->get_ok("/folder/$child_folder_number");
161 $t->find_element_ok("delete_folder_button", "id", "find 'delete folder' button and click")->click();
162 $t->driver->accept_alert();
164 $t->driver->accept_alert();
167 # CHECK IF F2 FOLDER EXISTS
168 $check_folder_deleted = $schema->resultset("Project::Project")->find({ project_id => $child_folder_number});
169 ok(!$check_folder_deleted, "folder F2 deleted");