Skip to content

Commit cfa962a

Browse files
scastillo-jpjosepato87
authored andcommitted
TT-39 fix: creating test
1 parent f9c4786 commit cfa962a

File tree

11 files changed

+63
-52
lines changed

11 files changed

+63
-52
lines changed
Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
<div class="month-picker">
2-
<div class="card">
3-
<div class="card-header">
4-
<div class="d-flex align-items-center">
5-
<button class="btn mr-auto" (click)="decrement()">
6-
<i class="fa fa-chevron-left"></i>
7-
</button>
8-
<p>
9-
{{selectedYearText}}
10-
</p>
11-
<button class="btn ml-auto" (click)="increment()">
12-
<i class="fa fa-chevron-right"></i>
13-
</button>
14-
</div>
15-
</div>
16-
17-
<div class="card-body">
18-
<div class="row">
19-
<div class="col-sm-2" *ngFor="let month of months; let i = index">
20-
<div class="month-picker-cell">
21-
<button class="btn"
22-
[ngClass]="{'btn-primary': isSelectedMonth(i)}"
23-
(click)="selectMonth(i)">
24-
<small>{{ month }}</small>
25-
</button>
26-
</div>
27-
</div>
28-
</div>
29-
</div>
30-
</div>
1+
<div class="card-header">
2+
<div class="d-flex align-items-center">
3+
<button class="btn mr-auto" (click)="decrement()">
4+
<i class="fa fa-chevron-left"></i>
5+
</button>
6+
<p>
7+
{{selectedYearText}}
8+
</p>
9+
<button class="btn ml-auto" (click)="increment()">
10+
<i class="fa fa-chevron-right"></i>
11+
</button>
12+
</div>
3113
</div>
14+
<div class="row">
15+
<div class="spacing col-xl-1 col-lg-1 col-md-2 col-sm-2 col-xs-4" *ngFor="let month of months; let i = index">
16+
<button class="btn btn-light btn-block"
17+
[ngClass]="{'btn-primary': isSelectedMonth(i)}"
18+
(click)="selectMonth(i)">
19+
<small>{{ month.slice(0, 3) }}</small>
20+
</button>
21+
</div>
22+
</div>

src/app/modules/shared/components/month-picker/month-picker.component.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@
2121
@include highlight();
2222
border-radius: 0.2em;
2323
text-decoration: underline;
24-
2524
}
25+
.spacing {
26+
padding: 0.1em;
27+
}

src/app/modules/shared/components/month-picker/month-picker.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SubstractDatePipe } from './../../pipes/substract-date/substract-date.pipe';
12
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
23
import * as moment from 'moment';
34

