Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<div class="card-header">
<div class="d-flex align-items-center">
<button class="btn mr-auto" (click)="changeYear('subtract')">
<i class="fa fa-chevron-left"></i>
</button>
<p>
{{selectedYearText}}
</p>
<button class="btn ml-auto" (click)="changeYear('add')">
<i class="fa fa-chevron-right"></i>
</button>
<div class="row align-items-center">
<div class="col-sm-4">
<button class="btn mr-auto" (click)="changeYear('subtract')">
<i class="fa fa-chevron-left"></i>
</button>
</div>
<div class="col-sm-4">
<p class="text-center year-text">
{{selectedYearText}}
</p>
</div>

<div class="col-sm-4 text-right">
<button *ngIf="showArrowNext" class="btn ml-auto" (click)="changeYear('add')">
<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
</div>
<div class="row content-months">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
margin: 0;
}

.year-text {
margin-bottom: 0;
}

.month {
background: $primary;
color: white;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe('MonthPickerComponent', () => {
expect(component.changeYear).toHaveBeenCalled();
expect(component.selectedYearText).toEqual(incrementYear);
expect(component.selectedYearMoment.format('Y')).toEqual(incrementYear);
expect(component.showArrowNext).toEqual(false);
});


it('should subtract a year to current year', () => {
component.selectedYearMoment = moment();
const decrementYear = moment().subtract(1, 'year').format('Y');
Expand All @@ -58,12 +58,14 @@ describe('MonthPickerComponent', () => {
expect(component.selectedYearMoment.format('Y')).toEqual(decrementYear);
});


it('selectMonth should call selectDate', () => {
component.selectedYear = 2020;
const monthSelect = new Date().getMonth();
const yearSelect = new Date().getFullYear();
spyOn(component, 'selectDate');
component.selectMonth(10);
expect(component.selectDate).toHaveBeenCalledWith(10, 2020);

component.selectMonth(monthSelect);

expect(component.selectDate).toHaveBeenCalledWith(monthSelect, yearSelect);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export class MonthPickerComponent implements OnInit {
selectedMonthIndex: number;
selectedYearMoment: moment.Moment;
selectedYear: number;

selectedYearText: string;
months: Array<string> = [];
currentYear = new Date().getFullYear();
showArrowNext = false;

constructor() {
this.selectedYearMoment = moment();
Expand All @@ -40,6 +41,8 @@ export class MonthPickerComponent implements OnInit {

const monthIndex = changeAction === 'add' ? 0 : 11;
this.selectMonth(monthIndex);

this.showArrowNext = this.selectedYear < this.currentYear ?? true;
}

selectMonth(monthIndex: number) {
Expand Down