|
| 1 | + |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +var test = require('selenium-webdriver/testing'), |
| 6 | + By = require('selenium-webdriver').By, |
| 7 | + until = require('selenium-webdriver').until, |
| 8 | + Promise = require("bluebird"), |
| 9 | + expect = require('chai').expect, |
| 10 | + moment = require('moment'), |
| 11 | + add_new_user_func = require('../../lib/add_new_user'), |
| 12 | + check_elements_func = require('../../lib/check_elements'), |
| 13 | + config = require('../../lib/config'), |
| 14 | + login_user_func = require('../../lib/login_with_user'), |
| 15 | + logout_user_func = require('../../lib/logout_user'), |
| 16 | + open_page_func = require('../../lib/open_page'), |
| 17 | + register_new_user_func = require('../../lib/register_new_user'), |
| 18 | + submit_form_func = require('../../lib/submit_form'), |
| 19 | + user_info_func = require('../../lib/user_info'), |
| 20 | + application_host = config.get_application_host(); |
| 21 | + |
| 22 | +/* |
| 23 | + * Scenario (based in bug #166): |
| 24 | + * |
| 25 | + * * Create company |
| 26 | + * * Obtain admoin details and go to admin details page |
| 27 | + * * Update admin's details to have start date as very beginnign of this year |
| 28 | + * * Add one week length holiday and approve it |
| 29 | + * * Check that allowance section of user details page shows "15 out of 20" |
| 30 | + * * Go to employees list page and make sure used shows 5 and remaining 15 |
| 31 | + * * Initiate revoke procedure (but not finish) |
| 32 | + * * Go to employees list page and make sure used shows 5 and remaining 15 |
| 33 | + * |
| 34 | + * */ |
| 35 | + |
| 36 | +describe('Leave request cancelation', function(){ |
| 37 | + |
| 38 | + this.timeout( config.get_execution_timeout() ); |
| 39 | + |
| 40 | + var driver, email_A, user_id_A; |
| 41 | + |
| 42 | + it("Register new company", function(done){ |
| 43 | + register_new_user_func({ |
| 44 | + application_host : application_host, |
| 45 | + }) |
| 46 | + .then(function(data){ |
| 47 | + driver = data.driver; |
| 48 | + email_A = data.email; |
| 49 | + done(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + it("Obtain information about admin user A", function(done){ |
| 54 | + user_info_func({ |
| 55 | + driver : driver, |
| 56 | + email : email_A, |
| 57 | + }) |
| 58 | + .then(function(data){ |
| 59 | + user_id_A = data.user.id; |
| 60 | + done(); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('Open user A details page', function(done){ |
| 65 | + open_page_func({ |
| 66 | + url : application_host + 'users/edit/'+user_id_A+'/', |
| 67 | + driver : driver, |
| 68 | + }) |
| 69 | + .then(function(){ done() }); |
| 70 | + }); |
| 71 | + |
| 72 | + |
| 73 | + it('Update admin details to have start date at very beginig of this year', function(done){ |
| 74 | + submit_form_func({ |
| 75 | + driver : driver, |
| 76 | + form_params : [{ |
| 77 | + selector : 'input#start_date_inp', |
| 78 | + value : moment().startOf('year').format('YYYY-MM-DD'), |
| 79 | + }], |
| 80 | + submit_button_selector : 'button#save_changes_btn', |
| 81 | + message : /Details for .+ were updated/, |
| 82 | + should_be_successful : true, |
| 83 | + }) |
| 84 | + .then(function(){ done() }); |
| 85 | + }); |
| 86 | + |
| 87 | + it("Open calendar page", function(done){ |
| 88 | + open_page_func({ |
| 89 | + url : application_host + 'calendar/?year=2015&show_full_year=1', |
| 90 | + driver : driver, |
| 91 | + }) |
| 92 | + .then(function(){done()}); |
| 93 | + }); |
| 94 | + |
| 95 | + it("Open Book leave popup window", function(done){ |
| 96 | + driver.findElement(By.css('#book_time_off_btn')) |
| 97 | + .then(function(el){ return el.click() }) |
| 98 | + .then(function(el){ |
| 99 | + // This is very important line when working with Bootstrap modals! |
| 100 | + return driver.sleep(1000); |
| 101 | + }) |
| 102 | + .then(function(){ done() }); |
| 103 | + }); |
| 104 | + |
| 105 | + it("Submit new leave request for user A one weekday", function(done){ |
| 106 | + submit_form_func({ |
| 107 | + driver : driver, |
| 108 | + form_params : [{ |
| 109 | + selector : 'input#from', |
| 110 | + value : '2017-05-01', |
| 111 | + },{ |
| 112 | + selector : 'input#to', |
| 113 | + value : '2017-05-07', |
| 114 | + }], |
| 115 | + message : /New leave request was added/, |
| 116 | + }) |
| 117 | + .then(function(){done()}); |
| 118 | + }); |
| 119 | + |
| 120 | + it("Open requests page", function( done ){ |
| 121 | + open_page_func({ |
| 122 | + url : application_host + 'requests/', |
| 123 | + driver : driver, |
| 124 | + }) |
| 125 | + .then(function(){ done() }); |
| 126 | + }); |
| 127 | + |
| 128 | + it("Approve new leave request", function(done){ |
| 129 | + driver.findElement(By.css( |
| 130 | + 'tr[vpp="pending_for__'+email_A+'"] .btn-success' |
| 131 | + )) |
| 132 | + .then(function(el){ return el.click(); }) |
| 133 | + .then(function(){ |
| 134 | + // Wait until page properly is reloaded |
| 135 | + return driver.wait(until.elementLocated(By.css('h1')), 1000); |
| 136 | + }) |
| 137 | + .then(function(){done()}); |
| 138 | + }); |
| 139 | + |
| 140 | + it('Open user A details page (abcenses section)', function(done){ |
| 141 | + open_page_func({ |
| 142 | + url : application_host + 'users/edit/'+user_id_A+'/absences/', |
| 143 | + driver : driver, |
| 144 | + }) |
| 145 | + .then(function(){ done() }); |
| 146 | + }); |
| 147 | + |
| 148 | + it('Check that allowance section of user details page shows "15 out of 20"', function(done){ |
| 149 | + driver |
| 150 | + .findElement( By.css('#days_remaining_inp') ) |
| 151 | + .then(function(inp){ |
| 152 | + return inp.getAttribute('value'); |
| 153 | + }) |
| 154 | + .then(function(text){ |
| 155 | + expect( text ).to.be.eq('15 out of 20'); |
| 156 | + done(); |
| 157 | + }) |
| 158 | + }); |
| 159 | + |
| 160 | + it('Open employees list page', function(done){ |
| 161 | + open_page_func({ |
| 162 | + url : application_host + 'users', |
| 163 | + driver : driver, |
| 164 | + }) |
| 165 | + .then(function(){ done() }); |
| 166 | + }); |
| 167 | + |
| 168 | + it('Ensure "remaining" 15', function(done){ |
| 169 | + driver |
| 170 | + .findElement( By.css('tr[data-vpp-user-row="'+user_id_A+'"] .vpp-days-remaining') ) |
| 171 | + .then(function(el){ return el.getText() }) |
| 172 | + .then(function(text){ |
| 173 | + expect( text ).to.be.eq('15'); |
| 174 | + done(); |
| 175 | + }) |
| 176 | + }); |
| 177 | + |
| 178 | + it('Ensure "used" shows 5', function(done){ |
| 179 | + driver |
| 180 | + .findElement( By.css('tr[data-vpp-user-row="'+user_id_A+'"] .vpp-days-used') ) |
| 181 | + .then(function(el){ return el.getText() }) |
| 182 | + .then(function(text){ |
| 183 | + expect( text ).to.be.eq('5'); |
| 184 | + done(); |
| 185 | + }) |
| 186 | + }); |
| 187 | + |
| 188 | + it("Open requests page", function(done){ |
| 189 | + open_page_func({ |
| 190 | + url : application_host + 'requests/', |
| 191 | + driver : driver, |
| 192 | + }) |
| 193 | + .then(function(){ done() }); |
| 194 | + }); |
| 195 | + |
| 196 | + it('Initiate revoke procedure (but not finish)', function(done){ |
| 197 | + driver |
| 198 | + .findElement(By.css( |
| 199 | + 'button.revoke-btn' |
| 200 | + )) |
| 201 | + .then(function(el){ return el.click(); }) |
| 202 | + .then(function(){ |
| 203 | + // Wait until page properly is reloaded |
| 204 | + return driver.wait(until.elementLocated(By.css('h1')), 1000); |
| 205 | + }) |
| 206 | + .then(function(){ done() }); |
| 207 | + }); |
| 208 | + |
| 209 | + it('Open user A details page (abcenses section)', function(done){ |
| 210 | + open_page_func({ |
| 211 | + url : application_host + 'users/edit/'+user_id_A+'/absences/', |
| 212 | + driver : driver, |
| 213 | + }) |
| 214 | + .then(function(){ done() }); |
| 215 | + }); |
| 216 | + |
| 217 | + it('Check that allowance section of user details page shows "15 out of 20"', function(done){ |
| 218 | + driver |
| 219 | + .findElement( By.css('#days_remaining_inp') ) |
| 220 | + .then(function(inp){ |
| 221 | + return inp.getAttribute('value'); |
| 222 | + }) |
| 223 | + .then(function(text){ |
| 224 | + expect( text ).to.be.eq('15 out of 20'); |
| 225 | + done(); |
| 226 | + }) |
| 227 | + }); |
| 228 | + |
| 229 | + it('Open employees list page', function(done){ |
| 230 | + open_page_func({ |
| 231 | + url : application_host + 'users', |
| 232 | + driver : driver, |
| 233 | + }) |
| 234 | + .then(function(){ done() }); |
| 235 | + }); |
| 236 | + |
| 237 | + it('Ensure "remaining" 15', function(done){ |
| 238 | + driver |
| 239 | + .findElement( By.css('tr[data-vpp-user-row="'+user_id_A+'"] .vpp-days-remaining') ) |
| 240 | + .then(function(el){ return el.getText() }) |
| 241 | + .then(function(text){ |
| 242 | + expect( text ).to.be.eq('15'); |
| 243 | + done(); |
| 244 | + }) |
| 245 | + }); |
| 246 | + |
| 247 | + it('Ensure "used" shows 5', function(done){ |
| 248 | + driver |
| 249 | + .findElement( By.css('tr[data-vpp-user-row="'+user_id_A+'"] .vpp-days-used') ) |
| 250 | + .then(function(el){ return el.getText() }) |
| 251 | + .then(function(text){ |
| 252 | + expect( text ).to.be.eq('5'); |
| 253 | + done(); |
| 254 | + }) |
| 255 | + }); |
| 256 | + |
| 257 | + after(function(done){ |
| 258 | + driver.quit().then(function(){ done(); }); |
| 259 | + }); |
| 260 | + |
| 261 | +}); |
0 commit comments