Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TT-39 fix: creating test
  • Loading branch information
scastillo-jp authored and Guido Quezada committed Dec 28, 2020
commit da55e06978b278590e477b4e666517ec56155c27
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
<div class="month-picker">
<div class="card">
<div class="card-header">
<div class="d-flex align-items-center">
<button class="btn mr-auto" (click)="decrement()">
<i class="fa fa-chevron-left"></i>
</button>
<p>
{{selectedYearText}}
</p>
<button class="btn ml-auto" (click)="increment()">
<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>

<div class="card-body">
<div class="row">
<div class="col-sm-2" *ngFor="let month of months; let i = index">
<div class="month-picker-cell">
<button class="btn"
[ngClass]="{'btn-primary': isSelectedMonth(i)}"
(click)="selectMonth(i)">
<small>{{ month }}</small>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="card-header">
<div class="d-flex align-items-center">
<button class="btn mr-auto" (click)="decrement()">
<i class="fa fa-chevron-left"></i>
</button>
<p>
{{selectedYearText}}
</p>
<button class="btn ml-auto" (click)="increment()">
<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
<div class="row">
<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">
<button class="btn btn-light btn-block"
[ngClass]="{'btn-primary': isSelectedMonth(i)}"
(click)="selectMonth(i)">
<small>{{ month.slice(0, 3) }}</small>
</button>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
@include highlight();
border-radius: 0.2em;
text-decoration: underline;

}
.spacing {
padding: 0.1em;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SubstractDatePipe } from './../../pipes/substract-date/substract-date.pipe';
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import * as moment from 'moment';

Expand All @@ -7,8 +8,10 @@ import * as moment from 'moment';
styleUrls: ['./month-picker.component.scss']
})
export class MonthPickerComponent implements OnInit {

@Output() dateSelected = new EventEmitter<{ monthIndex: number; year: number; }>();
@Output() dateSelected = new EventEmitter<{
monthIndex: number;
year: number;
}>();

selectedMonthMoment: moment.Moment;
selectedMonthIndex: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class EntryFieldsComponent implements OnInit {

ngOnInit(): void {
this.store.dispatch(new LoadActivities());
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
this.store.dispatch(new entryActions.LoadEntries(12, 2020));
this.actionsSubject$
.pipe(filter((action: any) => action.type === ActivityManagementActionTypes.LOAD_ACTIVITIES_SUCCESS))
.subscribe((action) => {
Expand Down
6 changes: 4 additions & 2 deletions src/app/modules/time-clock/services/entry.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ describe('EntryService', () => {
});

it('load all Entries', () => {
const year = new Date().getFullYear();
const month = new Date().getMonth();

const timezoneOffset = new Date().getTimezoneOffset();
service.loadEntries(month).subscribe();
service.loadEntries(year, month).subscribe();

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

});
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class EntryService {
return this.http.get(`${this.baseUrl}/running`);
}

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

createEntry(entryData): Observable<any> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/time-clock/store/entry.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class LoadActiveEntryFail implements Action {
export class LoadEntries implements Action {
public readonly type = EntryActionTypes.LOAD_ENTRIES;

constructor(public month: number) {
constructor(public month: number, public year: number) {
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ export class EntryEffects {
@Effect()
loadEntries$: Observable<Action> = this.actions$.pipe(
ofType(actions.EntryActionTypes.LOAD_ENTRIES),
map((action: actions.LoadEntries) => action.month),
mergeMap((month) =>
this.entryService.loadEntries(month).pipe(
// tslint:disable-next-line:no-unused-expression
map((action: actions.LoadEntries) => (action.month, action.year)),
mergeMap((month, year) =>
this.entryService.loadEntries(month, year).pipe(
map((entries) => new actions.LoadEntriesSuccess(entries)),
catchError((error) => {
this.toastrService.warning(`The data could not be loaded`);
return of(new actions.LoadEntriesFail(error));
})
)
)

);

@Effect()
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/time-clock/store/entry.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ describe('entryReducer', () => {
});

it('on LoadEntries, isLoading is true', () => {
const action = new actions.LoadEntries(new Date().getMonth() + 1);
const month = 12;
const year = 2020;
const action = new actions.LoadEntries(month, year);
const state = entryReducer(initialState, action);
expect(state.timeEntriesDataSource.isLoading).toEqual(true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ describe('TimeEntriesComponent', () => {
}));

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

component.saveEntry(entryToSave);
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CreateEntry(entryToSave.entry));
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(currentMonth));
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(currentMonth, year));
});

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

it('should get the entry List by Month and year', () => {
const month = 1;
const year = 2020;
const month = new Date().getMonth();
const year = new Date().getFullYear();

spyOn(store, 'dispatch');
component.dateSelected({monthIndex: month, year: 2020});
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month));
component.dateSelected({monthIndex: month, year: year});
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(month + 1, year));
});

it('doSave when activeTimeEntry === null', waitForAsync(() => {
Expand Down
13 changes: 10 additions & 3 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { formatDate } from '@angular/common';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActionsSubject, select, Store } from '@ngrx/store';
import { ToastrService } from 'ngx-toastr';
Expand Down Expand Up @@ -31,6 +32,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
selectedMonthIndex: number;
selectedMonthAsText: string;

currentMonth = new Date().getMonth();
year = new Date().getFullYear();

constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource));
}
Expand All @@ -40,7 +44,10 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));

this.store.dispatch(new entryActions.LoadEntries(this.selectedMonthIndex, this.year));
console.log('year', this.store.dispatch(new entryActions.LoadEntries(this.currentMonth, this.year)));

this.loadActiveEntry();

this.entriesSubscription = this.actionsSubject$.pipe(
Expand All @@ -52,7 +59,6 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
)
).subscribe((action) => {
this.loadActiveEntry();
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
});
}

Expand Down Expand Up @@ -80,6 +86,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
this.canMarkEntryAsWIP = this.isEntryRunningEqualsToEntryToEdit(this.getEntryRunning(ds.data), this.entry)
|| this.isTheEntryToEditTheLastOne(ds.data);
});
console.log('entryId', this.entryId);
}

private isEntryRunningEqualsToEntryToEdit(entryRunning: Entry, entryToEdit: Entry) {
Expand Down Expand Up @@ -168,7 +175,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy {
this.selectedYearAsText = event.year.toString();
this.selectedMonthIndex = event.monthIndex;
this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM');
this.store.dispatch(new entryActions.LoadEntries(event.monthIndex));
this.store.dispatch(new entryActions.LoadEntries(event.monthIndex + 1, event.year));
}

openModal(item: any) {
Expand Down