start fixing test for multi cat phenotype upload.
[sgn.git] / t / selenium2 / breeders / 01_folder.t
blob3a08544892792dc02f8ffb6875b999f42b58ca0d
2 use strict;
4 use lib 't/lib';
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 {
17     sleep(2);
19     $t->get_ok("/breeders/trials");
20     sleep(7);
22     $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
23     sleep(10);
25   $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
26   sleep(5);
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);
35   sleep(2);
37   $t->find_element_ok('button[id="new_folder_submit"]', "css", "create new folder submit")->click();
38   sleep(5);
40   $t->find_element_ok('button[id="close_new_folder_success_dialog"]', "css", "close new folder success dialog")->click();
41   sleep(8);
43   $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
44   sleep(10);
46   $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
47   sleep(5);
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();
54   sleep(1);
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();
64   sleep(1);
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();
71   sleep(5);
73   $t->find_element_ok('button[id="close_new_folder_success_dialog"]', "css", "close new folder success dialog")->click();
74   sleep(7);
76   $t->find_element_ok("refresh_jstree_html", "name", "refresh tree")->click();
77   sleep(5);
79   $t->find_element_ok("jstree-icon", "class", "open up tree")->click();
80   sleep(2);
82   # MOVE TRIAL TO F2 FOLDER FROM MODAL WINDOW
83   $t->find_element_ok("open_folder_dialog_link", "id", "place trial in F2")->click();
84   sleep(1);
86   $t->find_element_ok("html_select_folder_for_trial", "id","pass child folder $folder_child_name as folder name")->click();
87   sleep(1);
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');
91   $child_elem->click();
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();
97   sleep(4);
98   $t->find_element_ok('button[id="close_set_folder_success_dialog"]', "css", "close set folder success dialog")->click();
99   sleep(2);
101   # TEST DELETE OF PARENT FOLDER - SHOULD FAIL
102   $t->get_ok("/folder/$parent_folder_number");
103   sleep(2);
105   $t->find_element_ok("delete_folder_button", "id", "delete folder fails because child folder.")->click();
106   $t->driver->accept_alert();
107   sleep(2);
108   $t->driver->accept_alert();
109   sleep(2);
111   $t->find_element_ok("Folders", "partial_link_text", "go to folder tab")->click();
112   sleep(2);
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();
121   sleep(2);
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");
126   sleep(2);
128   $t->find_element_ok("delete_folder_button", "id", "delete folder")->click();
129   $t->driver->accept_alert();
130   sleep(2);
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");
138   sleep(2);
140   $t->find_element_ok("open_folder_dialog_link", "id", "open a 'move trail' modal window to move trial from F2 folder")->click();
141   sleep(1);
143   $t->find_element_ok("html_select_folder_for_trial", "id","pass 'None' (root) folder as folder name")->click();
144   sleep(1);
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();
152   sleep(4);
153   $t->find_element_ok('button[id="close_set_folder_success_dialog"]', "css", "close set folder success dialog")->click();
154   sleep(2);
156   # DELETE F2 FOLDER
158   $t->get_ok("/folder/$child_folder_number");
159   sleep(2);
161   $t->find_element_ok("delete_folder_button", "id", "find 'delete folder' button and click")->click();
162   $t->driver->accept_alert();
163   sleep(2);
164   $t->driver->accept_alert();
165   sleep(2);
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");
173 $t->driver->close();
174 $f->clean_up_db();
175 done_testing();