@@ -7,8 +8,10 @@ import * as moment from 'moment';
78
styleUrls: ['./month-picker.component.scss']
89
})
910
export class MonthPickerComponent implements OnInit {
10-
11-
@Output() dateSelected = new EventEmitter<{ monthIndex: number; year: number; }>();
11+
@Output() dateSelected = new EventEmitter<{
12+
monthIndex: number;
13+
year: number;
14+
}>();
1215

1316
selectedMonthMoment: moment.Moment;
1417
selectedMonthIndex: number;

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class EntryFieldsComponent implements OnInit {
5050

5151
ngOnInit(): void {
5252
this.store.dispatch(new LoadActivities());
53-
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
53+
this.store.dispatch(new entryActions.LoadEntries(12, 2020));
5454
this.actionsSubject$
5555
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
5656
.subscribe((action) => {

src/app/modules/time-clock/services/entry.service.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ describe('EntryService', () => {
5454
});
5555

5656
it('load all Entries', () => {
57+
const year = new Date().getFullYear();
5758
const month = new Date().getMonth();
59+
5860
const timezoneOffset = new Date().getTimezoneOffset();
59-
service.loadEntries(month).subscribe();
61+
service.loadEntries(year, month).subscribe();
6062

61-
const loadEntryRequest = httpMock.expectOne(`${service.baseUrl}?month=${month}&timezone_offset=${timezoneOffset}`);
63+
const loadEntryRequest = httpMock.expectOne(`${service.baseUrl}?month=${month}&year=${year}&timezone_offset=${timezoneOffset}`);
6264
expect(loadEntryRequest.request.method).toBe('GET');
6365

6466
});

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export class EntryService {
2323
return this.http.get(`${this.baseUrl}/running`);
2424
}
2525

26-
loadEntries(month): Observable<any> {
26+
loadEntries(year, month): Observable<any> {
2727
const timezoneOffset = new Date().getTimezoneOffset();
28-
return this.http.get(`${this.baseUrl}?month=${month}&timezone_offset=${timezoneOffset}`);
28+
return this.http.get(`${this.baseUrl}?month=${month}&year=${year}&timezone_offset=${timezoneOffset}`);
2929
}
3030

3131
createEntry(entryData): Observable<any> {

src/app/modules/time-clock/store/entry.actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class LoadActiveEntryFail implements Action {
9999
export class LoadEntries implements Action {
100100
public readonly type = EntryActionTypes.LOAD_ENTRIES;
101101

102-
constructor(public month: number) {
102+
constructor(public month: number, public year: number) {
103103
}
104104
}
105105

src/app/modules/time-clock/store/entry.effects.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,18 @@ export class EntryEffects {
8787
@Effect()
8888
loadEntries$: Observable<Action> = this.actions$.pipe(
8989
ofType(actions.EntryActionTypes.LOAD_ENTRIES),
90-
map((action: actions.LoadEntries) => action.month),
91-
mergeMap((month) =>
92-
this.entryService.loadEntries(month).pipe(
90+
// tslint:disable-next-line:no-unused-expression
91+
map((action: actions.LoadEntries) => (action.month, action.year)),
92+
mergeMap((month, year) =>
93+
this.entryService.loadEntries(month, year).pipe(
9394
map((entries) => new actions.LoadEntriesSuccess(entries)),
9495
catchError((error) => {
9596
this.toastrService.warning(`The data could not be loaded`);
9697
return of(new actions.LoadEntriesFail(error));
9798
})
9899
)
99100
)
101+
100102
);
101103

102104
@Effect()

src/app/modules/time-clock/store/entry.reducer.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ describe('entryReducer', () => {
107107
});
108108

109109
it('on LoadEntries, isLoading is true', () => {
110-
const action = new actions.LoadEntries(new Date().getMonth() + 1);
110+
const month = 12;
111+
const year = 2020;
112+
const action = new actions.LoadEntries(month, year);
111113
const state = entryReducer(initialState, action);
112114
expect(state.timeEntriesDataSource.isLoading).toEqual(true);
113115
});

src/app/modules/time-entries/pages/time-entries.component.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ describe('TimeEntriesComponent', () => {
127127
}));
128128

129129
it('when create time entries, the time entries should be queried', () => {
130-
const currentMonth = new Date().getMonth() + 1;
130+
const currentMonth = new Date().getMonth();
131+
const year = new Date().getFullYear();
131132
const entryToSave = {
132133
entry: {
133134
project_id: 'project-id',
@@ -142,7 +143,7 @@ describe('TimeEntriesComponent', () => {
142143

143144
component.saveEntry(entryToSave);
144145
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CreateEntry(entryToSave.entry));
145-
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(currentMonth));
146+
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(currentMonth, year));
146147
});
147148

148149
it('when creating a new entry, then entryId should be null', () => {
@@ -324,11 +325,12 @@ describe('TimeEntriesComponent', () => {
324325
});
325326

326327
it('should get the entry List by Month and year', () => {
327-
const month = 1;
328-
const year = 2020;
328+
const month = new Date().getMonth();
329+
const year = new Date().getFullYear();
330+
329331
spyOn(store, 'dispatch');
330-
component.dateSelected({monthIndex: month, year: 2020});
331-
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month));
332+
component.dateSelected({monthIndex: month, year: year});
333+
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month + 1, year));
332334
});
333335

334336
it('doSave when activeTimeEntry === null', waitForAsync(() => {

0 commit comments

Comments
 (0)