Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
fix: #347 pre-fill start end dates in report
  • Loading branch information
enriquezrene committed Jun 15, 2020
commit 7d67319650bfe62a37c2c556dcf9107c15664275
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
<div class="col">
<div class="input-group">
<app-input-label text="Start Date"></app-input-label>
<app-input-date formControlName="startDate" required="true"></app-input-date>
<app-input-date formControlName="startDate" id="startDate" required="true"></app-input-date>
</div>
</div>
<div class="col">
<div class="input-group">
<app-input-label text="End Date"></app-input-label>
<app-input-date formControlName="endDate" required="true"></app-input-date>
<app-input-date formControlName="endDate" id="endDate" required="true"></app-input-date>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col">
<button type="submit" class="btn btn-primary float-right"
[disabled]="!(reportForm.touched && reportForm.valid)">Search
</button>
<button type="submit" class="btn btn-primary float-right">Search</button>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component} from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import { formatDate } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import * as entryActions from '../../../time-clock/store/entry.actions';
import {Store} from '@ngrx/store';
import {EntryState} from '../../../time-clock/store/entry.reducer';
Expand All @@ -9,7 +10,7 @@ import * as moment from 'moment';
selector: 'app-time-range-form',
templateUrl: './time-range-form.component.html',
})
export class TimeRangeFormComponent {
export class TimeRangeFormComponent implements OnInit {
public reportForm: FormGroup;
private startDate = new FormControl('');
private endDate = new FormControl('');
Expand All @@ -20,6 +21,17 @@ export class TimeRangeFormComponent {
endDate: this.endDate
});
}
ngOnInit(): void {
this.setInitialDataOnScreen();
}

setInitialDataOnScreen() {
this.reportForm.setValue({
startDate: formatDate(moment().startOf('week').toString(), 'yyyy-MM-dd', 'en'),
endDate: formatDate(moment().endOf('week').toString(), 'yyyy-MM-dd', 'en')
});
this.onSubmit();
}

onSubmit() {
this.store.dispatch(new entryActions.LoadEntriesByTimeRange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ describe('Reports Page', () => {
}));
});

it('setInitialDataOnScreen on ngOnInit', () => {
spyOn(component, 'setInitialDataOnScreen');

component.ngOnInit();

expect(component.setInitialDataOnScreen).toHaveBeenCalled();
});

it('setInitialDataOnScreen sets dates in form', () => {
spyOn(component.reportForm, 'setValue');

component.setInitialDataOnScreen();

expect(component.reportForm.setValue).toHaveBeenCalled();
});

it('triggers onSubmit to set initial data', () => {
spyOn(component, 'onSubmit');

component.setInitialDataOnScreen();

expect(component.onSubmit).toHaveBeenCalled();
});

afterEach(() => {
fixture.destroy();
});
Expand Down