@@ -2,7 +2,7 @@ import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
2
2
import { MockStore , provideMockStore } from '@ngrx/store/testing' ;
3
3
import { DataTablesModule } from 'angular-datatables' ;
4
4
import { NgxPaginationModule } from 'ngx-pagination' ;
5
- import { Entry } from 'src/app/modules/shared/models' ;
5
+ import { Activity , Entry , Customer , Project } from 'src/app/modules/shared/models' ;
6
6
import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/substract-date.pipe' ;
7
7
import { SubstractDatePipeDisplayAsFloat } from 'src/app/modules/shared/pipes/substract-date-return-float/substract-date-return-float.pipe' ;
8
8
import { getReportDataSource , getResultSumEntriesSelected } from 'src/app/modules/time-clock/store/entry.selectors' ;
@@ -11,6 +11,14 @@ import { TimeEntriesTableComponent } from './time-entries-table.component';
11
11
import { TotalHours } from '../../models/total-hours-report' ;
12
12
import { ActionsSubject } from '@ngrx/store' ;
13
13
import { UserActionTypes } from 'src/app/modules/users/store' ;
14
+ import { ProjectActionTypes } from 'src/app/modules/customer-management/components/projects/components/store/project.actions' ;
15
+ import { SearchUserComponent } from 'src/app/modules/shared/components/search-user/search-user.component' ;
16
+ import { SearchProjectComponent } from 'src/app/modules/shared/components/search-project/search-project.component' ;
17
+ import { SearchActivityComponent } from 'src/app/modules/shared/components/search-activity/search-activity.component' ;
18
+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
19
+ import { MatCheckboxModule } from '@angular/material/checkbox' ;
20
+ import { NgSelectModule } from '@ng-select/ng-select' ;
21
+ import { ActivityManagementActionTypes } from 'src/app/modules/activities-management/store' ;
14
22
15
23
describe ( 'Reports Page' , ( ) => {
16
24
describe ( 'TimeEntriesTableComponent' , ( ) => {
@@ -55,13 +63,13 @@ describe('Reports Page', () => {
55
63
uri : 'custom uri' ,
56
64
project_id : '123' ,
57
65
project_name : 'Time-Tracker' ,
58
- }
66
+ } ,
59
67
] ;
60
68
61
69
const state : EntryState = {
62
70
active : timeEntry ,
63
71
isLoading : false ,
64
- resultSumEntriesSelected : new TotalHours ( ) ,
72
+ resultSumEntriesSelected : new TotalHours ( ) ,
65
73
message : '' ,
66
74
createError : false ,
67
75
updateError : false ,
@@ -81,25 +89,37 @@ describe('Reports Page', () => {
81
89
beforeEach (
82
90
waitForAsync ( ( ) => {
83
91
TestBed . configureTestingModule ( {
84
- imports : [ NgxPaginationModule , DataTablesModule ] ,
85
- declarations : [ TimeEntriesTableComponent , SubstractDatePipe , SubstractDatePipeDisplayAsFloat ] ,
92
+ imports : [
93
+ NgxPaginationModule ,
94
+ DataTablesModule ,
95
+ MatCheckboxModule ,
96
+ NgSelectModule ,
97
+ FormsModule ,
98
+ ReactiveFormsModule ,
99
+ ] ,
100
+ declarations : [
101
+ TimeEntriesTableComponent ,
102
+ SubstractDatePipe ,
103
+ SubstractDatePipeDisplayAsFloat ,
104
+ SearchUserComponent ,
105
+ SearchProjectComponent ,
106
+ SearchActivityComponent ,
107
+ ] ,
86
108
providers : [ provideMockStore ( { initialState : state } ) , { provide : ActionsSubject , useValue : actionSub } ] ,
87
109
} ) . compileComponents ( ) ;
88
-
89
110
} )
90
111
) ;
91
112
92
- beforeEach (
93
- ( ) => {
94
- fixture = TestBed . createComponent ( TimeEntriesTableComponent ) ;
95
- component = fixture . componentInstance ;
96
- store = TestBed . inject ( MockStore ) ;
97
- store . setState ( state ) ;
98
- getReportDataSourceSelectorMock = ( store . overrideSelector ( getReportDataSource , state . reportDataSource ) ,
113
+ beforeEach ( ( ) => {
114
+ fixture = TestBed . createComponent ( TimeEntriesTableComponent ) ;
115
+ component = fixture . componentInstance ;
116
+ store = TestBed . inject ( MockStore ) ;
117
+ store . setState ( state ) ;
118
+ getReportDataSourceSelectorMock =
119
+ ( store . overrideSelector ( getReportDataSource , state . reportDataSource ) ,
99
120
store . overrideSelector ( getResultSumEntriesSelected , state . resultSumEntriesSelected ) ) ;
100
- fixture . detectChanges ( ) ;
101
- }
102
- ) ;
121
+ fixture . detectChanges ( ) ;
122
+ } ) ;
103
123
104
124
beforeEach ( ( ) => {
105
125
row = 0 ;
@@ -144,11 +164,10 @@ describe('Reports Page', () => {
144
164
const params = [
145
165
{ url : 'http://example.com' , expected_value : true } ,
146
166
{ url : 'https://example.com' , expected_value : true } ,
147
- { url : 'no-url-example' , expected_value : false }
167
+ { url : 'no-url-example' , expected_value : false } ,
148
168
] ;
149
169
params . map ( ( param ) => {
150
170
it ( `Given the url ${ param . url } , the method isURL should return ${ param . expected_value } ` , ( ) => {
151
-
152
171
expect ( component . isURL ( param . url ) ) . toEqual ( param . expected_value ) ;
153
172
} ) ;
154
173
} ) ;
@@ -160,50 +179,47 @@ describe('Reports Page', () => {
160
179
} ) ;
161
180
162
181
it ( 'when the rerenderDataTable method is called and dtElement and dtInstance are defined, the destroy and next methods are called ' ,
163
- ( ) => {
164
- spyOn ( component . dtTrigger , 'next' ) ;
182
+ ( ) => {
183
+ spyOn ( component . dtTrigger , 'next' ) ;
165
184
166
- component . ngAfterViewInit ( ) ;
185
+ component . ngAfterViewInit ( ) ;
167
186
168
- component . dtElement . dtInstance . then ( ( dtInstance ) => {
169
- expect ( component . dtTrigger . next ) . toHaveBeenCalled ( ) ;
170
- } ) ;
187
+ component . dtElement . dtInstance . then ( ( dtInstance ) => {
188
+ expect ( component . dtTrigger . next ) . toHaveBeenCalled ( ) ;
171
189
} ) ;
190
+ } ) ;
172
191
173
192
it ( `When the user method is called, the emit method is called` , ( ) => {
174
193
const userId = 'abc123' ;
175
194
spyOn ( component . selectedUserId , 'emit' ) ;
176
195
component . user ( userId ) ;
177
196
expect ( component . selectedUserId . emit ) . toHaveBeenCalled ( ) ;
178
-
179
197
} ) ;
180
198
181
199
it ( 'Should populate the users with the payload from the action executed' , ( ) => {
182
200
const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
183
201
const usersArray = [ ] ;
184
202
const action = {
185
203
type : UserActionTypes . LOAD_USERS_SUCCESS ,
186
- payload : usersArray
204
+ payload : usersArray ,
187
205
} ;
188
206
189
207
actionSubject . next ( action ) ;
190
208
191
-
192
209
expect ( component . users ) . toEqual ( usersArray ) ;
193
210
} ) ;
194
211
195
212
it ( 'The sum of the data dates is equal to {"hours": 3, "minutes":20,"seconds":0}' , ( ) => {
196
213
const { hours, minutes, seconds } : TotalHours = component . sumDates ( timeEntryList ) ;
197
214
expect ( { hours, minutes, seconds } ) . toEqual ( { hours : 3 , minutes : 20 , seconds : 0 } ) ;
198
-
199
215
} ) ;
200
216
201
217
it ( 'the sume of hours of entries selected is equal to {hours:0, minutes:0, seconds:0}' , ( ) => {
202
218
let checked = true ;
203
- let { hours, minutes, seconds} : TotalHours = component . sumHoursEntriesSelected ( timeEntryList [ 0 ] , checked ) ;
219
+ let { hours, minutes, seconds } : TotalHours = component . sumHoursEntriesSelected ( timeEntryList [ 0 ] , checked ) ;
204
220
checked = false ;
205
- ( { hours, minutes, seconds} = component . sumHoursEntriesSelected ( timeEntryList [ 0 ] , checked ) ) ;
206
- expect ( { hours, minutes, seconds} ) . toEqual ( { hours : 0 , minutes : 0 , seconds : 0 } ) ;
221
+ ( { hours, minutes, seconds } = component . sumHoursEntriesSelected ( timeEntryList [ 0 ] , checked ) ) ;
222
+ expect ( { hours, minutes, seconds } ) . toEqual ( { hours : 0 , minutes : 0 , seconds : 0 } ) ;
207
223
} ) ;
208
224
209
225
it ( 'should export data with the correct format' , ( ) => {
@@ -228,7 +244,7 @@ describe('Reports Page', () => {
228
244
"ng-reflect-ng-for-of": "git"
229
245
}--><!--ng-container--><!--bindings={
230
246
"ng-reflect-ng-if": "true"
231
- }-->`
247
+ }-->` ,
232
248
] ;
233
249
const dataFormat = [
234
250
'<span matripple="" class="mat-ripple mat-checkbox-ripple mat-focus-indicator" ng-reflect-trigger="[object HTMLLabelElement]" ng-reflect-disabled="false" ng-reflect-radius="20" ng-reflect-centered="true" ng-reflect-animation="[object Object]"> ' ,
@@ -245,7 +261,7 @@ describe('Reports Page', () => {
245
261
'Activity_Name' ,
246
262
' https://ioetec.atlassian.net/browse/CB-115 ' ,
247
263
'' ,
248
- ' git '
264
+ ' git ' ,
249
265
] ;
250
266
251
267
data . forEach ( ( value : any , index ) => {
@@ -257,7 +273,7 @@ describe('Reports Page', () => {
257
273
it ( 'Should render column header called Time Zone' , ( ) => {
258
274
const table = document . querySelector ( 'table#time-entries-table' ) ;
259
275
const tableHeaderElements = Array . from ( table . getElementsByTagName ( 'th' ) ) ;
260
- const tableHeaderTitles = tableHeaderElements . map ( element => ( element . textContent ) ) ;
276
+ const tableHeaderTitles = tableHeaderElements . map ( ( element ) => element . textContent ) ;
261
277
expect ( tableHeaderTitles ) . toContain ( 'Time zone' ) ;
262
278
} ) ;
263
279
@@ -272,6 +288,45 @@ describe('Reports Page', () => {
272
288
expect ( cell ) . toContain ( 'UTC-5' ) ;
273
289
} ) ;
274
290
291
+ it ( 'Should populate the projects with the payload from the action executed' , ( ) => {
292
+ const actionSubject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
293
+ const customerObj : Customer = { name : 'name' } ;
294
+ const projectsArray : Project [ ] = [
295
+ {
296
+ id : 'projectId' ,
297
+ customer_id : 'customer_id' ,
298
+ customer : customerObj ,
299
+ name : 'name' ,
300
+ description : 'proejectDescription' ,
301
+ project_type_id : 'project_type_id' ,
302
+ status : 'active' ,
303
+ } ,
304
+ ] ;
305
+ const action = {
306
+ type : ProjectActionTypes . LOAD_PROJECTS_SUCCESS ,
307
+ payload : projectsArray ,
308
+ } ;
309
+ actionSubject . next ( action ) ;
310
+ expect ( component . projects ) . toEqual ( projectsArray ) ;
311
+ } ) ;
312
+
313
+ it ( 'Should populate the activities with the payload from the action executed' , ( ) => {
314
+ const Subject = TestBed . inject ( ActionsSubject ) as ActionsSubject ;
315
+ const activitiesArray : Activity [ ] = [
316
+ {
317
+ id : 'activityId' ,
318
+ name : 'activityName' ,
319
+ description : 'activityDescription' ,
320
+ status : 'string'
321
+ } ,
322
+ ] ;
323
+ const action = {
324
+ type : ActivityManagementActionTypes . LOAD_ACTIVITIES_SUCCESS ,
325
+ payload : activitiesArray ,
326
+ } ;
327
+ Subject . next ( action ) ;
328
+ expect ( component . activities ) . toEqual ( activitiesArray ) ;
329
+ } ) ;
275
330
276
331
afterEach ( ( ) => {
277
332
fixture . destroy ( ) ;
0 commit comments