Skip to content

Commit 8b46f06

Browse files
committed
Fix an issue with employees list showing incorrect used/remaining info
In case of "pending revoke" leaves ( leaves #166)
1 parent 3f40427 commit 8b46f06

File tree

7 files changed

+285
-14
lines changed

7 files changed

+285
-14
lines changed

lib/route/users.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,12 @@ router.get('/', function(req, res) {
517517
as : 'my_leaves',
518518
required : false,
519519
where : {
520-
status : model.Leave.status_approved(),
520+
// status : model.Leave.status_approved(),
521+
status : [
522+
model.Leave.status_approved(),
523+
model.Leave.status_new(),
524+
model.Leave.status_pended_revoke(),
525+
],
521526
$or : {
522527
date_start : {
523528
$between : [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "TimeOff.Management",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"private": false,
55
"description": "Simple yet powerful absence management software for small and medium size business",
66
"dependencies": {

t/integration/crud_users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('CRUD for users', function(){
132132
});
133133
});
134134

135-
it("And update its bose to be MANAGER", function(done){
135+
it("And update its boss to be MANAGER", function(done){
136136
submit_form_func({
137137
driver : driver,
138138
form_params : [{

t/integration/filter_users_by_departments.js renamed to t/integration/employees_page/filter_users_by_departments.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ var test = require('selenium-webdriver/testing'),
77
expect = require('chai').expect,
88
Promise = require("bluebird"),
99
until = require('selenium-webdriver').until,
10-
register_new_user_func = require('../lib/register_new_user'),
11-
login_user_func = require('../lib/login_with_user'),
12-
open_page_func = require('../lib/open_page'),
13-
submit_form_func = require('../lib/submit_form'),
14-
check_elements_func = require('../lib/check_elements'),
15-
add_new_user_func = require('../lib/add_new_user'),
10+
register_new_user_func = require('../../lib/register_new_user'),
11+
login_user_func = require('../../lib/login_with_user'),
12+
open_page_func = require('../../lib/open_page'),
13+
submit_form_func = require('../../lib/submit_form'),
14+
check_elements_func = require('../../lib/check_elements'),
15+
add_new_user_func = require('../../lib/add_new_user'),
1616
By = require('selenium-webdriver').By,
1717
new_department_form_id = '#add_new_department_form',
18-
config = require('../lib/config'),
18+
config = require('../../lib/config'),
1919
application_host = config.get_application_host();
2020

2121
/*
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
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+
});

t/integration/leave_request/cancel_basic.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ describe('Check only requestor can see the Cancel button', function(){
423423
.then(function(){ done() });
424424
});
425425

426-
it("Submit new leave requesti from user B for one weekday", function(done){
426+
it("Submit new leave requesti from user B", function(done){
427427
submit_form_func({
428428
driver : driver,
429429
form_params : [{
@@ -492,4 +492,9 @@ describe('Check only requestor can see the Cancel button', function(){
492492
done();
493493
});
494494
});
495+
496+
after(function(done){
497+
driver.quit().then(function(){ done(); });
498+
});
499+
495500
});

views/users.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
</thead>
3535
<tbody>
3636
{{# each users}}
37-
<tr>
37+
<tr data-vpp-user-row="{{this.id}}">
3838
<td class="user-link-cell"><a href="/users/edit/{{this.id}}/">{{this.full_name}}</a></td>
3939
<td class="user_department">{{this.department.name}}</td>
4040
<td>{{# if this.admin }}Yes{{else}}{{/if}}</td>
41-
<td>{{ this.calculate_number_of_days_available_in_allowance}}</td>
42-
<td>{{this.calculate_number_of_days_taken_from_allowance}}</td>
41+
<td class="vpp-days-remaining">{{ this.calculate_number_of_days_available_in_allowance}}</td>
42+
<td class="vpp-days-used">{{this.calculate_number_of_days_taken_from_allowance}}</td>
4343
</tr>
4444
{{/each}}
4545
</tbody>

0 commit comments

Comments
 (0)