Skip to content

Commit da2aedd

Browse files
committed
fix: TT-279 fix visual errors
1 parent d3aaafb commit da2aedd

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

src/app/modules/time-entries/components/calendar/calendar.component.html

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@
2727
isVisibleForCurrentView(calendarView, CalendarViewEnum.Week) ||
2828
isVisibleForCurrentView(calendarView, CalendarViewEnum.Day)
2929
"
30-
>
31-
<p class="additional" *ngIf="timeIsGreaterThan(timeEntries.start_date, timeEntries.end_date, 60)">
32-
{{ timeEntries.description }}
33-
</p>
34-
</div>
30+
></div>
3531
</div>
3632
</ng-template>
3733

@@ -72,16 +68,17 @@
7268
type="button"
7369
[(view)]="calendarView"
7470
[(viewDate)]="currentDate"
75-
class="btn btn-light btn-block"
71+
class="btn btn-light btn-block m-0"
7672
(click)="handleChangeDateEvent()"
7773
>
7874
Previus
7975
</button>
8076
<button
8177
mwlCalendarToday
78+
[ngClass]="{ active: isToday }"
8279
type="button"
8380
[(viewDate)]="currentDate"
84-
class="btn btn-light btn-block"
81+
class="btn btn-light btn-block m-0"
8582
(click)="handleChangeDateEvent()"
8683
>
8784
Today
@@ -91,7 +88,7 @@
9188
type="button"
9289
[(view)]="calendarView"
9390
[(viewDate)]="currentDate"
94-
class="btn btn-light btn-block"
91+
class="btn btn-light btn-block m-0"
9592
(click)="handleChangeDateEvent()"
9693
[disabled]="nextDateDisabled"
9794
>
@@ -109,13 +106,28 @@
109106
</div>
110107
<div class="col-sm-4 text-right">
111108
<div class="btn-group" role="group" aria-label="Calendar View">
112-
<button type="button" class="btn btn-light btn-block" (click)="changeCalendarView(CalendarViewEnum.Month)">
109+
<button
110+
[ngClass]="{ active: isVisibleForCurrentView(calendarView, CalendarViewEnum.Month) }"
111+
type="button"
112+
class="btn btn-light btn-block m-0"
113+
(click)="changeCalendarView(CalendarViewEnum.Month)"
114+
>
113115
Month
114116
</button>
115-
<button type="button" class="btn btn-light btn-block" (click)="changeCalendarView(CalendarViewEnum.Week)">
117+
<button
118+
[ngClass]="{ active: isVisibleForCurrentView(calendarView, CalendarViewEnum.Week) }"
119+
type="button"
120+
class="btn btn-light btn-block m-0"
121+
(click)="changeCalendarView(CalendarViewEnum.Week)"
122+
>
116123
Week
117124
</button>
118-
<button type="button" class="btn btn-light btn-block" (click)="changeCalendarView(CalendarViewEnum.Day)">
125+
<button
126+
[ngClass]="{ active: isVisibleForCurrentView(calendarView, CalendarViewEnum.Day) }"
127+
type="button"
128+
class="btn btn-light btn-block m-0"
129+
(click)="changeCalendarView(CalendarViewEnum.Day)"
130+
>
119131
Day
120132
</button>
121133
</div>

src/app/modules/time-entries/components/calendar/calendar.component.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ describe('CalendarComponent', () => {
119119
expect(component.timeEntriesAsEvent.length).toEqual(1);
120120
});
121121

122+
it('Call isVisibleForCurrentDate when call ngOnInit()', () => {
123+
spyOn(component, 'isVisibleForCurrentDate');
124+
125+
component.ngOnInit();
126+
127+
expect(component.isVisibleForCurrentDate).toHaveBeenCalled();
128+
});
129+
122130
it('Call navigationEnable when call ngOnInit()', () => {
123131
spyOn(component, 'navigationEnable');
124132

@@ -170,10 +178,12 @@ describe('CalendarComponent', () => {
170178
const calendarView = CalendarView.Month;
171179
spyOn(component, 'navigationEnable');
172180
spyOn(component.changeDate, 'emit');
181+
spyOn(component, 'isVisibleForCurrentDate');
173182

174183
component.handleChangeDateEvent();
175184

176185
expect(component.navigationEnable).toHaveBeenCalledWith(calendarView);
186+
expect(component.isVisibleForCurrentDate).toHaveBeenCalled();
177187
expect(component.changeDate.emit).toHaveBeenCalledWith(fakeValueEmit);
178188
});
179189

@@ -288,4 +298,20 @@ describe('CalendarComponent', () => {
288298

289299
expect(response).toBeFalse();
290300
});
301+
302+
it('returns boolean when call isVisibleForCurrentDate', () => {
303+
[
304+
{ current: '2021-04-11T10:20:00Z', initial: '2021-04-11T08:00:00Z', expected: true },
305+
{ current: '2021-04-12T17:00:00Z', initial: '2021-04-11T17:00:00Z', expected: false },
306+
{ current: '2021-04-11T18:00:00Z', initial: '2021-04-12T18:00:00Z', expected: false },
307+
{ current: '2021-04-12T12:00:00Z', initial: '2021-04-12T12:00:00Z', expected: true },
308+
].forEach(({ current, initial, expected }) => {
309+
component.currentDate = new Date(current);
310+
component.initialDate = new Date(initial);
311+
312+
const result = component.isVisibleForCurrentDate();
313+
314+
expect(result).toBe(expected);
315+
});
316+
});
291317
});

src/app/modules/time-entries/components/calendar/calendar.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DataSource } from '../../../shared/models/data-source.model';
99
import { Entry } from 'src/app/modules/shared/models';
1010
import { map } from 'rxjs/operators';
1111
import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/substract-date.pipe';
12+
import { initialConfig } from 'ngx-mask';
1213

1314
@Component({
1415
selector: 'app-calendar',
@@ -30,17 +31,20 @@ export class CalendarComponent implements OnInit {
3031

3132
initialDate: Date;
3233
previusDate: Date;
34+
isToday: boolean;
3335
timeEntriesAsEvent: CalendarEvent[];
3436
nextDateDisabled: boolean;
3537

3638
constructor() {
3739
this.initialDate = new Date();
3840
this.previusDate = new Date();
41+
this.isToday = false;
3942
this.timeEntriesAsEvent = [];
4043
this.nextDateDisabled = true;
4144
}
4245

4346
ngOnInit(): void {
47+
this.isToday = this.isVisibleForCurrentDate();
4448
this.navigationEnable(this.calendarView);
4549
}
4650

@@ -80,6 +84,7 @@ export class CalendarComponent implements OnInit {
8084

8185
handleChangeDateEvent(): void{
8286
const date = this.currentDate;
87+
this.isToday = this.isVisibleForCurrentDate();
8388
this.navigationEnable(this.calendarView);
8489
this.changeDate.emit({date});
8590
}
@@ -119,4 +124,10 @@ export class CalendarComponent implements OnInit {
119124
isVisibleForCurrentView(currentCalendarView: CalendarView, desiredView: CalendarView ): boolean{
120125
return currentCalendarView === desiredView;
121126
}
127+
128+
isVisibleForCurrentDate(): boolean{
129+
const currentDate: Date = new Date(this.currentDate);
130+
const initialDate: Date = new Date(this.initialDate);
131+
return currentDate.setHours(0, 0, 0, 0) === initialDate.setHours(0, 0, 0, 0);
132+
}
122133
}

0 commit comments

Comments
 (0)